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.
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.
28 #include <sys/types.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
36 <sys/termios.h> only defines TIOCNOTTY if !_XOPEN_SOURCE, while
37 <sys/ttold.h> does so unconditionally. */
39 #include <sys/bsd_types.h>
40 #include <sys/ttold.h>
42 #include <netinet/tcp.h>
43 #if defined(HAVE_NETINET_IN_SYSTM_H)
44 #include <netinet/in_systm.h>
46 #if defined(HAVE_NETINET_IP_H)
47 #include <netinet/ip.h>
49 #if defined(HAVE_NETINET_IP_MROUTE_H)
50 #include <netinet/ip_mroute.h>
52 #if defined(HAVE_NETINET_IF_ETHER_H)
53 #include <netinet/if_ether.h>
56 #include <sys/ioctl.h>
58 #if defined(HAVE_SYSCALL_H)
61 #if defined(HAVE_SYS_SYSCALL_H)
62 #include <sys/syscall.h>
64 #if defined(HAVE_SYS_EPOLL_H)
65 #include <sys/epoll.h>
67 #if defined(HAVE_SYS_FILE_H)
70 #if defined(HAVE_SYS_MMAN_H)
73 #if defined(HAVE_SYS_PRCTL_H)
74 #include <sys/prctl.h>
76 #if defined(HAVE_SYS_PTRACE_H)
77 #include <sys/ptrace.h>
79 #include <sys/resource.h>
81 #include <sys/socket.h>
84 #include <sys/times.h>
87 #if defined(HAVE_SYS_USER_H)
90 #if defined(HAVE_SYS_UTSNAME_H)
91 #include <sys/utsname.h>
93 #if defined(HAVE_SYS_SELECT_H)
94 #include <sys/select.h>
100 #if defined(HAVE_LINUX_FILTER_H)
101 #include <linux/filter.h>
103 #if defined(HAVE_LINUX_IF_ADDR_H)
104 #include <linux/if_addr.h>
106 #if defined(HAVE_LINUX_IF_ETHER_H)
107 #include <linux/if_ether.h>
109 #if defined(HAVE_LINUX_IF_TUN_H)
110 #include <linux/if_tun.h>
112 #if defined(HAVE_LINUX_NETLINK_H)
113 #include <linux/netlink.h>
115 #if defined(HAVE_LINUX_RTNETLINK_H)
116 #include <linux/rtnetlink.h>
118 #if defined(HAVE_NET_IF_H)
121 #if defined(HAVE_NET_IF_ARP_H)
122 #include <net/if_arp.h>
124 #if defined(HAVE_NET_ROUTE_H)
125 #include <net/route.h>
127 #if defined (HAVE_NETPACKET_PACKET_H)
128 #include <netpacket/packet.h>
130 #if defined(HAVE_SYS_MOUNT_H)
131 #include <sys/mount.h>
133 #if defined(HAVE_SYS_VFS_H)
136 #if defined(HAVE_STATFS_H)
137 #include <sys/statfs.h>
139 #if defined(HAVE_SYS_TIMEX_H)
140 #include <sys/timex.h>
142 #if defined(HAVE_SYS_SYSINFO_H)
143 #include <sys/sysinfo.h>
145 #if defined(HAVE_USTAT_H)
148 #if defined(HAVE_UTIME_H)
151 #if defined(HAVE_LINUX_ETHER_H)
152 #include <linux/ether.h>
154 #if defined(HAVE_LINUX_FS_H)
155 #include <linux/fs.h>
157 #if defined(HAVE_LINUX_REBOOT_H)
158 #include <linux/reboot.h>
160 #if defined(HAVE_SYS_INOTIFY_H)
161 #include <sys/inotify.h>
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. */
169 TIOCGWINSZ_val = TIOCGWINSZ,
172 TIOCNOTTY_val = TIOCNOTTY,
175 TIOCSCTTY_val = TIOCSCTTY,
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 | \
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' \
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}
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}
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/' | \
249 sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
250 echo "const $sup = _$sys" >> ${OUT}
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}
262 grep '^const _S_' gen-sysinfo.go | \
263 sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
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}
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/' \
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}
307 # pathconf constants.
308 grep '^const __PC' gen-sysinfo.go |
309 sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
311 # The PATH_MAX constant.
312 if grep '^const _PATH_MAX ' gen-sysinfo.go >/dev/null 2>&1; then
313 echo 'const PathMax = _PATH_MAX' >> ${OUT}
317 grep '^const _EPOLL' gen-sysinfo.go |
318 sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
319 # Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
320 if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
321 echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
323 if ! grep '^const EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
324 echo "const EPOLL_CLOEXEC = 02000000" >> ${OUT}
328 grep '^const _PR_' gen-sysinfo.go |
329 sed -e 's/^\(const \)_\(PR_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
332 grep '^const _PTRACE' gen-sysinfo.go |
333 sed -e 's/^\(const \)_\(PTRACE[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
334 # We need some ptrace options that are not defined in older versions
336 if ! grep '^const PTRACE_SETOPTIONS' ${OUT} > /dev/null 2>&1; then
337 echo "const PTRACE_SETOPTIONS = 0x4200" >> ${OUT}
339 if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then
340 echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
342 if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then
343 echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
345 if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then
346 echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
348 if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then
349 echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
351 if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then
352 echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
354 if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then
355 echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
357 if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then
358 echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
360 if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then
361 echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
363 if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
364 echo "const PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
366 if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
367 echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
369 if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then
370 echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
372 if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then
373 echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
375 if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then
376 echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
378 if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then
379 echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
381 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
382 echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
384 if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
385 echo "const _PTRACE_TRACEME = 0" >> ${OUT}
388 # The registers returned by PTRACE_GETREGS. This is probably
389 # GNU/Linux specific; it should do no harm if there is no
391 regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
392 if test "$regs" != ""; then
393 regs=`echo $regs | sed -e 's/type _user_regs_struct struct //' -e 's/[{}]//g'`
394 regs=`echo $regs | sed -e s'/^ *//'`
396 while test -n "$regs"; do
397 field=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
398 regs=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
399 # Capitalize the first character of the field.
400 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
401 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
402 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
404 nregs="$nregs $field;"
406 echo "type PtraceRegs struct {$nregs }" >> ${OUT}
410 echo 'type Size_t _size_t' >> ${OUT}
411 echo "type Ssize_t _ssize_t" >> ${OUT}
412 if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then
413 echo "type Offset_t _off64_t" >> ${OUT}
415 echo "type Offset_t _off_t" >> ${OUT}
417 echo "type Mode_t _mode_t" >> ${OUT}
418 echo "type Pid_t _pid_t" >> ${OUT}
419 echo "type Uid_t _uid_t" >> ${OUT}
420 echo "type Gid_t _gid_t" >> ${OUT}
421 echo "type Socklen_t _socklen_t" >> ${OUT}
423 # The long type, needed because that is the type that ptrace returns.
424 sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
425 if test "$sizeof_long" = "4"; then
426 echo "type _C_long int32" >> ${OUT}
427 elif test "$sizeof_long" = "8"; then
428 echo "type _C_long int64" >> ${OUT}
430 echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
434 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
435 # double is commented by -fdump-go-spec.
436 if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
437 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
439 if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
440 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
444 if grep '^type _time_t ' gen-sysinfo.go > /dev/null 2>&1; then
445 echo 'type Time_t _time_t' >> ${OUT}
448 # The time structures need special handling: we need to name the
449 # types, so that we can cast integers to the right types when
450 # assigning to the structures.
451 timeval=`grep '^type _timeval ' gen-sysinfo.go`
452 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
453 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
454 echo "type Timeval_sec_t $timeval_sec" >> ${OUT}
455 echo "type Timeval_usec_t $timeval_usec" >> ${OUT}
457 sed -e 's/type _timeval /type Timeval /' \
458 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
459 -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
460 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
461 if test "$timespec" = ""; then
462 # IRIX 6.5 has __timespec instead.
463 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
465 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
466 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
467 echo "type Timespec_sec_t $timespec_sec" >> ${OUT}
468 echo "type Timespec_nsec_t $timespec_nsec" >> ${OUT}
470 sed -e 's/^type ___timespec /type Timespec /' \
471 -e 's/^type _timespec /type Timespec /' \
472 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
473 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
475 timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
476 if test "$timestruc" != ""; then
477 timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
478 timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
479 echo "type Timestruc_sec_t $timestruc_sec" >> ${OUT}
480 echo "type Timestruc_nsec_t $timestruc_nsec" >> ${OUT}
482 sed -e 's/^type _timestruc_t /type Timestruc /' \
483 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
484 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
488 grep '^type _tms ' gen-sysinfo.go | \
489 sed -e 's/type _tms/type Tms/' \
490 -e 's/tms_utime/Utime/' \
491 -e 's/tms_stime/Stime/' \
492 -e 's/tms_cutime/Cutime/' \
493 -e 's/tms_cstime/Cstime/' \
497 # Prefer largefile variant if available.
498 stat=`grep '^type _stat64 ' gen-sysinfo.go || true`
499 if test "$stat" != ""; then
500 grep '^type _stat64 ' gen-sysinfo.go
502 grep '^type _stat ' gen-sysinfo.go
503 fi | sed -e 's/type _stat64/type Stat_t/' \
504 -e 's/type _stat/type Stat_t/' \
506 -e 's/st_ino/Ino/g' \
507 -e 's/st_nlink/Nlink/' \
508 -e 's/st_mode/Mode/' \
511 -e 's/st_rdev/Rdev/' \
512 -e 's/st_size/Size/' \
513 -e 's/st_blksize/Blksize/' \
514 -e 's/st_blocks/Blocks/' \
515 -e 's/st_atim/Atim/' \
516 -e 's/st_mtim/Mtim/' \
517 -e 's/st_ctim/Ctim/' \
518 -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
519 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
520 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
521 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
522 -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
525 # The directory searching types.
526 # Prefer largefile variant if available.
527 dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true`
528 if test "$dirent" != ""; then
529 grep '^type _dirent64 ' gen-sysinfo.go
531 grep '^type _dirent ' gen-sysinfo.go
532 fi | sed -e 's/type _dirent64/type Dirent/' \
533 -e 's/type _dirent/type Dirent/' \
534 -e 's/d_name \[0+1\]/d_name [0+256]/' \
535 -e 's/d_name/Name/' \
536 -e 's/]int8/]byte/' \
539 -e 's/d_reclen/Reclen/' \
540 -e 's/d_type/Type/' \
542 echo "type DIR _DIR" >> ${OUT}
544 # Values for d_type field in dirent.
545 grep '^const _DT_' gen-sysinfo.go |
546 sed -e 's/^\(const \)_\(DT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
549 rusage=`grep '^type _rusage struct' gen-sysinfo.go`
550 if test "$rusage" != ""; then
551 # Remove anonymous unions from GNU/Linux <bits/resource.h>.
552 rusage=`echo $rusage | sed -e 's/Godump_[0-9]* struct {\([^}]*\)};/\1/g'`
553 rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
554 rusage=`echo $rusage | sed -e 's/^ *//'`
556 while test -n "$rusage"; do
557 field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
558 rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
559 # Drop the leading ru_, capitalize the next character.
560 field=`echo $field | sed -e 's/^ru_//'`
561 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
562 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
563 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
564 # Fix _timeval _timespec, and _timestruc_t.
565 r=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
566 r=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
567 r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
569 nrusage="$nrusage $field;"
571 echo "type Rusage struct {$nrusage }" >> ${OUT}
573 echo "type Rusage struct {}" >> ${OUT}
576 # The RUSAGE constants.
577 grep '^const _RUSAGE_' gen-sysinfo.go | \
578 sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
580 # The utsname struct.
581 grep '^type _utsname ' gen-sysinfo.go | \
582 sed -e 's/_utsname/Utsname/' \
583 -e 's/sysname/Sysname/' \
584 -e 's/nodename/Nodename/' \
585 -e 's/release/Release/' \
586 -e 's/version/Version/' \
587 -e 's/machine/Machine/' \
588 -e 's/domainname/Domainname/' \
592 iovec=`grep '^type _iovec ' gen-sysinfo.go`
593 iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
594 echo "type Iovec_len_t $iovec_len" >> ${OUT}
596 sed -e 's/_iovec/Iovec/' \
597 -e 's/iov_base/Base/' \
598 -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
602 msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
603 msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
604 echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
606 sed -e 's/_msghdr/Msghdr/' \
607 -e 's/msg_name/Name/' \
608 -e 's/msg_namelen/Namelen/' \
609 -e 's/msg_iov/Iov/' \
610 -e 's/msg_iovlen/Iovlen/' \
611 -e 's/_iovec/Iovec/' \
612 -e 's/msg_control/Control/' \
613 -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
614 -e 's/msg_flags/Flags/' \
617 # The MSG_ flags for Msghdr.
618 grep '^const _MSG_' gen-sysinfo.go | \
619 sed -e 's/^\(const \)_\(MSG_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
621 # The cmsghdr struct.
622 cmsghdr=`grep '^type _cmsghdr ' gen-sysinfo.go`
623 if test -n "$cmsghdr"; then
624 cmsghdr_len=`echo $cmsghdr | sed -n -e 's/^.*cmsg_len \([^ ]*\);.*$/\1/p'`
625 echo "type Cmsghdr_len_t $cmsghdr_len" >> ${OUT}
627 sed -e 's/_cmsghdr/Cmsghdr/' \
628 -e 's/cmsg_len *[a-zA-Z0-9_]*/Len Cmsghdr_len_t/' \
629 -e 's/cmsg_level/Level/' \
630 -e 's/cmsg_type/Type/' \
635 # The SCM_ flags for Cmsghdr.
636 grep '^const _SCM_' gen-sysinfo.go | \
637 sed -e 's/^\(const \)_\(SCM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
640 grep '^type _ucred ' gen-sysinfo.go | \
641 sed -e 's/_ucred/Ucred/' \
647 # The ip_mreq struct.
648 grep '^type _ip_mreq ' gen-sysinfo.go | \
649 sed -e 's/_ip_mreq/IPMreq/' \
650 -e 's/imr_multiaddr/Multiaddr/' \
651 -e 's/imr_interface/Interface/' \
652 -e 's/_in_addr/[4]byte/g' \
655 # We need IPMreq to compile the net package.
656 if ! grep 'type IPMreq ' ${OUT} >/dev/null 2>&1; then
657 echo 'type IPMreq struct { Multiaddr [4]byte; Interface [4]byte; }' >> ${OUT}
660 # The ipv6_mreq struct.
661 grep '^type _ipv6_mreq ' gen-sysinfo.go | \
662 sed -e 's/_ipv6_mreq/IPv6Mreq/' \
663 -e 's/ipv6mr_multiaddr/Multiaddr/' \
664 -e 's/ipv6mr_interface/Interface/' \
665 -e 's/_in6_addr/[16]byte/' \
668 # We need IPv6Mreq to compile the net package.
669 if ! grep 'type IPv6Mreq ' ${OUT} >/dev/null 2>&1; then
670 echo 'type IPv6Mreq struct { Multiaddr [16]byte; Interface uint32; }' >> ${OUT}
673 # The ip_mreqn struct.
674 grep '^type _ip_mreqn ' gen-sysinfo.go | \
675 sed -e 's/_ip_mreqn/IPMreqn/' \
676 -e 's/imr_multiaddr/Multiaddr/' \
677 -e 's/imr_address/Address/' \
678 -e 's/imr_ifindex/Ifindex/' \
679 -e 's/_in_addr/[4]byte/g' \
682 # We need IPMreq to compile the net package.
683 if ! grep 'type IPMreqn ' ${OUT} >/dev/null 2>&1; then
684 echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT}
687 # Try to guess the type to use for fd_set.
688 fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
689 fds_bits_type="_C_long"
690 if test "$fd_set" != ""; then
691 fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
693 echo "type fds_bits_type $fds_bits_type" >> ${OUT}
695 # The addrinfo struct.
696 grep '^type _addrinfo ' gen-sysinfo.go | \
697 sed -e 's/_addrinfo/Addrinfo/g' \
701 # The addrinfo flags and errors.
702 grep '^const _AI_' gen-sysinfo.go | \
703 sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
704 grep '^const _EAI_' gen-sysinfo.go | \
705 sed -e 's/^\(const \)_\(EAI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
708 grep '^type _passwd ' gen-sysinfo.go | \
709 sed -e 's/_passwd/Passwd/' \
713 # The ioctl flags for the controlling TTY.
714 grep '^const _TIOC' gen-sysinfo.go | \
716 sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
717 # We need TIOCGWINSZ.
718 if ! grep '^const TIOCGWINSZ' ${OUT} >/dev/null 2>&1; then
719 if grep '^const _TIOCGWINSZ_val' ${OUT} >/dev/null 2>&1; then
720 echo 'const TIOCGWINSZ = _TIOCGWINSZ_val' >> ${OUT}
723 if ! grep '^const TIOCNOTTY' ${OUT} >/dev/null 2>&1; then
724 if grep '^const _TIOCNOTTY_val' ${OUT} >/dev/null 2>&1; then
725 echo 'const TIOCNOTTY = _TIOCNOTTY_val' >> ${OUT}
728 if ! grep '^const TIOCSCTTY' ${OUT} >/dev/null 2>&1; then
729 if grep '^const _TIOCSCTTY_val' ${OUT} >/dev/null 2>&1; then
730 echo 'const TIOCSCTTY = _TIOCSCTTY_val' >> ${OUT}
734 # The ioctl flags for terminal control
735 grep '^const _TC[GS]ET' gen-sysinfo.go | \
736 sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
738 # ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but
739 # needs handling in syscalls.exec.go.
740 if ! grep '^const _TIOCSCTTY ' gen-sysinfo.go >/dev/null 2>&1; then
741 if grep '^const _TIOCNXCL ' gen-sysinfo.go >/dev/null 2>&1; then
742 echo "const TIOCSCTTY = TIOCNXCL" >> ${OUT}
746 # The nlmsghdr struct.
747 grep '^type _nlmsghdr ' gen-sysinfo.go | \
748 sed -e 's/_nlmsghdr/NlMsghdr/' \
749 -e 's/nlmsg_len/Len/' \
750 -e 's/nlmsg_type/Type/' \
751 -e 's/nlmsg_flags/Flags/' \
752 -e 's/nlmsg_seq/Seq/' \
753 -e 's/nlmsg_pid/Pid/' \
756 # The nlmsg flags and operators.
757 grep '^const _NLM' gen-sysinfo.go | \
758 sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
760 # NLMSG_HDRLEN is defined as an expression using sizeof.
761 if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev/null 2>&1; then
762 if grep '^const _sizeof_nlmsghdr ' ${OUT} > /dev/null 2>&1; then
763 echo 'const NLMSG_HDRLEN = (_sizeof_nlmsghdr + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1)' >> ${OUT}
768 grep '^type _rtmsg ' gen-sysinfo.go | \
769 sed -e 's/_rtmsg/RtMsg/' \
770 -e 's/rtm_family/Family/' \
771 -e 's/rtm_dst_len/Dst_len/' \
772 -e 's/rtm_src_len/Src_len/' \
773 -e 's/rtm_tos/Tos/' \
774 -e 's/rtm_table/Table/' \
775 -e 's/rtm_protocol/Protocol/' \
776 -e 's/rtm_scope/Scope/' \
777 -e 's/rtm_type/Type/' \
778 -e 's/rtm_flags/Flags/' \
781 # The rtgenmsg struct.
782 grep '^type _rtgenmsg ' gen-sysinfo.go | \
783 sed -e 's/_rtgenmsg/RtGenmsg/' \
784 -e 's/rtgen_family/Family/' \
787 # The routing message flags.
788 grep '^const _RT_' gen-sysinfo.go | \
789 sed -e 's/^\(const \)_\(RT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
790 grep '^const _RTA' gen-sysinfo.go | \
791 sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
792 grep '^const _RTF' gen-sysinfo.go | \
793 sed -e 's/^\(const \)_\(RTF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
794 grep '^const _RTCF' gen-sysinfo.go | \
795 sed -e 's/^\(const \)_\(RTCF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
796 grep '^const _RTM' gen-sysinfo.go | \
797 sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
798 grep '^const _RTN' gen-sysinfo.go | \
799 sed -e 's/^\(const \)_\(RTN[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
800 grep '^const _RTPROT' gen-sysinfo.go | \
801 sed -e 's/^\(const \)_\(RTPROT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
803 # The ifinfomsg struct.
804 grep '^type _ifinfomsg ' gen-sysinfo.go | \
805 sed -e 's/_ifinfomsg/IfInfomsg/' \
806 -e 's/ifi_family/Family/' \
807 -e 's/ifi_type/Type/' \
808 -e 's/ifi_index/Index/' \
809 -e 's/ifi_flags/Flags/' \
810 -e 's/ifi_change/Change/' \
813 # The interface information types and flags.
814 grep '^const _IFA' gen-sysinfo.go | \
815 sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
816 grep '^const _IFLA' gen-sysinfo.go | \
817 sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
818 grep '^const _IFF' gen-sysinfo.go | \
819 sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
820 grep '^const _IFNAMSIZ' gen-sysinfo.go | \
821 sed -e 's/^\(const \)_\(IFNAMSIZ[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
822 grep '^const _SIOC' gen-sysinfo.go |
823 sed -e 's/^\(const \)_\(SIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
825 # The ifaddrmsg struct.
826 grep '^type _ifaddrmsg ' gen-sysinfo.go | \
827 sed -e 's/_ifaddrmsg/IfAddrmsg/' \
828 -e 's/ifa_family/Family/' \
829 -e 's/ifa_prefixlen/Prefixlen/' \
830 -e 's/ifa_flags/Flags/' \
831 -e 's/ifa_scope/Scope/' \
832 -e 's/ifa_index/Index/' \
836 grep '^type _rtattr ' gen-sysinfo.go | \
837 sed -e 's/_rtattr/RtAttr/' \
838 -e 's/rta_len/Len/' \
839 -e 's/rta_type/Type/' \
842 # The in_pktinfo struct.
843 grep '^type _in_pktinfo ' gen-sysinfo.go | \
844 sed -e 's/_in_pktinfo/Inet4Pktinfo/' \
845 -e 's/ipi_ifindex/Ifindex/' \
846 -e 's/ipi_spec_dst/Spec_dst/' \
847 -e 's/ipi_addr/Addr/' \
848 -e 's/_in_addr/[4]byte/g' \
851 # The in6_pktinfo struct.
852 grep '^type _in6_pktinfo ' gen-sysinfo.go | \
853 sed -e 's/_in6_pktinfo/Inet6Pktinfo/' \
854 -e 's/ipi6_addr/Addr/' \
855 -e 's/ipi6_ifindex/Ifindex/' \
856 -e 's/_in6_addr/[16]byte/' \
859 # The termios struct.
860 grep '^type _termios ' gen-sysinfo.go | \
861 sed -e 's/_termios/Termios/' \
862 -e 's/c_iflag/Iflag/' \
863 -e 's/c_oflag/Oflag/' \
864 -e 's/c_cflag/Cflag/' \
865 -e 's/c_lflag/Lflag/' \
866 -e 's/c_line/Line/' \
868 -e 's/c_ispeed/Ispeed/' \
869 -e 's/c_ospeed/Ospeed/' \
872 # The termios constants.
873 for n in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \
874 IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \
875 OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 CS5 CS6 CS7 CS8 TABDLY \
876 BSDLY VTDLY FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL \
877 CLOCAL LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE ECHO ECHOE ECHOK \
878 ECHONL ECHOCTL ECHOPRT ECHOKE DEFECHO FLUSHO NOFLSH TOSTOP PENDIN IEXTEN \
879 VINTR VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 VSWTCH VSTART VSTOP \
880 VSUSP VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS TCSANOW TCSADRAIN \
881 TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON TCIOFF TCION B0 B50 \
882 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 \
883 B38400 B57600 B115200 B230400 B460800 B500000 B576000 B921600 B1000000 \
884 B1152000 B1500000 B2000000 B2500000 B3000000 B3500000 B4000000; do
886 grep "^const _$n " gen-sysinfo.go | \
887 sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
891 grep '^const _MNT_' gen-sysinfo.go |
892 sed -e 's/^\(const \)_\(MNT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
893 grep '^const _MS_' gen-sysinfo.go |
894 sed -e 's/^\(const \)_\(MS_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
896 # The fallocate flags.
897 grep '^const _FALLOC_' gen-sysinfo.go |
898 sed -e 's/^\(const \)_\(FALLOC_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
901 # Prefer largefile variant if available.
902 statfs=`grep '^type _statfs64 ' gen-sysinfo.go || true`
903 if test "$statfs" != ""; then
904 grep '^type _statfs64 ' gen-sysinfo.go
906 grep '^type _statfs ' gen-sysinfo.go
907 fi | sed -e 's/type _statfs64/type Statfs_t/' \
908 -e 's/type _statfs/type Statfs_t/' \
909 -e 's/f_type/Type/' \
910 -e 's/f_bsize/Bsize/' \
911 -e 's/f_blocks/Blocks/' \
912 -e 's/f_bfree/Bfree/' \
913 -e 's/f_bavail/Bavail/' \
914 -e 's/f_files/Files/' \
915 -e 's/f_ffree/Ffree/' \
916 -e 's/f_fsid/Fsid/' \
917 -e 's/f_namelen/Namelen/' \
918 -e 's/f_frsize/Frsize/' \
919 -e 's/f_flags/Flags/' \
920 -e 's/f_spare/Spare/' \
924 timex=`grep '^type _timex ' gen-sysinfo.go || true`
925 if test "$timex" = ""; then
926 timex=`grep '^// type _timex ' gen-sysinfo.go || true`
927 if test "$timex" != ""; then
928 timex=`echo $timex | sed -e 's|// ||' -e 's/INVALID-bit-field/int32/g'`
931 if test "$timex" != ""; then
933 sed -e 's/_timex/Timex/' \
934 -e 's/modes/Modes/' \
935 -e 's/offset/Offset/' \
937 -e 's/maxerror/Maxerror/' \
938 -e 's/esterror/Esterror/' \
939 -e 's/status/Status/' \
940 -e 's/constant/Constant/' \
941 -e 's/precision/Precision/' \
942 -e 's/tolerance/Tolerance/' \
943 -e 's/ time / Time /' \
945 -e 's/ppsfreq/Ppsfreq/' \
946 -e 's/jitter/Jitter/' \
947 -e 's/shift/Shift/' \
948 -e 's/stabil/Stabil/' \
949 -e 's/jitcnt/Jitcnt/' \
950 -e 's/calcnt/Calcnt/' \
951 -e 's/errcnt/Errcnt/' \
952 -e 's/stbcnt/Stbcnt/' \
954 -e 's/_timeval/Timeval/' \
959 grep '^type _rlimit ' gen-sysinfo.go | \
960 sed -e 's/_rlimit/Rlimit/' \
961 -e 's/rlim_cur/Cur/' \
962 -e 's/rlim_max/Max/' \
965 # The RLIMIT constants.
966 grep '^const _RLIMIT_' gen-sysinfo.go |
967 sed -e 's/^\(const \)_\(RLIMIT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
968 grep '^const _RLIM_' gen-sysinfo.go |
969 sed -e 's/^\(const \)_\(RLIM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
971 # The sysinfo struct.
972 grep '^type _sysinfo ' gen-sysinfo.go | \
973 sed -e 's/_sysinfo/Sysinfo_t/' \
974 -e 's/uptime/Uptime/' \
975 -e 's/loads/Loads/' \
976 -e 's/totalram/Totalram/' \
977 -e 's/freeram/Freeram/' \
978 -e 's/sharedram/Sharedram/' \
979 -e 's/bufferram/Bufferram/' \
980 -e 's/totalswap/Totalswap/' \
981 -e 's/freeswap/Freeswap/' \
982 -e 's/procs/Procs/' \
983 -e 's/totalhigh/Totalhigh/' \
984 -e 's/freehigh/Freehigh/' \
985 -e 's/mem_unit/Unit/' \
989 grep '^type _ustat ' gen-sysinfo.go | \
990 sed -e 's/_ustat/Ustat_t/' \
991 -e 's/f_tfree/Tfree/' \
992 -e 's/f_tinode/Tinoe/' \
993 -e 's/f_fname/Fname/' \
994 -e 's/f_fpack/Fpack/' \
996 # Force it to be defined, as on some older GNU/Linux systems the
997 # header file fails when using with <linux/filter.h>.
998 if ! grep 'type _ustat ' gen-sysinfo.go >/dev/null 2>&1; then
999 echo 'type Ustat_t struct { Tfree int32; Tinoe uint64; Fname [5+1]int8; Fpack [5+1]int8; }' >> ${OUT}
1002 # The utimbuf struct.
1003 grep '^type _utimbuf ' gen-sysinfo.go | \
1004 sed -e 's/_utimbuf/Utimbuf/' \
1005 -e 's/actime/Actime/' \
1006 -e 's/modtime/Modtime/' \
1009 # The LOCK flags for flock.
1010 grep '^const _LOCK_' gen-sysinfo.go |
1011 sed -e 's/^\(const \)_\(LOCK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1013 # The GNU/Linux LINUX_REBOOT flags.
1014 grep '^const _LINUX_REBOOT_' gen-sysinfo.go |
1015 sed -e 's/^\(const \)_\(LINUX_REBOOT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1017 # The GNU/Linux sock_filter struct.
1018 grep '^type _sock_filter ' gen-sysinfo.go | \
1019 sed -e 's/_sock_filter/SockFilter/' \
1026 # The GNU/Linux sock_fprog struct.
1027 grep '^type _sock_fprog ' gen-sysinfo.go | \
1028 sed -e 's/_sock_fprog/SockFprog/' \
1030 -e 's/filter/Filter/' \
1031 -e 's/_sock_filter/SockFilter/' \
1034 # The GNU/Linux filter flags.
1035 grep '^const _BPF_' gen-sysinfo.go | \
1036 sed -e 's/^\(const \)_\(BPF_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1038 # The GNU/Linux nlattr struct.
1039 grep '^type _nlattr ' gen-sysinfo.go | \
1040 sed -e 's/_nlattr/NlAttr/' \
1041 -e 's/nla_len/Len/' \
1042 -e 's/nla_type/Type/' \
1045 # The GNU/Linux nlmsgerr struct.
1046 grep '^type _nlmsgerr ' gen-sysinfo.go | \
1047 sed -e 's/_nlmsgerr/NlMsgerr/' \
1048 -e 's/error/Error/' \
1050 -e 's/_nlmsghdr/NlMsghdr/' \
1053 # The GNU/Linux rtnexthop struct.
1054 grep '^type _rtnexthop ' gen-sysinfo.go | \
1055 sed -e 's/_rtnexthop/RtNexthop/' \
1056 -e 's/rtnh_len/Len/' \
1057 -e 's/rtnh_flags/Flags/' \
1058 -e 's/rtnh_hops/Hops/' \
1059 -e 's/rtnh_ifindex/Ifindex/' \
1062 # The GNU/Linux netlink flags.
1063 grep '^const _NETLINK_' gen-sysinfo.go | \
1064 sed -e 's/^\(const \)_\(NETLINK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1065 grep '^const _NLA_' gen-sysinfo.go | \
1066 sed -e 's/^\(const \)_\(NLA_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1068 # The GNU/Linux packet socket flags.
1069 grep '^const _PACKET_' gen-sysinfo.go | \
1070 sed -e 's/^\(const \)_\(PACKET_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1072 # The GNU/Linux inotify_event struct.
1073 grep '^type _inotify_event ' gen-sysinfo.go | \
1074 sed -e 's/_inotify_event/InotifyEvent/' \
1077 -e 's/cookie/Cookie/' \
1081 -e 's/\[0\]byte/[0]int8/' \
1084 # The Solaris 11 Update 1 _zone_net_addr_t struct.
1085 grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
1086 sed -e 's/_in6_addr/[16]byte/' \
1090 set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \
1091 ifaddrmsg IfAddrmsg ifinfomsg IfInfomsg in_pktinfo Inet4Pktinfo \
1092 in6_pktinfo Inet6Pktinfo inotify_event InotifyEvent linger Linger \
1093 msghdr Msghdr nlattr NlAttr nlmsgerr NlMsgerr nlmsghdr NlMsghdr \
1094 rtattr RtAttr rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \
1095 sock_filter SockFilter sock_fprog SockFprog ucred Ucred
1096 while test $# != 0; do
1101 if grep "^const _sizeof_$nc =" gen-sysinfo.go >/dev/null 2>&1; then
1102 echo "const Sizeof$ngo = _sizeof_$nc" >> ${OUT}
1106 # In order to compile the net package, we need some sizes to exist
1107 # even if the types do not.
1108 if ! grep 'const SizeofIPMreq ' ${OUT} >/dev/null 2>&1; then
1109 echo 'const SizeofIPMreq = 8' >> ${OUT}
1111 if ! grep 'const SizeofIPv6Mreq ' ${OUT} >/dev/null 2>&1; then
1112 echo 'const SizeofIPv6Mreq = 20' >> ${OUT}
1114 if ! grep 'const SizeofIPMreqn ' ${OUT} >/dev/null 2>&1; then
1115 echo 'const SizeofIPMreqn = 12' >> ${OUT}