Clean up ST_REGS handling in the MIPS backend.
[official-gcc.git] / libgo / mksysinfo.sh
blobe188155e5faab4ac59859f5d153770c51d9d2759
1 #!/bin/sh
3 # Copyright 2009 The Go Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style
5 # license that can be found in the LICENSE file.
7 # Create sysinfo.go.
9 # This shell script creates the sysinfo.go file which holds types and
10 # constants extracted from the system header files. This relies on a
11 # hook in gcc: the -fdump-go-spec option will generate debugging
12 # information in Go syntax.
14 # We currently #include all the files at once, which works, but leads
15 # to exposing some names which ideally should not be exposed, as they
16 # match grep patterns. E.g., WCHAR_MIN gets exposed because it starts
17 # with W, like the wait flags.
19 CC=${CC:-gcc}
20 OUT=tmp-sysinfo.go
22 set -e
24 rm -f sysinfo.c
25 cat > sysinfo.c <<EOF
26 #include "config.h"
28 #include <sys/types.h>
29 #include <dirent.h>
30 #include <errno.h>
31 #include <fcntl.h>
32 #include <netinet/in.h>
33 /* <netinet/tcp.h> needs u_char/u_short, but <sys/bsd_types> is only
34 included by <netinet/in.h> if _SGIAPI (i.e. _SGI_SOURCE
35 && !_XOPEN_SOURCE.
36 <sys/termios.h> only defines TIOCNOTTY if !_XOPEN_SOURCE, while
37 <sys/ttold.h> does so unconditionally. */
38 #ifdef __sgi__
39 #include <sys/bsd_types.h>
40 #include <sys/ttold.h>
41 #endif
42 #include <netinet/tcp.h>
43 #if defined(HAVE_NETINET_IN_SYSTM_H)
44 #include <netinet/in_systm.h>
45 #endif
46 #if defined(HAVE_NETINET_IP_H)
47 #include <netinet/ip.h>
48 #endif
49 #if defined(HAVE_NETINET_IP_MROUTE_H)
50 #include <netinet/ip_mroute.h>
51 #endif
52 #if defined(HAVE_NETINET_IF_ETHER_H)
53 #include <netinet/if_ether.h>
54 #endif
55 #include <signal.h>
56 #include <sys/ioctl.h>
57 #include <termios.h>
58 #if defined(HAVE_SYSCALL_H)
59 #include <syscall.h>
60 #endif
61 #if defined(HAVE_SYS_SYSCALL_H)
62 #include <sys/syscall.h>
63 #endif
64 #if defined(HAVE_SYS_EPOLL_H)
65 #include <sys/epoll.h>
66 #endif
67 #if defined(HAVE_SYS_FILE_H)
68 #include <sys/file.h>
69 #endif
70 #if defined(HAVE_SYS_MMAN_H)
71 #include <sys/mman.h>
72 #endif
73 #if defined(HAVE_SYS_PRCTL_H)
74 #include <sys/prctl.h>
75 #endif
76 #if defined(HAVE_SYS_PTRACE_H)
77 #include <sys/ptrace.h>
78 #endif
79 #include <sys/resource.h>
80 #include <sys/uio.h>
81 #include <sys/socket.h>
82 #include <sys/stat.h>
83 #include <sys/time.h>
84 #include <sys/times.h>
85 #include <sys/wait.h>
86 #include <sys/un.h>
87 #if defined(HAVE_SYS_USER_H)
88 #include <sys/user.h>
89 #endif
90 #if defined(HAVE_SYS_UTSNAME_H)
91 #include <sys/utsname.h>
92 #endif
93 #if defined(HAVE_SYS_SELECT_H)
94 #include <sys/select.h>
95 #endif
96 #include <time.h>
97 #include <unistd.h>
98 #include <netdb.h>
99 #include <pwd.h>
100 #if defined(HAVE_LINUX_FILTER_H)
101 #include <linux/filter.h>
102 #endif
103 #if defined(HAVE_LINUX_IF_ADDR_H)
104 #include <linux/if_addr.h>
105 #endif
106 #if defined(HAVE_LINUX_IF_ETHER_H)
107 #include <linux/if_ether.h>
108 #endif
109 #if defined(HAVE_LINUX_IF_TUN_H)
110 #include <linux/if_tun.h>
111 #endif
112 #if defined(HAVE_LINUX_NETLINK_H)
113 #include <linux/netlink.h>
114 #endif
115 #if defined(HAVE_LINUX_RTNETLINK_H)
116 #include <linux/rtnetlink.h>
117 #endif
118 #if defined(HAVE_NET_IF_H)
119 #include <net/if.h>
120 #endif
121 #if defined(HAVE_NET_IF_ARP_H)
122 #include <net/if_arp.h>
123 #endif
124 #if defined(HAVE_NET_ROUTE_H)
125 #include <net/route.h>
126 #endif
127 #if defined (HAVE_NETPACKET_PACKET_H)
128 #include <netpacket/packet.h>
129 #endif
130 #if defined(HAVE_SYS_MOUNT_H)
131 #include <sys/mount.h>
132 #endif
133 #if defined(HAVE_SYS_VFS_H)
134 #include <sys/vfs.h>
135 #endif
136 #if defined(HAVE_STATFS_H)
137 #include <sys/statfs.h>
138 #endif
139 #if defined(HAVE_SYS_TIMEX_H)
140 #include <sys/timex.h>
141 #endif
142 #if defined(HAVE_SYS_SYSINFO_H)
143 #include <sys/sysinfo.h>
144 #endif
145 #if defined(HAVE_USTAT_H)
146 #include <ustat.h>
147 #endif
148 #if defined(HAVE_UTIME_H)
149 #include <utime.h>
150 #endif
151 #if defined(HAVE_LINUX_ETHER_H)
152 #include <linux/ether.h>
153 #endif
154 #if defined(HAVE_LINUX_FS_H)
155 #include <linux/fs.h>
156 #endif
157 #if defined(HAVE_LINUX_REBOOT_H)
158 #include <linux/reboot.h>
159 #endif
160 #if defined(HAVE_SYS_INOTIFY_H)
161 #include <sys/inotify.h>
162 #endif
163 #if defined(HAVE_NETINET_ICMP6_H)
164 #include <netinet/icmp6.h>
165 #endif
166 #if defined(HAVE_SCHED_H)
167 #include <sched.h>
168 #endif
170 /* Constants that may only be defined as expressions on some systems,
171 expressions too complex for -fdump-go-spec to handle. These are
172 handled specially below. */
173 enum {
174 #ifdef TIOCGWINSZ
175 TIOCGWINSZ_val = TIOCGWINSZ,
176 #endif
177 #ifdef TIOCNOTTY
178 TIOCNOTTY_val = TIOCNOTTY,
179 #endif
180 #ifdef TIOCSCTTY
181 TIOCSCTTY_val = TIOCSCTTY,
182 #endif
183 #ifdef TIOCGPTN
184 TIOCGPTN_val = TIOCGPTN,
185 #endif
186 #ifdef TIOCSPTLCK
187 TIOCSPTLCK_val = TIOCSPTLCK,
188 #endif
189 #ifdef TIOCGDEV
190 TIOCGDEV_val = TIOCGDEV,
191 #endif
192 #ifdef TIOCSIG
193 TIOCSIG_val = TIOCSIG,
194 #endif
198 ${CC} -fdump-go-spec=gen-sysinfo.go -std=gnu99 -S -o sysinfo.s sysinfo.c
200 echo 'package syscall' > ${OUT}
201 echo 'import "unsafe"' >> ${OUT}
202 echo 'type _ unsafe.Pointer' >> ${OUT}
204 # Get all the consts and types, skipping ones which could not be
205 # represented in Go and ones which we need to rewrite. We also skip
206 # function declarations, as we don't need them here. All the symbols
207 # will all have a leading underscore.
208 grep -v '^// ' gen-sysinfo.go | \
209 grep -v '^func' | \
210 grep -v '^type _timeval ' | \
211 grep -v '^type _timespec_t ' | \
212 grep -v '^type _timespec ' | \
213 grep -v '^type _timestruc_t ' | \
214 grep -v '^type _epoll_' | \
215 grep -v 'in6_addr' | \
216 grep -v 'sockaddr_in6' | \
217 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
218 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
219 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
220 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
221 >> ${OUT}
223 # The errno constants. These get type Errno.
224 echo '#include <errno.h>' | ${CC} -x c - -E -dM | \
225 egrep '#define E[A-Z0-9_]+ ' | \
226 sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(_\1)/' >> ${OUT}
228 # The O_xxx flags.
229 egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
230 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
231 if ! grep '^const O_ASYNC' ${OUT} >/dev/null 2>&1; then
232 echo "const O_ASYNC = 0" >> ${OUT}
234 if ! grep '^const O_CLOEXEC' ${OUT} >/dev/null 2>&1; then
235 echo "const O_CLOEXEC = 0" >> ${OUT}
238 # The os package requires F_DUPFD_CLOEXEC to be defined.
239 if ! grep '^const F_DUPFD_CLOEXEC' ${OUT} >/dev/null 2>&1; then
240 echo "const F_DUPFD_CLOEXEC = 0" >> ${OUT}
243 # These flags can be lost on i386 GNU/Linux when using
244 # -D_FILE_OFFSET_BITS=64, because we see "#define F_SETLK F_SETLK64"
245 # before we see the definition of F_SETLK64.
246 for flag in F_GETLK F_SETLK F_SETLKW; do
247 if ! grep "^const ${flag} " ${OUT} >/dev/null 2>&1 \
248 && grep "^const ${flag}64 " ${OUT} >/dev/null 2>&1; then
249 echo "const ${flag} = ${flag}64" >> ${OUT}
251 done
253 # The Flock_t struct for fcntl.
254 grep '^type _flock ' gen-sysinfo.go | \
255 sed -e 's/type _flock/type Flock_t/' \
256 -e 's/l_type/Type/' \
257 -e 's/l_whence/Whence/' \
258 -e 's/l_start/Start/' \
259 -e 's/l_len/Len/' \
260 -e 's/l_pid/Pid/' \
261 >> ${OUT}
263 # The signal numbers.
264 grep '^const _SIG[^_]' gen-sysinfo.go | \
265 grep -v '^const _SIGEV_' | \
266 sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = Signal(_\2)/' >> ${OUT}
267 if ! grep '^const SIGPOLL ' ${OUT} >/dev/null 2>&1; then
268 if grep '^const SIGIO ' ${OUT} > /dev/null 2>&1; then
269 echo "const SIGPOLL = SIGIO" >> ${OUT}
272 if ! grep '^const SIGCLD ' ${OUT} >/dev/null 2>&1; then
273 if grep '^const SIGCHLD ' ${OUT} >/dev/null 2>&1; then
274 echo "const SIGCLD = SIGCHLD" >> ${OUT}
278 # The syscall numbers. We force the names to upper case.
279 grep '^const _SYS_' gen-sysinfo.go | \
280 sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \
281 while read sys; do
282 sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
283 echo "const $sup = _$sys" >> ${OUT}
284 done
286 # The GNU/Linux support wants to use SYS_GETDENTS64 if available.
287 if ! grep '^const SYS_GETDENTS ' ${OUT} >/dev/null 2>&1; then
288 echo "const SYS_GETDENTS = 0" >> ${OUT}
290 if ! grep '^const SYS_GETDENTS64 ' ${OUT} >/dev/null 2>&1; then
291 echo "const SYS_GETDENTS64 = 0" >> ${OUT}
294 # Stat constants.
295 grep '^const _S_' gen-sysinfo.go | \
296 sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
298 # Mmap constants.
299 grep '^const _PROT_' gen-sysinfo.go | \
300 sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
301 grep '^const _MAP_' gen-sysinfo.go | \
302 sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
303 grep '^const _MADV_' gen-sysinfo.go | \
304 sed -e 's/^\(const \)_\(MADV_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
305 grep '^const _MCL_' gen-sysinfo.go | \
306 sed -e 's/^\(const \)_\(MCL_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
308 # Process status constants.
309 grep '^const _W' gen-sysinfo.go |
310 sed -e 's/^\(const \)_\(W[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
311 # WSTOPPED was introduced in glibc 2.3.4.
312 if ! grep '^const _WSTOPPED = ' gen-sysinfo.go >/dev/null 2>&1; then
313 if grep '^const _WUNTRACED = ' gen-sysinfo.go > /dev/null 2>&1; then
314 echo 'const WSTOPPED = _WUNTRACED' >> ${OUT}
315 else
316 echo 'const WSTOPPED = 2' >> ${OUT}
319 if grep '^const ___WALL = ' gen-sysinfo.go >/dev/null 2>&1 \
320 && ! grep '^const _WALL = ' gen-sysinfo.go >/dev/null 2>&1; then
321 echo 'const WALL = ___WALL' >> ${OUT}
324 # Networking constants.
325 egrep '^const _(AF|ARPHRD|ETH|IN|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
326 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
327 grep '^const _SOMAXCONN' gen-sysinfo.go |
328 sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
329 >> ${OUT}
330 grep '^const _SHUT_' gen-sysinfo.go |
331 sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
333 # The net package requires some const definitions.
334 for m in IP_PKTINFO IPV6_V6ONLY IPPROTO_IPV6 IPV6_JOIN_GROUP IPV6_LEAVE_GROUP IPV6_TCLASS SO_REUSEPORT; do
335 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
336 echo "const $m = 0" >> ${OUT}
338 done
339 for m in SOCK_CLOEXEC SOCK_NONBLOCK; do
340 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
341 echo "const $m = -1" >> ${OUT}
343 done
345 # The syscall package requires AF_LOCAL.
346 if ! grep '^const AF_LOCAL ' ${OUT} >/dev/null 2>&1; then
347 if grep '^const AF_UNIX ' ${OUT} >/dev/null 2>&1; then
348 echo "const AF_LOCAL = AF_UNIX" >> ${OUT}
352 # pathconf constants.
353 grep '^const __PC' gen-sysinfo.go |
354 sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
356 # The PATH_MAX constant.
357 if grep '^const _PATH_MAX ' gen-sysinfo.go >/dev/null 2>&1; then
358 echo 'const PathMax = _PATH_MAX' >> ${OUT}
361 # epoll constants.
362 grep '^const _EPOLL' gen-sysinfo.go |
363 sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
364 # Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
365 if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
366 echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
368 if ! grep '^const EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
369 echo "const EPOLL_CLOEXEC = 02000000" >> ${OUT}
372 # Prctl constants.
373 grep '^const _PR_' gen-sysinfo.go |
374 sed -e 's/^\(const \)_\(PR_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
376 # Ptrace constants.
377 grep '^const _PTRACE' gen-sysinfo.go |
378 sed -e 's/^\(const \)_\(PTRACE[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
379 # We need some ptrace options that are not defined in older versions
380 # of glibc.
381 if ! grep '^const PTRACE_SETOPTIONS' ${OUT} > /dev/null 2>&1; then
382 echo "const PTRACE_SETOPTIONS = 0x4200" >> ${OUT}
384 if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then
385 echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
387 if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then
388 echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
390 if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then
391 echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
393 if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then
394 echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
396 if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then
397 echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
399 if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then
400 echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
402 if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then
403 echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
405 if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then
406 echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
408 if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
409 echo "const PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
411 if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
412 echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
414 if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then
415 echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
417 if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then
418 echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
420 if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then
421 echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
423 if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then
424 echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
426 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
427 echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
429 if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
430 echo "const _PTRACE_TRACEME = 0" >> ${OUT}
433 # The registers returned by PTRACE_GETREGS. This is probably
434 # GNU/Linux specific; it should do no harm if there is no
435 # _user_regs_struct.
436 regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
437 if test "$regs" != ""; then
438 regs=`echo $regs | sed -e 's/type _user_regs_struct struct //' -e 's/[{}]//g'`
439 regs=`echo $regs | sed -e s'/^ *//'`
440 nregs=
441 while test -n "$regs"; do
442 field=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
443 regs=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
444 # Capitalize the first character of the field.
445 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
446 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
447 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
448 field="$f$r"
449 nregs="$nregs $field;"
450 done
451 echo "type PtraceRegs struct {$nregs }" >> ${OUT}
454 # Some basic types.
455 echo 'type Size_t _size_t' >> ${OUT}
456 echo "type Ssize_t _ssize_t" >> ${OUT}
457 if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then
458 echo "type Offset_t _off64_t" >> ${OUT}
459 else
460 echo "type Offset_t _off_t" >> ${OUT}
462 echo "type Mode_t _mode_t" >> ${OUT}
463 echo "type Pid_t _pid_t" >> ${OUT}
464 echo "type Uid_t _uid_t" >> ${OUT}
465 echo "type Gid_t _gid_t" >> ${OUT}
466 echo "type Socklen_t _socklen_t" >> ${OUT}
468 # The C int type.
469 sizeof_int=`grep '^const ___SIZEOF_INT__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
470 if test "$sizeof_int" = "4"; then
471 echo "type _C_int int32" >> ${OUT}
472 echo "type _C_uint uint32" >> ${OUT}
473 elif test "$sizeof_int" = "8"; then
474 echo "type _C_int int64" >> ${OUT}
475 echo "type _C_uint uint64" >> ${OUT}
476 else
477 echo 1>&2 "mksysinfo.sh: could not determine size of int (got $sizeof_int)"
478 exit 1
481 # The C long type, needed because that is the type that ptrace returns.
482 sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
483 if test "$sizeof_long" = "4"; then
484 echo "type _C_long int32" >> ${OUT}
485 elif test "$sizeof_long" = "8"; then
486 echo "type _C_long int64" >> ${OUT}
487 else
488 echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
489 exit 1
492 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
493 # double is commented by -fdump-go-spec.
494 if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
495 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
497 if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
498 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
501 # The time_t type.
502 if grep '^type _time_t ' gen-sysinfo.go > /dev/null 2>&1; then
503 echo 'type Time_t _time_t' >> ${OUT}
506 # The time structures need special handling: we need to name the
507 # types, so that we can cast integers to the right types when
508 # assigning to the structures.
509 timeval=`grep '^type _timeval ' gen-sysinfo.go`
510 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
511 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
512 echo "type Timeval_sec_t $timeval_sec" >> ${OUT}
513 echo "type Timeval_usec_t $timeval_usec" >> ${OUT}
514 echo $timeval | \
515 sed -e 's/type _timeval /type Timeval /' \
516 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
517 -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
518 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
519 if test "$timespec" = ""; then
520 # IRIX 6.5 has __timespec instead.
521 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
523 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
524 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
525 echo "type Timespec_sec_t $timespec_sec" >> ${OUT}
526 echo "type Timespec_nsec_t $timespec_nsec" >> ${OUT}
527 echo $timespec | \
528 sed -e 's/^type ___timespec /type Timespec /' \
529 -e 's/^type _timespec /type Timespec /' \
530 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
531 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
533 timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
534 if test "$timestruc" != ""; then
535 timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
536 timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
537 echo "type Timestruc_sec_t $timestruc_sec" >> ${OUT}
538 echo "type Timestruc_nsec_t $timestruc_nsec" >> ${OUT}
539 echo $timestruc | \
540 sed -e 's/^type _timestruc_t /type Timestruc /' \
541 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
542 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
545 # The tms struct.
546 grep '^type _tms ' gen-sysinfo.go | \
547 sed -e 's/type _tms/type Tms/' \
548 -e 's/tms_utime/Utime/' \
549 -e 's/tms_stime/Stime/' \
550 -e 's/tms_cutime/Cutime/' \
551 -e 's/tms_cstime/Cstime/' \
552 >> ${OUT}
554 # The stat type.
555 # Prefer largefile variant if available.
556 stat=`grep '^type _stat64 ' gen-sysinfo.go || true`
557 if test "$stat" != ""; then
558 grep '^type _stat64 ' gen-sysinfo.go
559 else
560 grep '^type _stat ' gen-sysinfo.go
561 fi | sed -e 's/type _stat64/type Stat_t/' \
562 -e 's/type _stat/type Stat_t/' \
563 -e 's/st_dev/Dev/' \
564 -e 's/st_ino/Ino/g' \
565 -e 's/st_nlink/Nlink/' \
566 -e 's/st_mode/Mode/' \
567 -e 's/st_uid/Uid/' \
568 -e 's/st_gid/Gid/' \
569 -e 's/st_rdev/Rdev/' \
570 -e 's/st_size/Size/' \
571 -e 's/st_blksize/Blksize/' \
572 -e 's/st_blocks/Blocks/' \
573 -e 's/st_atim/Atim/' \
574 -e 's/st_mtim/Mtim/' \
575 -e 's/st_ctim/Ctim/' \
576 -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
577 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
578 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
579 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
580 -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
581 >> ${OUT}
583 # The directory searching types.
584 # Prefer largefile variant if available.
585 dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true`
586 if test "$dirent" != ""; then
587 grep '^type _dirent64 ' gen-sysinfo.go
588 else
589 grep '^type _dirent ' gen-sysinfo.go
590 fi | sed -e 's/type _dirent64/type Dirent/' \
591 -e 's/type _dirent/type Dirent/' \
592 -e 's/d_name \[0+1\]/d_name [0+256]/' \
593 -e 's/d_name/Name/' \
594 -e 's/]int8/]byte/' \
595 -e 's/d_ino/Ino/' \
596 -e 's/d_off/Off/' \
597 -e 's/d_reclen/Reclen/' \
598 -e 's/d_type/Type/' \
599 >> ${OUT}
600 echo "type DIR _DIR" >> ${OUT}
602 # Values for d_type field in dirent.
603 grep '^const _DT_' gen-sysinfo.go |
604 sed -e 's/^\(const \)_\(DT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
606 # The rusage struct.
607 rusage=`grep '^type _rusage struct' gen-sysinfo.go`
608 if test "$rusage" != ""; then
609 # Remove anonymous unions from GNU/Linux <bits/resource.h>.
610 rusage=`echo $rusage | sed -e 's/Godump_[0-9]* struct {\([^}]*\)};/\1/g'`
611 rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
612 rusage=`echo $rusage | sed -e 's/^ *//'`
613 nrusage=
614 while test -n "$rusage"; do
615 field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
616 rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
617 # Drop the leading ru_, capitalize the next character.
618 field=`echo $field | sed -e 's/^ru_//'`
619 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
620 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
621 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
622 # Fix _timeval _timespec, and _timestruc_t.
623 r=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
624 r=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
625 r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
626 field="$f$r"
627 nrusage="$nrusage $field;"
628 done
629 echo "type Rusage struct {$nrusage }" >> ${OUT}
630 else
631 echo "type Rusage struct {}" >> ${OUT}
634 # The RUSAGE constants.
635 grep '^const _RUSAGE_' gen-sysinfo.go | \
636 sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
638 # The utsname struct.
639 grep '^type _utsname ' gen-sysinfo.go | \
640 sed -e 's/_utsname/Utsname/' \
641 -e 's/sysname/Sysname/' \
642 -e 's/nodename/Nodename/' \
643 -e 's/release/Release/' \
644 -e 's/version/Version/' \
645 -e 's/machine/Machine/' \
646 -e 's/domainname/Domainname/' \
647 >> ${OUT}
649 # The iovec struct.
650 iovec=`grep '^type _iovec ' gen-sysinfo.go`
651 iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
652 echo "type Iovec_len_t $iovec_len" >> ${OUT}
653 echo $iovec | \
654 sed -e 's/_iovec/Iovec/' \
655 -e 's/iov_base/Base/' \
656 -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
657 >> ${OUT}
659 # The msghdr struct.
660 msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
661 msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
662 echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
663 echo $msghdr | \
664 sed -e 's/_msghdr/Msghdr/' \
665 -e 's/msg_name/Name/' \
666 -e 's/msg_namelen/Namelen/' \
667 -e 's/msg_iov/Iov/' \
668 -e 's/msg_iovlen/Iovlen/' \
669 -e 's/_iovec/Iovec/' \
670 -e 's/msg_control/Control/' \
671 -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
672 -e 's/msg_flags/Flags/' \
673 >> ${OUT}
675 # The MSG_ flags for Msghdr.
676 grep '^const _MSG_' gen-sysinfo.go | \
677 sed -e 's/^\(const \)_\(MSG_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
679 # The cmsghdr struct.
680 cmsghdr=`grep '^type _cmsghdr ' gen-sysinfo.go`
681 if test -n "$cmsghdr"; then
682 cmsghdr_len=`echo $cmsghdr | sed -n -e 's/^.*cmsg_len \([^ ]*\);.*$/\1/p'`
683 echo "type Cmsghdr_len_t $cmsghdr_len" >> ${OUT}
684 echo "$cmsghdr" | \
685 sed -e 's/_cmsghdr/Cmsghdr/' \
686 -e 's/cmsg_len *[a-zA-Z0-9_]*/Len Cmsghdr_len_t/' \
687 -e 's/cmsg_level/Level/' \
688 -e 's/cmsg_type/Type/' \
689 -e 's/\[\]/[0]/' \
690 >> ${OUT}
693 # The SCM_ flags for Cmsghdr.
694 grep '^const _SCM_' gen-sysinfo.go | \
695 sed -e 's/^\(const \)_\(SCM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
697 # The ucred struct.
698 grep '^type _ucred ' gen-sysinfo.go | \
699 sed -e 's/_ucred/Ucred/' \
700 -e 's/pid/Pid/' \
701 -e 's/uid/Uid/' \
702 -e 's/gid/Gid/' \
703 >> ${OUT}
705 # The ip_mreq struct.
706 grep '^type _ip_mreq ' gen-sysinfo.go | \
707 sed -e 's/_ip_mreq/IPMreq/' \
708 -e 's/imr_multiaddr/Multiaddr/' \
709 -e 's/imr_interface/Interface/' \
710 -e 's/_in_addr/[4]byte/g' \
711 >> ${OUT}
713 # We need IPMreq to compile the net package.
714 if ! grep 'type IPMreq ' ${OUT} >/dev/null 2>&1; then
715 echo 'type IPMreq struct { Multiaddr [4]byte; Interface [4]byte; }' >> ${OUT}
718 # The ipv6_mreq struct.
719 grep '^type _ipv6_mreq ' gen-sysinfo.go | \
720 sed -e 's/_ipv6_mreq/IPv6Mreq/' \
721 -e 's/ipv6mr_multiaddr/Multiaddr/' \
722 -e 's/ipv6mr_interface/Interface/' \
723 -e 's/_in6_addr/[16]byte/' \
724 >> ${OUT}
726 # We need IPv6Mreq to compile the net package.
727 if ! grep 'type IPv6Mreq ' ${OUT} >/dev/null 2>&1; then
728 echo 'type IPv6Mreq struct { Multiaddr [16]byte; Interface uint32; }' >> ${OUT}
731 # The ip_mreqn struct.
732 grep '^type _ip_mreqn ' gen-sysinfo.go | \
733 sed -e 's/_ip_mreqn/IPMreqn/' \
734 -e 's/imr_multiaddr/Multiaddr/' \
735 -e 's/imr_address/Address/' \
736 -e 's/imr_ifindex/Ifindex/' \
737 -e 's/_in_addr/[4]byte/g' \
738 >> ${OUT}
740 # We need IPMreq to compile the net package.
741 if ! grep 'type IPMreqn ' ${OUT} >/dev/null 2>&1; then
742 echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT}
745 # The icmp6_filter struct.
746 grep '^type _icmp6_filter ' gen-sysinfo.go | \
747 sed -e 's/_icmp6_filter/ICMPv6Filter/' \
748 -e 's/data/Data/' \
749 -e 's/filt/Filt/' \
750 >> ${OUT}
752 # We need ICMPv6Filter to compile the syscall package.
753 if ! grep 'type ICMPv6Filter ' ${OUT} > /dev/null 2>&1; then
754 echo 'type ICMPv6Filter struct { Data [8]uint32 }' >> ${OUT}
757 # Try to guess the type to use for fd_set.
758 fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
759 fds_bits_type="_C_long"
760 if test "$fd_set" != ""; then
761 fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
763 echo "type fds_bits_type $fds_bits_type" >> ${OUT}
765 # The addrinfo struct.
766 grep '^type _addrinfo ' gen-sysinfo.go | \
767 sed -e 's/_addrinfo/Addrinfo/g' \
768 -e 's/ ai_/ Ai_/g' \
769 >> ${OUT}
771 # The addrinfo flags and errors.
772 grep '^const _AI_' gen-sysinfo.go | \
773 sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
774 grep '^const _EAI_' gen-sysinfo.go | \
775 sed -e 's/^\(const \)_\(EAI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
777 # The passwd struct.
778 grep '^type _passwd ' gen-sysinfo.go | \
779 sed -e 's/_passwd/Passwd/' \
780 -e 's/ pw_/ Pw_/g' \
781 >> ${OUT}
783 # The ioctl flags for the controlling TTY.
784 grep '^const _TIOC' gen-sysinfo.go | \
785 grep -v '_val =' | \
786 sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
787 # We need TIOCGWINSZ.
788 if ! grep '^const TIOCGWINSZ' ${OUT} >/dev/null 2>&1; then
789 if grep '^const _TIOCGWINSZ_val' ${OUT} >/dev/null 2>&1; then
790 echo 'const TIOCGWINSZ = _TIOCGWINSZ_val' >> ${OUT}
793 if ! grep '^const TIOCNOTTY' ${OUT} >/dev/null 2>&1; then
794 if grep '^const _TIOCNOTTY_val' ${OUT} >/dev/null 2>&1; then
795 echo 'const TIOCNOTTY = _TIOCNOTTY_val' >> ${OUT}
798 if ! grep '^const TIOCSCTTY' ${OUT} >/dev/null 2>&1; then
799 if grep '^const _TIOCSCTTY_val' ${OUT} >/dev/null 2>&1; then
800 echo 'const TIOCSCTTY = _TIOCSCTTY_val' >> ${OUT}
803 if ! grep '^const TIOCGPTN' ${OUT} >/dev/null 2>&1; then
804 if grep '^const _TIOCGPTN_val' ${OUT} >/dev/null 2>&1; then
805 echo 'const TIOCGPTN = _TIOCGPTN_val' >> ${OUT}
808 if ! grep '^const TIOCSPTLCK' ${OUT} >/dev/null 2>&1; then
809 if grep '^const _TIOCSPTLCK_val' ${OUT} >/dev/null 2>&1; then
810 echo 'const TIOCSPTLCK = _TIOCSPTLCK_val' >> ${OUT}
813 if ! grep '^const TIOCGDEV' ${OUT} >/dev/null 2>&1; then
814 if grep '^const _TIOCGDEV_val' ${OUT} >/dev/null 2>&1; then
815 echo 'const TIOCGDEV = _TIOCGDEV_val' >> ${OUT}
818 if ! grep '^const TIOCSIG' ${OUT} >/dev/null 2>&1; then
819 if grep '^const _TIOCSIG_val' ${OUT} >/dev/null 2>&1; then
820 echo 'const TIOCSIG = _TIOCSIG_val' >> ${OUT}
824 # The ioctl flags for terminal control
825 grep '^const _TC[GS]ET' gen-sysinfo.go | \
826 sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
828 # ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but
829 # needs handling in syscalls.exec.go.
830 if ! grep '^const _TIOCSCTTY ' gen-sysinfo.go >/dev/null 2>&1; then
831 if grep '^const _TIOCNXCL ' gen-sysinfo.go >/dev/null 2>&1; then
832 echo "const TIOCSCTTY = TIOCNXCL" >> ${OUT}
836 # The nlmsghdr struct.
837 grep '^type _nlmsghdr ' gen-sysinfo.go | \
838 sed -e 's/_nlmsghdr/NlMsghdr/' \
839 -e 's/nlmsg_len/Len/' \
840 -e 's/nlmsg_type/Type/' \
841 -e 's/nlmsg_flags/Flags/' \
842 -e 's/nlmsg_seq/Seq/' \
843 -e 's/nlmsg_pid/Pid/' \
844 >> ${OUT}
846 # The nlmsg flags and operators.
847 grep '^const _NLM' gen-sysinfo.go | \
848 sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
850 # NLMSG_HDRLEN is defined as an expression using sizeof.
851 if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev/null 2>&1; then
852 if grep '^const _sizeof_nlmsghdr ' ${OUT} > /dev/null 2>&1; then
853 echo 'const NLMSG_HDRLEN = (_sizeof_nlmsghdr + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1)' >> ${OUT}
857 # The rtmsg struct.
858 grep '^type _rtmsg ' gen-sysinfo.go | \
859 sed -e 's/_rtmsg/RtMsg/' \
860 -e 's/rtm_family/Family/' \
861 -e 's/rtm_dst_len/Dst_len/' \
862 -e 's/rtm_src_len/Src_len/' \
863 -e 's/rtm_tos/Tos/' \
864 -e 's/rtm_table/Table/' \
865 -e 's/rtm_protocol/Protocol/' \
866 -e 's/rtm_scope/Scope/' \
867 -e 's/rtm_type/Type/' \
868 -e 's/rtm_flags/Flags/' \
869 >> ${OUT}
871 # The rtgenmsg struct.
872 grep '^type _rtgenmsg ' gen-sysinfo.go | \
873 sed -e 's/_rtgenmsg/RtGenmsg/' \
874 -e 's/rtgen_family/Family/' \
875 >> ${OUT}
877 # The routing message flags.
878 grep '^const _RT_' gen-sysinfo.go | \
879 sed -e 's/^\(const \)_\(RT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
880 grep '^const _RTA' gen-sysinfo.go | \
881 sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
882 grep '^const _RTF' gen-sysinfo.go | \
883 sed -e 's/^\(const \)_\(RTF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
884 grep '^const _RTCF' gen-sysinfo.go | \
885 sed -e 's/^\(const \)_\(RTCF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
886 grep '^const _RTM' gen-sysinfo.go | \
887 sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
888 grep '^const _RTN' gen-sysinfo.go | \
889 sed -e 's/^\(const \)_\(RTN[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
890 grep '^const _RTPROT' gen-sysinfo.go | \
891 sed -e 's/^\(const \)_\(RTPROT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
893 # The ifinfomsg struct.
894 grep '^type _ifinfomsg ' gen-sysinfo.go | \
895 sed -e 's/_ifinfomsg/IfInfomsg/' \
896 -e 's/ifi_family/Family/' \
897 -e 's/ifi_type/Type/' \
898 -e 's/ifi_index/Index/' \
899 -e 's/ifi_flags/Flags/' \
900 -e 's/ifi_change/Change/' \
901 >> ${OUT}
903 # The interface information types and flags.
904 grep '^const _IFA' gen-sysinfo.go | \
905 sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
906 grep '^const _IFLA' gen-sysinfo.go | \
907 sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
908 grep '^const _IFF' gen-sysinfo.go | \
909 sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
910 grep '^const _IFNAMSIZ' gen-sysinfo.go | \
911 sed -e 's/^\(const \)_\(IFNAMSIZ[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
912 grep '^const _SIOC' gen-sysinfo.go |
913 sed -e 's/^\(const \)_\(SIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
915 # The ifaddrmsg struct.
916 grep '^type _ifaddrmsg ' gen-sysinfo.go | \
917 sed -e 's/_ifaddrmsg/IfAddrmsg/' \
918 -e 's/ifa_family/Family/' \
919 -e 's/ifa_prefixlen/Prefixlen/' \
920 -e 's/ifa_flags/Flags/' \
921 -e 's/ifa_scope/Scope/' \
922 -e 's/ifa_index/Index/' \
923 >> ${OUT}
925 # The rtattr struct.
926 grep '^type _rtattr ' gen-sysinfo.go | \
927 sed -e 's/_rtattr/RtAttr/' \
928 -e 's/rta_len/Len/' \
929 -e 's/rta_type/Type/' \
930 >> ${OUT}
932 # The in_pktinfo struct.
933 grep '^type _in_pktinfo ' gen-sysinfo.go | \
934 sed -e 's/_in_pktinfo/Inet4Pktinfo/' \
935 -e 's/ipi_ifindex/Ifindex/' \
936 -e 's/ipi_spec_dst/Spec_dst/' \
937 -e 's/ipi_addr/Addr/' \
938 -e 's/_in_addr/[4]byte/g' \
939 >> ${OUT}
941 # The in6_pktinfo struct.
942 grep '^type _in6_pktinfo ' gen-sysinfo.go | \
943 sed -e 's/_in6_pktinfo/Inet6Pktinfo/' \
944 -e 's/ipi6_addr/Addr/' \
945 -e 's/ipi6_ifindex/Ifindex/' \
946 -e 's/_in6_addr/[16]byte/' \
947 >> ${OUT}
949 # The termios struct.
950 grep '^type _termios ' gen-sysinfo.go | \
951 sed -e 's/_termios/Termios/' \
952 -e 's/c_iflag/Iflag/' \
953 -e 's/c_oflag/Oflag/' \
954 -e 's/c_cflag/Cflag/' \
955 -e 's/c_lflag/Lflag/' \
956 -e 's/c_line/Line/' \
957 -e 's/c_cc/Cc/' \
958 -e 's/c_ispeed/Ispeed/' \
959 -e 's/c_ospeed/Ospeed/' \
960 >> ${OUT}
962 # The termios constants.
963 for n in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \
964 IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \
965 OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 CS5 CS6 CS7 CS8 TABDLY \
966 BSDLY VTDLY FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL \
967 CLOCAL LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE ECHO ECHOE ECHOK \
968 ECHONL ECHOCTL ECHOPRT ECHOKE DEFECHO FLUSHO NOFLSH TOSTOP PENDIN IEXTEN \
969 VINTR VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 VSWTCH VSTART VSTOP \
970 VSUSP VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS TCSANOW TCSADRAIN \
971 TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON TCIOFF TCION B0 B50 \
972 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 \
973 B38400 B57600 B115200 B230400 B460800 B500000 B576000 B921600 B1000000 \
974 B1152000 B1500000 B2000000 B2500000 B3000000 B3500000 B4000000; do
976 grep "^const _$n " gen-sysinfo.go | \
977 sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
978 done
980 # The mount flags
981 grep '^const _MNT_' gen-sysinfo.go |
982 sed -e 's/^\(const \)_\(MNT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
983 grep '^const _MS_' gen-sysinfo.go |
984 sed -e 's/^\(const \)_\(MS_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
986 # The fallocate flags.
987 grep '^const _FALLOC_' gen-sysinfo.go |
988 sed -e 's/^\(const \)_\(FALLOC_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
990 # The statfs struct.
991 # Prefer largefile variant if available.
992 statfs=`grep '^type _statfs64 ' gen-sysinfo.go || true`
993 if test "$statfs" != ""; then
994 grep '^type _statfs64 ' gen-sysinfo.go
995 else
996 grep '^type _statfs ' gen-sysinfo.go
997 fi | sed -e 's/type _statfs64/type Statfs_t/' \
998 -e 's/type _statfs/type Statfs_t/' \
999 -e 's/f_type/Type/' \
1000 -e 's/f_bsize/Bsize/' \
1001 -e 's/f_blocks/Blocks/' \
1002 -e 's/f_bfree/Bfree/' \
1003 -e 's/f_bavail/Bavail/' \
1004 -e 's/f_files/Files/' \
1005 -e 's/f_ffree/Ffree/' \
1006 -e 's/f_fsid/Fsid/' \
1007 -e 's/f_namelen/Namelen/' \
1008 -e 's/f_frsize/Frsize/' \
1009 -e 's/f_flags/Flags/' \
1010 -e 's/f_spare/Spare/' \
1011 >> ${OUT}
1013 # The timex struct.
1014 timex=`grep '^type _timex ' gen-sysinfo.go || true`
1015 if test "$timex" = ""; then
1016 timex=`grep '^// type _timex ' gen-sysinfo.go || true`
1017 if test "$timex" != ""; then
1018 timex=`echo $timex | sed -e 's|// ||' -e 's/INVALID-bit-field/int32/g'`
1021 if test "$timex" != ""; then
1022 echo "$timex" | \
1023 sed -e 's/_timex/Timex/' \
1024 -e 's/modes/Modes/' \
1025 -e 's/offset/Offset/' \
1026 -e 's/freq/Freq/' \
1027 -e 's/maxerror/Maxerror/' \
1028 -e 's/esterror/Esterror/' \
1029 -e 's/status/Status/' \
1030 -e 's/constant/Constant/' \
1031 -e 's/precision/Precision/' \
1032 -e 's/tolerance/Tolerance/' \
1033 -e 's/ time / Time /' \
1034 -e 's/tick/Tick/' \
1035 -e 's/ppsfreq/Ppsfreq/' \
1036 -e 's/jitter/Jitter/' \
1037 -e 's/shift/Shift/' \
1038 -e 's/stabil/Stabil/' \
1039 -e 's/jitcnt/Jitcnt/' \
1040 -e 's/calcnt/Calcnt/' \
1041 -e 's/errcnt/Errcnt/' \
1042 -e 's/stbcnt/Stbcnt/' \
1043 -e 's/tai/Tai/' \
1044 -e 's/_timeval/Timeval/' \
1045 >> ${OUT}
1048 # The rlimit struct.
1049 grep '^type _rlimit ' gen-sysinfo.go | \
1050 sed -e 's/_rlimit/Rlimit/' \
1051 -e 's/rlim_cur/Cur/' \
1052 -e 's/rlim_max/Max/' \
1053 >> ${OUT}
1055 # The RLIMIT constants.
1056 grep '^const _RLIMIT_' gen-sysinfo.go |
1057 sed -e 's/^\(const \)_\(RLIMIT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1058 grep '^const _RLIM_' gen-sysinfo.go |
1059 sed -e 's/^\(const \)_\(RLIM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1061 # The sysinfo struct.
1062 grep '^type _sysinfo ' gen-sysinfo.go | \
1063 sed -e 's/_sysinfo/Sysinfo_t/' \
1064 -e 's/uptime/Uptime/' \
1065 -e 's/loads/Loads/' \
1066 -e 's/totalram/Totalram/' \
1067 -e 's/freeram/Freeram/' \
1068 -e 's/sharedram/Sharedram/' \
1069 -e 's/bufferram/Bufferram/' \
1070 -e 's/totalswap/Totalswap/' \
1071 -e 's/freeswap/Freeswap/' \
1072 -e 's/procs/Procs/' \
1073 -e 's/totalhigh/Totalhigh/' \
1074 -e 's/freehigh/Freehigh/' \
1075 -e 's/mem_unit/Unit/' \
1076 >> ${OUT}
1078 # The ustat struct.
1079 grep '^type _ustat ' gen-sysinfo.go | \
1080 sed -e 's/_ustat/Ustat_t/' \
1081 -e 's/f_tfree/Tfree/' \
1082 -e 's/f_tinode/Tinoe/' \
1083 -e 's/f_fname/Fname/' \
1084 -e 's/f_fpack/Fpack/' \
1085 >> ${OUT}
1086 # Force it to be defined, as on some older GNU/Linux systems the
1087 # header file fails when using with <linux/filter.h>.
1088 if ! grep 'type _ustat ' gen-sysinfo.go >/dev/null 2>&1; then
1089 echo 'type Ustat_t struct { Tfree int32; Tinoe uint64; Fname [5+1]int8; Fpack [5+1]int8; }' >> ${OUT}
1092 # The utimbuf struct.
1093 grep '^type _utimbuf ' gen-sysinfo.go | \
1094 sed -e 's/_utimbuf/Utimbuf/' \
1095 -e 's/actime/Actime/' \
1096 -e 's/modtime/Modtime/' \
1097 >> ${OUT}
1099 # The LOCK flags for flock.
1100 grep '^const _LOCK_' gen-sysinfo.go |
1101 sed -e 's/^\(const \)_\(LOCK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1103 # The PRIO constants.
1104 grep '^const _PRIO_' gen-sysinfo.go | \
1105 sed -e 's/^\(const \)_\(PRIO_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1107 # The GNU/Linux LINUX_REBOOT flags.
1108 grep '^const _LINUX_REBOOT_' gen-sysinfo.go |
1109 sed -e 's/^\(const \)_\(LINUX_REBOOT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1111 # The GNU/Linux sock_filter struct.
1112 grep '^type _sock_filter ' gen-sysinfo.go | \
1113 sed -e 's/_sock_filter/SockFilter/' \
1114 -e 's/code/Code/' \
1115 -e 's/jt/Jt/' \
1116 -e 's/jf/Jf/' \
1117 -e 's/k /K /' \
1118 >> ${OUT}
1120 # The GNU/Linux sock_fprog struct.
1121 grep '^type _sock_fprog ' gen-sysinfo.go | \
1122 sed -e 's/_sock_fprog/SockFprog/' \
1123 -e 's/len/Len/' \
1124 -e 's/filter/Filter/' \
1125 -e 's/_sock_filter/SockFilter/' \
1126 >> ${OUT}
1128 # The GNU/Linux filter flags.
1129 grep '^const _BPF_' gen-sysinfo.go | \
1130 sed -e 's/^\(const \)_\(BPF_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1132 # The GNU/Linux nlattr struct.
1133 grep '^type _nlattr ' gen-sysinfo.go | \
1134 sed -e 's/_nlattr/NlAttr/' \
1135 -e 's/nla_len/Len/' \
1136 -e 's/nla_type/Type/' \
1137 >> ${OUT}
1139 # The GNU/Linux nlmsgerr struct.
1140 grep '^type _nlmsgerr ' gen-sysinfo.go | \
1141 sed -e 's/_nlmsgerr/NlMsgerr/' \
1142 -e 's/error/Error/' \
1143 -e 's/msg/Msg/' \
1144 -e 's/_nlmsghdr/NlMsghdr/' \
1145 >> ${OUT}
1147 # The GNU/Linux rtnexthop struct.
1148 grep '^type _rtnexthop ' gen-sysinfo.go | \
1149 sed -e 's/_rtnexthop/RtNexthop/' \
1150 -e 's/rtnh_len/Len/' \
1151 -e 's/rtnh_flags/Flags/' \
1152 -e 's/rtnh_hops/Hops/' \
1153 -e 's/rtnh_ifindex/Ifindex/' \
1154 >> ${OUT}
1156 # The GNU/Linux netlink flags.
1157 grep '^const _NETLINK_' gen-sysinfo.go | \
1158 sed -e 's/^\(const \)_\(NETLINK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1159 grep '^const _NLA_' gen-sysinfo.go | \
1160 sed -e 's/^\(const \)_\(NLA_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1162 # The GNU/Linux packet socket flags.
1163 grep '^const _PACKET_' gen-sysinfo.go | \
1164 sed -e 's/^\(const \)_\(PACKET_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1166 # The GNU/Linux inotify_event struct.
1167 grep '^type _inotify_event ' gen-sysinfo.go | \
1168 sed -e 's/_inotify_event/InotifyEvent/' \
1169 -e 's/wd/Wd/' \
1170 -e 's/mask/Mask/' \
1171 -e 's/cookie/Cookie/' \
1172 -e 's/len/Len/' \
1173 -e 's/name/Name/' \
1174 -e 's/\[\]/[0]/' \
1175 -e 's/\[0\]byte/[0]int8/' \
1176 >> ${OUT}
1178 # The GNU/Linux CLONE flags.
1179 grep '^const _CLONE_' gen-sysinfo.go | \
1180 sed -e 's/^\(const \)_\(CLONE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1182 # The Solaris 11 Update 1 _zone_net_addr_t struct.
1183 grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
1184 sed -e 's/_in6_addr/[16]byte/' \
1185 >> ${OUT}
1187 # Struct sizes.
1188 set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \
1189 ifaddrmsg IfAddrmsg ifinfomsg IfInfomsg in_pktinfo Inet4Pktinfo \
1190 in6_pktinfo Inet6Pktinfo inotify_event InotifyEvent linger Linger \
1191 msghdr Msghdr nlattr NlAttr nlmsgerr NlMsgerr nlmsghdr NlMsghdr \
1192 rtattr RtAttr rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \
1193 sock_filter SockFilter sock_fprog SockFprog ucred Ucred \
1194 icmp6_filter ICMPv6Filter
1195 while test $# != 0; do
1196 nc=$1
1197 ngo=$2
1198 shift
1199 shift
1200 if grep "^const _sizeof_$nc =" gen-sysinfo.go >/dev/null 2>&1; then
1201 echo "const Sizeof$ngo = _sizeof_$nc" >> ${OUT}
1203 done
1205 # In order to compile the net package, we need some sizes to exist
1206 # even if the types do not.
1207 if ! grep 'const SizeofIPMreq ' ${OUT} >/dev/null 2>&1; then
1208 echo 'const SizeofIPMreq = 8' >> ${OUT}
1210 if ! grep 'const SizeofIPv6Mreq ' ${OUT} >/dev/null 2>&1; then
1211 echo 'const SizeofIPv6Mreq = 20' >> ${OUT}
1213 if ! grep 'const SizeofIPMreqn ' ${OUT} >/dev/null 2>&1; then
1214 echo 'const SizeofIPMreqn = 12' >> ${OUT}
1216 if ! grep 'const SizeofICMPv6Filter ' ${OUT} >/dev/null 2>&1; then
1217 echo 'const SizeofICMPv6Filter = 32' >> ${OUT}
1220 exit $?