Merged revisions 195901,195904,196012 via svnmerge from
[official-gcc.git] / main / libgo / mksysinfo.sh
blobe8ab1eb27ac947cc0c0d18bbee7c2dafd491ab09
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
164 /* Constants that may only be defined as expressions on some systems,
165 expressions too complex for -fdump-go-spec to handle. These are
166 handled specially below. */
167 enum {
168 #ifdef TIOCGWINSZ
169 TIOCGWINSZ_val = TIOCGWINSZ,
170 #endif
171 #ifdef TIOCNOTTY
172 TIOCNOTTY_val = TIOCNOTTY,
173 #endif
174 #ifdef TIOCSCTTY
175 TIOCSCTTY_val = TIOCSCTTY,
176 #endif
180 ${CC} -fdump-go-spec=gen-sysinfo.go -std=gnu99 -S -o sysinfo.s sysinfo.c
182 echo 'package syscall' > ${OUT}
183 echo 'import "unsafe"' >> ${OUT}
184 echo 'type _ unsafe.Pointer' >> ${OUT}
186 # Get all the consts and types, skipping ones which could not be
187 # represented in Go and ones which we need to rewrite. We also skip
188 # function declarations, as we don't need them here. All the symbols
189 # will all have a leading underscore.
190 grep -v '^// ' gen-sysinfo.go | \
191 grep -v '^func' | \
192 grep -v '^type _timeval ' | \
193 grep -v '^type _timespec_t ' | \
194 grep -v '^type _timespec ' | \
195 grep -v '^type _timestruc_t ' | \
196 grep -v '^type _epoll_' | \
197 grep -v 'in6_addr' | \
198 grep -v 'sockaddr_in6' | \
199 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
200 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
201 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
202 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
203 >> ${OUT}
205 # The errno constants. These get type Errno.
206 echo '#include <errno.h>' | ${CC} -x c - -E -dM | \
207 egrep '#define E[A-Z0-9_]+ ' | \
208 sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(_\1)/' >> ${OUT}
210 # The O_xxx flags.
211 egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
212 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
213 if ! grep '^const O_ASYNC' ${OUT} >/dev/null 2>&1; then
214 echo "const O_ASYNC = 0" >> ${OUT}
216 if ! grep '^const O_CLOEXEC' ${OUT} >/dev/null 2>&1; then
217 echo "const O_CLOEXEC = 0" >> ${OUT}
220 # These flags can be lost on i386 GNU/Linux when using
221 # -D_FILE_OFFSET_BITS=64, because we see "#define F_SETLK F_SETLK64"
222 # before we see the definition of F_SETLK64.
223 for flag in F_GETLK F_SETLK F_SETLKW; do
224 if ! grep "^const ${flag} " ${OUT} >/dev/null 2>&1 \
225 && grep "^const ${flag}64 " ${OUT} >/dev/null 2>&1; then
226 echo "const ${flag} = ${flag}64" >> ${OUT}
228 done
230 # The signal numbers.
231 grep '^const _SIG[^_]' gen-sysinfo.go | \
232 grep -v '^const _SIGEV_' | \
233 sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = Signal(_\2)/' >> ${OUT}
234 if ! grep '^const SIGPOLL ' ${OUT} >/dev/null 2>&1; then
235 if grep '^const SIGIO ' ${OUT} > /dev/null 2>&1; then
236 echo "const SIGPOLL = SIGIO" >> ${OUT}
239 if ! grep '^const SIGCLD ' ${OUT} >/dev/null 2>&1; then
240 if grep '^const SIGCHLD ' ${OUT} >/dev/null 2>&1; then
241 echo "const SIGCLD = SIGCHLD" >> ${OUT}
245 # The syscall numbers. We force the names to upper case.
246 grep '^const _SYS_' gen-sysinfo.go | \
247 sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \
248 while read sys; do
249 sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
250 echo "const $sup = _$sys" >> ${OUT}
251 done
253 # The GNU/Linux support wants to use SYS_GETDENTS64 if available.
254 if ! grep '^const SYS_GETDENTS ' ${OUT} >/dev/null 2>&1; then
255 echo "const SYS_GETDENTS = 0" >> ${OUT}
257 if ! grep '^const SYS_GETDENTS64 ' ${OUT} >/dev/null 2>&1; then
258 echo "const SYS_GETDENTS64 = 0" >> ${OUT}
261 # Stat constants.
262 grep '^const _S_' gen-sysinfo.go | \
263 sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
265 # Mmap constants.
266 grep '^const _PROT_' gen-sysinfo.go | \
267 sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
268 grep '^const _MAP_' gen-sysinfo.go | \
269 sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
270 grep '^const _MADV_' gen-sysinfo.go | \
271 sed -e 's/^\(const \)_\(MADV_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
272 grep '^const _MCL_' gen-sysinfo.go | \
273 sed -e 's/^\(const \)_\(MCL_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
275 # Process status constants.
276 grep '^const _W' gen-sysinfo.go |
277 sed -e 's/^\(const \)_\(W[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
278 # WSTOPPED was introduced in glibc 2.3.4.
279 if ! grep '^const _WSTOPPED = ' gen-sysinfo.go >/dev/null 2>&1; then
280 if grep '^const _WUNTRACED = ' gen-sysinfo.go > /dev/null 2>&1; then
281 echo 'const WSTOPPED = _WUNTRACED' >> ${OUT}
282 else
283 echo 'const WSTOPPED = 2' >> ${OUT}
286 if grep '^const ___WALL = ' gen-sysinfo.go >/dev/null 2>&1 \
287 && ! grep '^const _WALL = ' gen-sysinfo.go >/dev/null 2>&1; then
288 echo 'const WALL = ___WALL' >> ${OUT}
291 # Networking constants.
292 egrep '^const _(AF|ARPHRD|ETH|IN|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
293 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
294 grep '^const _SOMAXCONN' gen-sysinfo.go |
295 sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
296 >> ${OUT}
297 grep '^const _SHUT_' gen-sysinfo.go |
298 sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
300 # The net package requires some const definitions.
301 for m in IP_PKTINFO IPV6_V6ONLY IPPROTO_IPV6 IPV6_JOIN_GROUP IPV6_LEAVE_GROUP IPV6_TCLASS SO_REUSEPORT; do
302 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
303 echo "const $m = 0" >> ${OUT}
305 done
306 for m in SOCK_CLOEXEC SOCK_NONBLOCK; do
307 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
308 echo "const $m = -1" >> ${OUT}
310 done
312 # pathconf constants.
313 grep '^const __PC' gen-sysinfo.go |
314 sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
316 # The PATH_MAX constant.
317 if grep '^const _PATH_MAX ' gen-sysinfo.go >/dev/null 2>&1; then
318 echo 'const PathMax = _PATH_MAX' >> ${OUT}
321 # epoll constants.
322 grep '^const _EPOLL' gen-sysinfo.go |
323 sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
324 # Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
325 if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
326 echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
328 if ! grep '^const EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
329 echo "const EPOLL_CLOEXEC = 02000000" >> ${OUT}
332 # Prctl constants.
333 grep '^const _PR_' gen-sysinfo.go |
334 sed -e 's/^\(const \)_\(PR_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
336 # Ptrace constants.
337 grep '^const _PTRACE' gen-sysinfo.go |
338 sed -e 's/^\(const \)_\(PTRACE[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
339 # We need some ptrace options that are not defined in older versions
340 # of glibc.
341 if ! grep '^const PTRACE_SETOPTIONS' ${OUT} > /dev/null 2>&1; then
342 echo "const PTRACE_SETOPTIONS = 0x4200" >> ${OUT}
344 if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then
345 echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
347 if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then
348 echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
350 if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then
351 echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
353 if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then
354 echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
356 if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then
357 echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
359 if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then
360 echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
362 if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then
363 echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
365 if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then
366 echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
368 if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
369 echo "const PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
371 if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
372 echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
374 if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then
375 echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
377 if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then
378 echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
380 if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then
381 echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
383 if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then
384 echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
386 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
387 echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
389 if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
390 echo "const _PTRACE_TRACEME = 0" >> ${OUT}
393 # The registers returned by PTRACE_GETREGS. This is probably
394 # GNU/Linux specific; it should do no harm if there is no
395 # _user_regs_struct.
396 regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
397 if test "$regs" != ""; then
398 regs=`echo $regs | sed -e 's/type _user_regs_struct struct //' -e 's/[{}]//g'`
399 regs=`echo $regs | sed -e s'/^ *//'`
400 nregs=
401 while test -n "$regs"; do
402 field=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
403 regs=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
404 # Capitalize the first character of the field.
405 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
406 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
407 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
408 field="$f$r"
409 nregs="$nregs $field;"
410 done
411 echo "type PtraceRegs struct {$nregs }" >> ${OUT}
414 # Some basic types.
415 echo 'type Size_t _size_t' >> ${OUT}
416 echo "type Ssize_t _ssize_t" >> ${OUT}
417 if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then
418 echo "type Offset_t _off64_t" >> ${OUT}
419 else
420 echo "type Offset_t _off_t" >> ${OUT}
422 echo "type Mode_t _mode_t" >> ${OUT}
423 echo "type Pid_t _pid_t" >> ${OUT}
424 echo "type Uid_t _uid_t" >> ${OUT}
425 echo "type Gid_t _gid_t" >> ${OUT}
426 echo "type Socklen_t _socklen_t" >> ${OUT}
428 # The C int type.
429 sizeof_int=`grep '^const ___SIZEOF_INT__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
430 if test "$sizeof_int" = "4"; then
431 echo "type _C_int int32" >> ${OUT}
432 echo "type _C_uint uint32" >> ${OUT}
433 elif test "$sizeof_int" = "8"; then
434 echo "type _C_int int64" >> ${OUT}
435 echo "type _C_uint uint64" >> ${OUT}
436 else
437 echo 1>&2 "mksysinfo.sh: could not determine size of int (got $sizeof_int)"
438 exit 1
441 # The C long type, needed because that is the type that ptrace returns.
442 sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
443 if test "$sizeof_long" = "4"; then
444 echo "type _C_long int32" >> ${OUT}
445 elif test "$sizeof_long" = "8"; then
446 echo "type _C_long int64" >> ${OUT}
447 else
448 echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
449 exit 1
452 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
453 # double is commented by -fdump-go-spec.
454 if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
455 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
457 if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
458 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
461 # The time_t type.
462 if grep '^type _time_t ' gen-sysinfo.go > /dev/null 2>&1; then
463 echo 'type Time_t _time_t' >> ${OUT}
466 # The time structures need special handling: we need to name the
467 # types, so that we can cast integers to the right types when
468 # assigning to the structures.
469 timeval=`grep '^type _timeval ' gen-sysinfo.go`
470 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
471 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
472 echo "type Timeval_sec_t $timeval_sec" >> ${OUT}
473 echo "type Timeval_usec_t $timeval_usec" >> ${OUT}
474 echo $timeval | \
475 sed -e 's/type _timeval /type Timeval /' \
476 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
477 -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
478 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
479 if test "$timespec" = ""; then
480 # IRIX 6.5 has __timespec instead.
481 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
483 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
484 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
485 echo "type Timespec_sec_t $timespec_sec" >> ${OUT}
486 echo "type Timespec_nsec_t $timespec_nsec" >> ${OUT}
487 echo $timespec | \
488 sed -e 's/^type ___timespec /type Timespec /' \
489 -e 's/^type _timespec /type Timespec /' \
490 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
491 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
493 timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
494 if test "$timestruc" != ""; then
495 timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
496 timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
497 echo "type Timestruc_sec_t $timestruc_sec" >> ${OUT}
498 echo "type Timestruc_nsec_t $timestruc_nsec" >> ${OUT}
499 echo $timestruc | \
500 sed -e 's/^type _timestruc_t /type Timestruc /' \
501 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
502 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
505 # The tms struct.
506 grep '^type _tms ' gen-sysinfo.go | \
507 sed -e 's/type _tms/type Tms/' \
508 -e 's/tms_utime/Utime/' \
509 -e 's/tms_stime/Stime/' \
510 -e 's/tms_cutime/Cutime/' \
511 -e 's/tms_cstime/Cstime/' \
512 >> ${OUT}
514 # The stat type.
515 # Prefer largefile variant if available.
516 stat=`grep '^type _stat64 ' gen-sysinfo.go || true`
517 if test "$stat" != ""; then
518 grep '^type _stat64 ' gen-sysinfo.go
519 else
520 grep '^type _stat ' gen-sysinfo.go
521 fi | sed -e 's/type _stat64/type Stat_t/' \
522 -e 's/type _stat/type Stat_t/' \
523 -e 's/st_dev/Dev/' \
524 -e 's/st_ino/Ino/g' \
525 -e 's/st_nlink/Nlink/' \
526 -e 's/st_mode/Mode/' \
527 -e 's/st_uid/Uid/' \
528 -e 's/st_gid/Gid/' \
529 -e 's/st_rdev/Rdev/' \
530 -e 's/st_size/Size/' \
531 -e 's/st_blksize/Blksize/' \
532 -e 's/st_blocks/Blocks/' \
533 -e 's/st_atim/Atim/' \
534 -e 's/st_mtim/Mtim/' \
535 -e 's/st_ctim/Ctim/' \
536 -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
537 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
538 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
539 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
540 -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
541 >> ${OUT}
543 # The directory searching types.
544 # Prefer largefile variant if available.
545 dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true`
546 if test "$dirent" != ""; then
547 grep '^type _dirent64 ' gen-sysinfo.go
548 else
549 grep '^type _dirent ' gen-sysinfo.go
550 fi | sed -e 's/type _dirent64/type Dirent/' \
551 -e 's/type _dirent/type Dirent/' \
552 -e 's/d_name \[0+1\]/d_name [0+256]/' \
553 -e 's/d_name/Name/' \
554 -e 's/]int8/]byte/' \
555 -e 's/d_ino/Ino/' \
556 -e 's/d_off/Off/' \
557 -e 's/d_reclen/Reclen/' \
558 -e 's/d_type/Type/' \
559 >> ${OUT}
560 echo "type DIR _DIR" >> ${OUT}
562 # Values for d_type field in dirent.
563 grep '^const _DT_' gen-sysinfo.go |
564 sed -e 's/^\(const \)_\(DT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
566 # The rusage struct.
567 rusage=`grep '^type _rusage struct' gen-sysinfo.go`
568 if test "$rusage" != ""; then
569 # Remove anonymous unions from GNU/Linux <bits/resource.h>.
570 rusage=`echo $rusage | sed -e 's/Godump_[0-9]* struct {\([^}]*\)};/\1/g'`
571 rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
572 rusage=`echo $rusage | sed -e 's/^ *//'`
573 nrusage=
574 while test -n "$rusage"; do
575 field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
576 rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
577 # Drop the leading ru_, capitalize the next character.
578 field=`echo $field | sed -e 's/^ru_//'`
579 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
580 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
581 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
582 # Fix _timeval _timespec, and _timestruc_t.
583 r=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
584 r=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
585 r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
586 field="$f$r"
587 nrusage="$nrusage $field;"
588 done
589 echo "type Rusage struct {$nrusage }" >> ${OUT}
590 else
591 echo "type Rusage struct {}" >> ${OUT}
594 # The RUSAGE constants.
595 grep '^const _RUSAGE_' gen-sysinfo.go | \
596 sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
598 # The utsname struct.
599 grep '^type _utsname ' gen-sysinfo.go | \
600 sed -e 's/_utsname/Utsname/' \
601 -e 's/sysname/Sysname/' \
602 -e 's/nodename/Nodename/' \
603 -e 's/release/Release/' \
604 -e 's/version/Version/' \
605 -e 's/machine/Machine/' \
606 -e 's/domainname/Domainname/' \
607 >> ${OUT}
609 # The iovec struct.
610 iovec=`grep '^type _iovec ' gen-sysinfo.go`
611 iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
612 echo "type Iovec_len_t $iovec_len" >> ${OUT}
613 echo $iovec | \
614 sed -e 's/_iovec/Iovec/' \
615 -e 's/iov_base/Base/' \
616 -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
617 >> ${OUT}
619 # The msghdr struct.
620 msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
621 msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
622 echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
623 echo $msghdr | \
624 sed -e 's/_msghdr/Msghdr/' \
625 -e 's/msg_name/Name/' \
626 -e 's/msg_namelen/Namelen/' \
627 -e 's/msg_iov/Iov/' \
628 -e 's/msg_iovlen/Iovlen/' \
629 -e 's/_iovec/Iovec/' \
630 -e 's/msg_control/Control/' \
631 -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
632 -e 's/msg_flags/Flags/' \
633 >> ${OUT}
635 # The MSG_ flags for Msghdr.
636 grep '^const _MSG_' gen-sysinfo.go | \
637 sed -e 's/^\(const \)_\(MSG_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
639 # The cmsghdr struct.
640 cmsghdr=`grep '^type _cmsghdr ' gen-sysinfo.go`
641 if test -n "$cmsghdr"; then
642 cmsghdr_len=`echo $cmsghdr | sed -n -e 's/^.*cmsg_len \([^ ]*\);.*$/\1/p'`
643 echo "type Cmsghdr_len_t $cmsghdr_len" >> ${OUT}
644 echo "$cmsghdr" | \
645 sed -e 's/_cmsghdr/Cmsghdr/' \
646 -e 's/cmsg_len *[a-zA-Z0-9_]*/Len Cmsghdr_len_t/' \
647 -e 's/cmsg_level/Level/' \
648 -e 's/cmsg_type/Type/' \
649 -e 's/\[\]/[0]/' \
650 >> ${OUT}
653 # The SCM_ flags for Cmsghdr.
654 grep '^const _SCM_' gen-sysinfo.go | \
655 sed -e 's/^\(const \)_\(SCM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
657 # The ucred struct.
658 grep '^type _ucred ' gen-sysinfo.go | \
659 sed -e 's/_ucred/Ucred/' \
660 -e 's/pid/Pid/' \
661 -e 's/uid/Uid/' \
662 -e 's/gid/Gid/' \
663 >> ${OUT}
665 # The ip_mreq struct.
666 grep '^type _ip_mreq ' gen-sysinfo.go | \
667 sed -e 's/_ip_mreq/IPMreq/' \
668 -e 's/imr_multiaddr/Multiaddr/' \
669 -e 's/imr_interface/Interface/' \
670 -e 's/_in_addr/[4]byte/g' \
671 >> ${OUT}
673 # We need IPMreq to compile the net package.
674 if ! grep 'type IPMreq ' ${OUT} >/dev/null 2>&1; then
675 echo 'type IPMreq struct { Multiaddr [4]byte; Interface [4]byte; }' >> ${OUT}
678 # The ipv6_mreq struct.
679 grep '^type _ipv6_mreq ' gen-sysinfo.go | \
680 sed -e 's/_ipv6_mreq/IPv6Mreq/' \
681 -e 's/ipv6mr_multiaddr/Multiaddr/' \
682 -e 's/ipv6mr_interface/Interface/' \
683 -e 's/_in6_addr/[16]byte/' \
684 >> ${OUT}
686 # We need IPv6Mreq to compile the net package.
687 if ! grep 'type IPv6Mreq ' ${OUT} >/dev/null 2>&1; then
688 echo 'type IPv6Mreq struct { Multiaddr [16]byte; Interface uint32; }' >> ${OUT}
691 # The ip_mreqn struct.
692 grep '^type _ip_mreqn ' gen-sysinfo.go | \
693 sed -e 's/_ip_mreqn/IPMreqn/' \
694 -e 's/imr_multiaddr/Multiaddr/' \
695 -e 's/imr_address/Address/' \
696 -e 's/imr_ifindex/Ifindex/' \
697 -e 's/_in_addr/[4]byte/g' \
698 >> ${OUT}
700 # We need IPMreq to compile the net package.
701 if ! grep 'type IPMreqn ' ${OUT} >/dev/null 2>&1; then
702 echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT}
705 # Try to guess the type to use for fd_set.
706 fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
707 fds_bits_type="_C_long"
708 if test "$fd_set" != ""; then
709 fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
711 echo "type fds_bits_type $fds_bits_type" >> ${OUT}
713 # The addrinfo struct.
714 grep '^type _addrinfo ' gen-sysinfo.go | \
715 sed -e 's/_addrinfo/Addrinfo/g' \
716 -e 's/ ai_/ Ai_/g' \
717 >> ${OUT}
719 # The addrinfo flags and errors.
720 grep '^const _AI_' gen-sysinfo.go | \
721 sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
722 grep '^const _EAI_' gen-sysinfo.go | \
723 sed -e 's/^\(const \)_\(EAI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
725 # The passwd struct.
726 grep '^type _passwd ' gen-sysinfo.go | \
727 sed -e 's/_passwd/Passwd/' \
728 -e 's/ pw_/ Pw_/g' \
729 >> ${OUT}
731 # The ioctl flags for the controlling TTY.
732 grep '^const _TIOC' gen-sysinfo.go | \
733 grep -v '_val =' | \
734 sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
735 # We need TIOCGWINSZ.
736 if ! grep '^const TIOCGWINSZ' ${OUT} >/dev/null 2>&1; then
737 if grep '^const _TIOCGWINSZ_val' ${OUT} >/dev/null 2>&1; then
738 echo 'const TIOCGWINSZ = _TIOCGWINSZ_val' >> ${OUT}
741 if ! grep '^const TIOCNOTTY' ${OUT} >/dev/null 2>&1; then
742 if grep '^const _TIOCNOTTY_val' ${OUT} >/dev/null 2>&1; then
743 echo 'const TIOCNOTTY = _TIOCNOTTY_val' >> ${OUT}
746 if ! grep '^const TIOCSCTTY' ${OUT} >/dev/null 2>&1; then
747 if grep '^const _TIOCSCTTY_val' ${OUT} >/dev/null 2>&1; then
748 echo 'const TIOCSCTTY = _TIOCSCTTY_val' >> ${OUT}
752 # The ioctl flags for terminal control
753 grep '^const _TC[GS]ET' gen-sysinfo.go | \
754 sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
756 # ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but
757 # needs handling in syscalls.exec.go.
758 if ! grep '^const _TIOCSCTTY ' gen-sysinfo.go >/dev/null 2>&1; then
759 if grep '^const _TIOCNXCL ' gen-sysinfo.go >/dev/null 2>&1; then
760 echo "const TIOCSCTTY = TIOCNXCL" >> ${OUT}
764 # The nlmsghdr struct.
765 grep '^type _nlmsghdr ' gen-sysinfo.go | \
766 sed -e 's/_nlmsghdr/NlMsghdr/' \
767 -e 's/nlmsg_len/Len/' \
768 -e 's/nlmsg_type/Type/' \
769 -e 's/nlmsg_flags/Flags/' \
770 -e 's/nlmsg_seq/Seq/' \
771 -e 's/nlmsg_pid/Pid/' \
772 >> ${OUT}
774 # The nlmsg flags and operators.
775 grep '^const _NLM' gen-sysinfo.go | \
776 sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
778 # NLMSG_HDRLEN is defined as an expression using sizeof.
779 if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev/null 2>&1; then
780 if grep '^const _sizeof_nlmsghdr ' ${OUT} > /dev/null 2>&1; then
781 echo 'const NLMSG_HDRLEN = (_sizeof_nlmsghdr + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1)' >> ${OUT}
785 # The rtmsg struct.
786 grep '^type _rtmsg ' gen-sysinfo.go | \
787 sed -e 's/_rtmsg/RtMsg/' \
788 -e 's/rtm_family/Family/' \
789 -e 's/rtm_dst_len/Dst_len/' \
790 -e 's/rtm_src_len/Src_len/' \
791 -e 's/rtm_tos/Tos/' \
792 -e 's/rtm_table/Table/' \
793 -e 's/rtm_protocol/Protocol/' \
794 -e 's/rtm_scope/Scope/' \
795 -e 's/rtm_type/Type/' \
796 -e 's/rtm_flags/Flags/' \
797 >> ${OUT}
799 # The rtgenmsg struct.
800 grep '^type _rtgenmsg ' gen-sysinfo.go | \
801 sed -e 's/_rtgenmsg/RtGenmsg/' \
802 -e 's/rtgen_family/Family/' \
803 >> ${OUT}
805 # The routing message flags.
806 grep '^const _RT_' gen-sysinfo.go | \
807 sed -e 's/^\(const \)_\(RT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
808 grep '^const _RTA' gen-sysinfo.go | \
809 sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
810 grep '^const _RTF' gen-sysinfo.go | \
811 sed -e 's/^\(const \)_\(RTF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
812 grep '^const _RTCF' gen-sysinfo.go | \
813 sed -e 's/^\(const \)_\(RTCF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
814 grep '^const _RTM' gen-sysinfo.go | \
815 sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
816 grep '^const _RTN' gen-sysinfo.go | \
817 sed -e 's/^\(const \)_\(RTN[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
818 grep '^const _RTPROT' gen-sysinfo.go | \
819 sed -e 's/^\(const \)_\(RTPROT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
821 # The ifinfomsg struct.
822 grep '^type _ifinfomsg ' gen-sysinfo.go | \
823 sed -e 's/_ifinfomsg/IfInfomsg/' \
824 -e 's/ifi_family/Family/' \
825 -e 's/ifi_type/Type/' \
826 -e 's/ifi_index/Index/' \
827 -e 's/ifi_flags/Flags/' \
828 -e 's/ifi_change/Change/' \
829 >> ${OUT}
831 # The interface information types and flags.
832 grep '^const _IFA' gen-sysinfo.go | \
833 sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
834 grep '^const _IFLA' gen-sysinfo.go | \
835 sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
836 grep '^const _IFF' gen-sysinfo.go | \
837 sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
838 grep '^const _IFNAMSIZ' gen-sysinfo.go | \
839 sed -e 's/^\(const \)_\(IFNAMSIZ[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
840 grep '^const _SIOC' gen-sysinfo.go |
841 sed -e 's/^\(const \)_\(SIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
843 # The ifaddrmsg struct.
844 grep '^type _ifaddrmsg ' gen-sysinfo.go | \
845 sed -e 's/_ifaddrmsg/IfAddrmsg/' \
846 -e 's/ifa_family/Family/' \
847 -e 's/ifa_prefixlen/Prefixlen/' \
848 -e 's/ifa_flags/Flags/' \
849 -e 's/ifa_scope/Scope/' \
850 -e 's/ifa_index/Index/' \
851 >> ${OUT}
853 # The rtattr struct.
854 grep '^type _rtattr ' gen-sysinfo.go | \
855 sed -e 's/_rtattr/RtAttr/' \
856 -e 's/rta_len/Len/' \
857 -e 's/rta_type/Type/' \
858 >> ${OUT}
860 # The in_pktinfo struct.
861 grep '^type _in_pktinfo ' gen-sysinfo.go | \
862 sed -e 's/_in_pktinfo/Inet4Pktinfo/' \
863 -e 's/ipi_ifindex/Ifindex/' \
864 -e 's/ipi_spec_dst/Spec_dst/' \
865 -e 's/ipi_addr/Addr/' \
866 -e 's/_in_addr/[4]byte/g' \
867 >> ${OUT}
869 # The in6_pktinfo struct.
870 grep '^type _in6_pktinfo ' gen-sysinfo.go | \
871 sed -e 's/_in6_pktinfo/Inet6Pktinfo/' \
872 -e 's/ipi6_addr/Addr/' \
873 -e 's/ipi6_ifindex/Ifindex/' \
874 -e 's/_in6_addr/[16]byte/' \
875 >> ${OUT}
877 # The termios struct.
878 grep '^type _termios ' gen-sysinfo.go | \
879 sed -e 's/_termios/Termios/' \
880 -e 's/c_iflag/Iflag/' \
881 -e 's/c_oflag/Oflag/' \
882 -e 's/c_cflag/Cflag/' \
883 -e 's/c_lflag/Lflag/' \
884 -e 's/c_line/Line/' \
885 -e 's/c_cc/Cc/' \
886 -e 's/c_ispeed/Ispeed/' \
887 -e 's/c_ospeed/Ospeed/' \
888 >> ${OUT}
890 # The termios constants.
891 for n in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \
892 IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \
893 OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 CS5 CS6 CS7 CS8 TABDLY \
894 BSDLY VTDLY FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL \
895 CLOCAL LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE ECHO ECHOE ECHOK \
896 ECHONL ECHOCTL ECHOPRT ECHOKE DEFECHO FLUSHO NOFLSH TOSTOP PENDIN IEXTEN \
897 VINTR VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 VSWTCH VSTART VSTOP \
898 VSUSP VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS TCSANOW TCSADRAIN \
899 TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON TCIOFF TCION B0 B50 \
900 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 \
901 B38400 B57600 B115200 B230400 B460800 B500000 B576000 B921600 B1000000 \
902 B1152000 B1500000 B2000000 B2500000 B3000000 B3500000 B4000000; do
904 grep "^const _$n " gen-sysinfo.go | \
905 sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
906 done
908 # The mount flags
909 grep '^const _MNT_' gen-sysinfo.go |
910 sed -e 's/^\(const \)_\(MNT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
911 grep '^const _MS_' gen-sysinfo.go |
912 sed -e 's/^\(const \)_\(MS_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
914 # The fallocate flags.
915 grep '^const _FALLOC_' gen-sysinfo.go |
916 sed -e 's/^\(const \)_\(FALLOC_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
918 # The statfs struct.
919 # Prefer largefile variant if available.
920 statfs=`grep '^type _statfs64 ' gen-sysinfo.go || true`
921 if test "$statfs" != ""; then
922 grep '^type _statfs64 ' gen-sysinfo.go
923 else
924 grep '^type _statfs ' gen-sysinfo.go
925 fi | sed -e 's/type _statfs64/type Statfs_t/' \
926 -e 's/type _statfs/type Statfs_t/' \
927 -e 's/f_type/Type/' \
928 -e 's/f_bsize/Bsize/' \
929 -e 's/f_blocks/Blocks/' \
930 -e 's/f_bfree/Bfree/' \
931 -e 's/f_bavail/Bavail/' \
932 -e 's/f_files/Files/' \
933 -e 's/f_ffree/Ffree/' \
934 -e 's/f_fsid/Fsid/' \
935 -e 's/f_namelen/Namelen/' \
936 -e 's/f_frsize/Frsize/' \
937 -e 's/f_flags/Flags/' \
938 -e 's/f_spare/Spare/' \
939 >> ${OUT}
941 # The timex struct.
942 timex=`grep '^type _timex ' gen-sysinfo.go || true`
943 if test "$timex" = ""; then
944 timex=`grep '^// type _timex ' gen-sysinfo.go || true`
945 if test "$timex" != ""; then
946 timex=`echo $timex | sed -e 's|// ||' -e 's/INVALID-bit-field/int32/g'`
949 if test "$timex" != ""; then
950 echo "$timex" | \
951 sed -e 's/_timex/Timex/' \
952 -e 's/modes/Modes/' \
953 -e 's/offset/Offset/' \
954 -e 's/freq/Freq/' \
955 -e 's/maxerror/Maxerror/' \
956 -e 's/esterror/Esterror/' \
957 -e 's/status/Status/' \
958 -e 's/constant/Constant/' \
959 -e 's/precision/Precision/' \
960 -e 's/tolerance/Tolerance/' \
961 -e 's/ time / Time /' \
962 -e 's/tick/Tick/' \
963 -e 's/ppsfreq/Ppsfreq/' \
964 -e 's/jitter/Jitter/' \
965 -e 's/shift/Shift/' \
966 -e 's/stabil/Stabil/' \
967 -e 's/jitcnt/Jitcnt/' \
968 -e 's/calcnt/Calcnt/' \
969 -e 's/errcnt/Errcnt/' \
970 -e 's/stbcnt/Stbcnt/' \
971 -e 's/tai/Tai/' \
972 -e 's/_timeval/Timeval/' \
973 >> ${OUT}
976 # The rlimit struct.
977 grep '^type _rlimit ' gen-sysinfo.go | \
978 sed -e 's/_rlimit/Rlimit/' \
979 -e 's/rlim_cur/Cur/' \
980 -e 's/rlim_max/Max/' \
981 >> ${OUT}
983 # The RLIMIT constants.
984 grep '^const _RLIMIT_' gen-sysinfo.go |
985 sed -e 's/^\(const \)_\(RLIMIT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
986 grep '^const _RLIM_' gen-sysinfo.go |
987 sed -e 's/^\(const \)_\(RLIM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
989 # The sysinfo struct.
990 grep '^type _sysinfo ' gen-sysinfo.go | \
991 sed -e 's/_sysinfo/Sysinfo_t/' \
992 -e 's/uptime/Uptime/' \
993 -e 's/loads/Loads/' \
994 -e 's/totalram/Totalram/' \
995 -e 's/freeram/Freeram/' \
996 -e 's/sharedram/Sharedram/' \
997 -e 's/bufferram/Bufferram/' \
998 -e 's/totalswap/Totalswap/' \
999 -e 's/freeswap/Freeswap/' \
1000 -e 's/procs/Procs/' \
1001 -e 's/totalhigh/Totalhigh/' \
1002 -e 's/freehigh/Freehigh/' \
1003 -e 's/mem_unit/Unit/' \
1004 >> ${OUT}
1006 # The ustat struct.
1007 grep '^type _ustat ' gen-sysinfo.go | \
1008 sed -e 's/_ustat/Ustat_t/' \
1009 -e 's/f_tfree/Tfree/' \
1010 -e 's/f_tinode/Tinoe/' \
1011 -e 's/f_fname/Fname/' \
1012 -e 's/f_fpack/Fpack/' \
1013 >> ${OUT}
1014 # Force it to be defined, as on some older GNU/Linux systems the
1015 # header file fails when using with <linux/filter.h>.
1016 if ! grep 'type _ustat ' gen-sysinfo.go >/dev/null 2>&1; then
1017 echo 'type Ustat_t struct { Tfree int32; Tinoe uint64; Fname [5+1]int8; Fpack [5+1]int8; }' >> ${OUT}
1020 # The utimbuf struct.
1021 grep '^type _utimbuf ' gen-sysinfo.go | \
1022 sed -e 's/_utimbuf/Utimbuf/' \
1023 -e 's/actime/Actime/' \
1024 -e 's/modtime/Modtime/' \
1025 >> ${OUT}
1027 # The LOCK flags for flock.
1028 grep '^const _LOCK_' gen-sysinfo.go |
1029 sed -e 's/^\(const \)_\(LOCK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1031 # The GNU/Linux LINUX_REBOOT flags.
1032 grep '^const _LINUX_REBOOT_' gen-sysinfo.go |
1033 sed -e 's/^\(const \)_\(LINUX_REBOOT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1035 # The GNU/Linux sock_filter struct.
1036 grep '^type _sock_filter ' gen-sysinfo.go | \
1037 sed -e 's/_sock_filter/SockFilter/' \
1038 -e 's/code/Code/' \
1039 -e 's/jt/Jt/' \
1040 -e 's/jf/Jf/' \
1041 -e 's/k /K /' \
1042 >> ${OUT}
1044 # The GNU/Linux sock_fprog struct.
1045 grep '^type _sock_fprog ' gen-sysinfo.go | \
1046 sed -e 's/_sock_fprog/SockFprog/' \
1047 -e 's/len/Len/' \
1048 -e 's/filter/Filter/' \
1049 -e 's/_sock_filter/SockFilter/' \
1050 >> ${OUT}
1052 # The GNU/Linux filter flags.
1053 grep '^const _BPF_' gen-sysinfo.go | \
1054 sed -e 's/^\(const \)_\(BPF_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1056 # The GNU/Linux nlattr struct.
1057 grep '^type _nlattr ' gen-sysinfo.go | \
1058 sed -e 's/_nlattr/NlAttr/' \
1059 -e 's/nla_len/Len/' \
1060 -e 's/nla_type/Type/' \
1061 >> ${OUT}
1063 # The GNU/Linux nlmsgerr struct.
1064 grep '^type _nlmsgerr ' gen-sysinfo.go | \
1065 sed -e 's/_nlmsgerr/NlMsgerr/' \
1066 -e 's/error/Error/' \
1067 -e 's/msg/Msg/' \
1068 -e 's/_nlmsghdr/NlMsghdr/' \
1069 >> ${OUT}
1071 # The GNU/Linux rtnexthop struct.
1072 grep '^type _rtnexthop ' gen-sysinfo.go | \
1073 sed -e 's/_rtnexthop/RtNexthop/' \
1074 -e 's/rtnh_len/Len/' \
1075 -e 's/rtnh_flags/Flags/' \
1076 -e 's/rtnh_hops/Hops/' \
1077 -e 's/rtnh_ifindex/Ifindex/' \
1078 >> ${OUT}
1080 # The GNU/Linux netlink flags.
1081 grep '^const _NETLINK_' gen-sysinfo.go | \
1082 sed -e 's/^\(const \)_\(NETLINK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1083 grep '^const _NLA_' gen-sysinfo.go | \
1084 sed -e 's/^\(const \)_\(NLA_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1086 # The GNU/Linux packet socket flags.
1087 grep '^const _PACKET_' gen-sysinfo.go | \
1088 sed -e 's/^\(const \)_\(PACKET_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1090 # The GNU/Linux inotify_event struct.
1091 grep '^type _inotify_event ' gen-sysinfo.go | \
1092 sed -e 's/_inotify_event/InotifyEvent/' \
1093 -e 's/wd/Wd/' \
1094 -e 's/mask/Mask/' \
1095 -e 's/cookie/Cookie/' \
1096 -e 's/len/Len/' \
1097 -e 's/name/Name/' \
1098 -e 's/\[\]/[0]/' \
1099 -e 's/\[0\]byte/[0]int8/' \
1100 >> ${OUT}
1102 # The Solaris 11 Update 1 _zone_net_addr_t struct.
1103 grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
1104 sed -e 's/_in6_addr/[16]byte/' \
1105 >> ${OUT}
1107 # Struct sizes.
1108 set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \
1109 ifaddrmsg IfAddrmsg ifinfomsg IfInfomsg in_pktinfo Inet4Pktinfo \
1110 in6_pktinfo Inet6Pktinfo inotify_event InotifyEvent linger Linger \
1111 msghdr Msghdr nlattr NlAttr nlmsgerr NlMsgerr nlmsghdr NlMsghdr \
1112 rtattr RtAttr rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \
1113 sock_filter SockFilter sock_fprog SockFprog ucred Ucred
1114 while test $# != 0; do
1115 nc=$1
1116 ngo=$2
1117 shift
1118 shift
1119 if grep "^const _sizeof_$nc =" gen-sysinfo.go >/dev/null 2>&1; then
1120 echo "const Sizeof$ngo = _sizeof_$nc" >> ${OUT}
1122 done
1124 # In order to compile the net package, we need some sizes to exist
1125 # even if the types do not.
1126 if ! grep 'const SizeofIPMreq ' ${OUT} >/dev/null 2>&1; then
1127 echo 'const SizeofIPMreq = 8' >> ${OUT}
1129 if ! grep 'const SizeofIPv6Mreq ' ${OUT} >/dev/null 2>&1; then
1130 echo 'const SizeofIPv6Mreq = 20' >> ${OUT}
1132 if ! grep 'const SizeofIPMreqn ' ${OUT} >/dev/null 2>&1; then
1133 echo 'const SizeofIPMreqn = 12' >> ${OUT}
1136 exit $?