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>
163 #if defined(HAVE_NETINET_ICMP6_H)
164 #include <netinet/icmp6.h>
166 #if defined(HAVE_SCHED_H)
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. */
175 TIOCGWINSZ_val = TIOCGWINSZ,
178 TIOCSWINSZ_val = TIOCSWINSZ,
181 TIOCNOTTY_val = TIOCNOTTY,
184 TIOCSCTTY_val = TIOCSCTTY,
187 TIOCGPTN_val = TIOCGPTN,
190 TIOCSPTLCK_val = TIOCSPTLCK,
193 TIOCGDEV_val = TIOCGDEV,
196 TIOCSIG_val = TIOCSIG,
207 ${CC} -fdump-go-spec=gen-sysinfo.go
-std=gnu99
-S -o sysinfo.s sysinfo.c
209 echo 'package syscall' > ${OUT}
210 echo 'import "unsafe"' >> ${OUT}
211 echo 'type _ unsafe.Pointer' >> ${OUT}
213 # Get all the consts and types, skipping ones which could not be
214 # represented in Go and ones which we need to rewrite. We also skip
215 # function declarations, as we don't need them here. All the symbols
216 # will all have a leading underscore.
217 grep -v '^// ' gen-sysinfo.go | \
219 grep -v '^type _timeval ' | \
220 grep -v '^type _timespec_t ' | \
221 grep -v '^type _timespec ' | \
222 grep -v '^type _timestruc_t ' | \
223 grep -v '^type _epoll_' | \
224 grep -v 'in6_addr' | \
225 grep -v 'sockaddr_in6' | \
226 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
227 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
228 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
229 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
232 # The errno constants. These get type Errno.
233 echo '#include <errno.h>' |
${CC} -x c
- -E -dM | \
234 egrep '#define E[A-Z0-9_]+ ' | \
235 sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(_\1)/' >> ${OUT}
238 egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
239 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
240 if ! grep '^const O_ASYNC' ${OUT} >/dev
/null
2>&1; then
241 echo "const O_ASYNC = 0" >> ${OUT}
243 if ! grep '^const O_CLOEXEC' ${OUT} >/dev
/null
2>&1; then
244 echo "const O_CLOEXEC = 0" >> ${OUT}
247 # The os package requires F_DUPFD_CLOEXEC to be defined.
248 if ! grep '^const F_DUPFD_CLOEXEC' ${OUT} >/dev
/null
2>&1; then
249 echo "const F_DUPFD_CLOEXEC = 0" >> ${OUT}
252 # These flags can be lost on i386 GNU/Linux when using
253 # -D_FILE_OFFSET_BITS=64, because we see "#define F_SETLK F_SETLK64"
254 # before we see the definition of F_SETLK64.
255 for flag
in F_GETLK F_SETLK F_SETLKW
; do
256 if ! grep "^const ${flag} " ${OUT} >/dev
/null
2>&1 \
257 && grep "^const ${flag}64 " ${OUT} >/dev
/null
2>&1; then
258 echo "const ${flag} = ${flag}64" >> ${OUT}
262 # The Flock_t struct for fcntl.
263 grep '^type _flock ' gen-sysinfo.go | \
264 sed -e 's/type _flock/type Flock_t/' \
265 -e 's/l_type/Type/' \
266 -e 's/l_whence/Whence/' \
267 -e 's/l_start/Start/' \
272 # The signal numbers.
273 grep '^const _SIG[^_]' gen-sysinfo.go | \
274 grep -v '^const _SIGEV_' | \
275 sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = Signal(_\2)/' >> ${OUT}
276 if ! grep '^const SIGPOLL ' ${OUT} >/dev/null 2>&1; then
277 if grep '^const SIGIO ' ${OUT} > /dev/null 2>&1; then
278 echo "const SIGPOLL
= SIGIO
" >> ${OUT}
281 if ! grep '^const SIGCLD ' ${OUT} >/dev/null 2>&1; then
282 if grep '^const SIGCHLD ' ${OUT} >/dev/null 2>&1; then
283 echo "const SIGCLD
= SIGCHLD
" >> ${OUT}
287 # The syscall numbers. We force the names to upper case.
288 grep '^const _SYS_' gen-sysinfo.go | \
289 sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \
291 sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
292 echo "const
$sup = _
$sys" >> ${OUT}
295 # The GNU/Linux support wants to use SYS_GETDENTS64 if available.
296 if ! grep '^const SYS_GETDENTS ' ${OUT} >/dev/null 2>&1; then
297 echo "const SYS_GETDENTS
= 0" >> ${OUT}
299 if ! grep '^const SYS_GETDENTS64 ' ${OUT} >/dev/null 2>&1; then
300 echo "const SYS_GETDENTS64
= 0" >> ${OUT}
304 grep '^const _S_' gen-sysinfo.go | \
305 sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
308 grep '^const _PROT_' gen-sysinfo.go | \
309 sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
310 grep '^const _MAP_' gen-sysinfo.go | \
311 sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
312 grep '^const _MADV_' gen-sysinfo.go | \
313 sed -e 's/^\(const \)_\(MADV_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
314 grep '^const _MCL_' gen-sysinfo.go | \
315 sed -e 's/^\(const \)_\(MCL_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
317 # Process status constants.
318 grep '^const _W' gen-sysinfo.go |
319 sed -e 's/^\(const \)_\(W[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
320 # WSTOPPED was introduced in glibc 2.3.4.
321 if ! grep '^const _WSTOPPED = ' gen-sysinfo.go >/dev/null 2>&1; then
322 if grep '^const _WUNTRACED = ' gen-sysinfo.go > /dev/null 2>&1; then
323 echo 'const WSTOPPED = _WUNTRACED' >> ${OUT}
325 echo 'const WSTOPPED = 2' >> ${OUT}
328 if grep '^const ___WALL = ' gen-sysinfo.go >/dev/null 2>&1 \
329 && ! grep '^const _WALL = ' gen-sysinfo.go >/dev/null 2>&1; then
330 echo 'const WALL = ___WALL' >> ${OUT}
333 # Networking constants.
334 egrep '^const _(AF|ARPHRD|ETH|IN|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
335 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
336 grep '^const _SOMAXCONN' gen-sysinfo.go |
337 sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
339 grep '^const _SHUT_' gen-sysinfo.go |
340 sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
342 # The net package requires some const definitions.
343 for m in IP_PKTINFO IPV6_V6ONLY IPPROTO_IPV6 IPV6_JOIN_GROUP IPV6_LEAVE_GROUP IPV6_TCLASS SO_REUSEPORT; do
344 if ! grep "^const
$m " ${OUT} >/dev/null 2>&1; then
345 echo "const
$m = 0" >> ${OUT}
348 for m in SOCK_CLOEXEC SOCK_NONBLOCK; do
349 if ! grep "^const
$m " ${OUT} >/dev/null 2>&1; then
350 echo "const
$m = -1" >> ${OUT}
354 # The syscall package requires AF_LOCAL.
355 if ! grep '^const AF_LOCAL ' ${OUT} >/dev/null 2>&1; then
356 if grep '^const AF_UNIX ' ${OUT} >/dev/null 2>&1; then
357 echo "const AF_LOCAL
= AF_UNIX
" >> ${OUT}
361 # pathconf constants.
362 grep '^const __PC' gen-sysinfo.go |
363 sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
365 # The PATH_MAX constant.
366 if grep '^const _PATH_MAX ' gen-sysinfo.go >/dev/null 2>&1; then
367 echo 'const PathMax = _PATH_MAX' >> ${OUT}
371 grep '^const _EPOLL' gen-sysinfo.go |
372 sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
373 # Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
374 if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
375 echo "const EPOLLRDHUP
= 0x2000" >> ${OUT}
377 if ! grep '^const EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
378 echo "const EPOLL_CLOEXEC
= 02000000" >> ${OUT}
382 grep '^const _PR_' gen-sysinfo.go |
383 sed -e 's/^\(const \)_\(PR_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
386 grep '^const _PTRACE' gen-sysinfo.go |
387 sed -e 's/^\(const \)_\(PTRACE[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
388 # We need some ptrace options that are not defined in older versions
390 if ! grep '^const PTRACE_SETOPTIONS' ${OUT} > /dev/null 2>&1; then
391 echo "const PTRACE_SETOPTIONS
= 0x4200" >> ${OUT}
393 if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then
394 echo "const PTRACE_O_TRACESYSGOOD
= 0x1" >> ${OUT}
396 if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then
397 echo "const PTRACE_O_TRACEFORK
= 0x2" >> ${OUT}
399 if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then
400 echo "const PTRACE_O_TRACEVFORK
= 0x4" >> ${OUT}
402 if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then
403 echo "const PTRACE_O_TRACECLONE
= 0x8" >> ${OUT}
405 if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then
406 echo "const PTRACE_O_TRACEEXEC
= 0x10" >> ${OUT}
408 if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then
409 echo "const PTRACE_O_TRACEVFORKDONE
= 0x20" >> ${OUT}
411 if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then
412 echo "const PTRACE_O_TRACEEXIT
= 0x40" >> ${OUT}
414 if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then
415 echo "const PTRACE_O_MASK
= 0x7f" >> ${OUT}
417 if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
418 echo "const PTRACE_GETEVENTMSG
= 0x4201" >> ${OUT}
420 if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
421 echo "const PTRACE_EVENT_FORK
= 1" >> ${OUT}
423 if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then
424 echo "const PTRACE_EVENT_VFORK
= 2" >> ${OUT}
426 if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then
427 echo "const PTRACE_EVENT_CLONE
= 3" >> ${OUT}
429 if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then
430 echo "const PTRACE_EVENT_EXEC
= 4" >> ${OUT}
432 if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then
433 echo "const PTRACE_EVENT_VFORK_DONE
= 5" >> ${OUT}
435 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
436 echo "const PTRACE_EVENT_EXIT
= 6" >> ${OUT}
438 if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
439 echo "const _PTRACE_TRACEME
= 0" >> ${OUT}
442 # The registers returned by PTRACE_GETREGS. This is probably
443 # GNU/Linux specific; it should do no harm if there is no
445 regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
446 if test "$regs" != ""; then
447 regs=`echo $regs | sed -e 's/type _user_regs_struct struct //' -e 's/[{}]//g'`
448 regs=`echo $regs | sed -e s'/^ *//'`
450 while test -n "$regs"; do
451 field=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
452 regs=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
453 # Capitalize the first character of the field.
454 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
455 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
456 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
458 nregs="$nregs $field;"
460 echo "type PtraceRegs struct
{$nregs }" >> ${OUT}
464 echo 'type Size_t _size_t' >> ${OUT}
465 echo "type Ssize_t _ssize_t
" >> ${OUT}
466 if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then
467 echo "type Offset_t _off64_t
" >> ${OUT}
469 echo "type Offset_t _off_t
" >> ${OUT}
471 echo "type Mode_t _mode_t
" >> ${OUT}
472 echo "type Pid_t _pid_t
" >> ${OUT}
473 echo "type Uid_t _uid_t
" >> ${OUT}
474 echo "type Gid_t _gid_t
" >> ${OUT}
475 echo "type Socklen_t _socklen_t
" >> ${OUT}
478 sizeof_int=`grep '^const ___SIZEOF_INT__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
479 if test "$sizeof_int" = "4"; then
480 echo "type _C_int int32
" >> ${OUT}
481 echo "type _C_uint uint32
" >> ${OUT}
482 elif test "$sizeof_int" = "8"; then
483 echo "type _C_int int64
" >> ${OUT}
484 echo "type _C_uint uint64
" >> ${OUT}
486 echo 1>&2 "mksysinfo.sh
: could not determine size of int
(got
$sizeof_int)"
490 # The C long type, needed because that is the type that ptrace returns.
491 sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
492 if test "$sizeof_long" = "4"; then
493 echo "type _C_long int32
" >> ${OUT}
494 elif test "$sizeof_long" = "8"; then
495 echo "type _C_long int64
" >> ${OUT}
497 echo 1>&2 "mksysinfo.sh
: could not determine size of long
(got
$sizeof_long)"
501 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
502 # double is commented by -fdump-go-spec.
503 if grep "^
// type _pad128_t
" gen-sysinfo.go > /dev/null 2>&1; then
504 echo "type _pad128_t struct
{ _l
[4]int32
; }" >> ${OUT}
506 if grep "^
// type _upad128_t
" gen-sysinfo.go > /dev/null 2>&1; then
507 echo "type _upad128_t struct
{ _l
[4]uint32
; }" >> ${OUT}
511 if grep '^type _time_t ' gen-sysinfo.go > /dev/null 2>&1; then
512 echo 'type Time_t _time_t' >> ${OUT}
515 # The time structures need special handling: we need to name the
516 # types, so that we can cast integers to the right types when
517 # assigning to the structures.
518 timeval=`grep '^type _timeval ' gen-sysinfo.go`
519 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
520 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
521 echo "type Timeval_sec_t
$timeval_sec" >> ${OUT}
522 echo "type Timeval_usec_t
$timeval_usec" >> ${OUT}
524 sed -e 's/type _timeval /type Timeval /' \
525 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
526 -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
527 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
528 if test "$timespec" = ""; then
529 # IRIX 6.5 has __timespec instead.
530 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
532 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
533 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
534 echo "type Timespec_sec_t
$timespec_sec" >> ${OUT}
535 echo "type Timespec_nsec_t
$timespec_nsec" >> ${OUT}
537 sed -e 's/^type ___timespec /type Timespec /' \
538 -e 's/^type _timespec /type Timespec /' \
539 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
540 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
542 timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
543 if test "$timestruc" != ""; then
544 timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
545 timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
546 echo "type Timestruc_sec_t
$timestruc_sec" >> ${OUT}
547 echo "type Timestruc_nsec_t
$timestruc_nsec" >> ${OUT}
549 sed -e 's/^type _timestruc_t /type Timestruc /' \
550 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
551 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
555 grep '^type _tms ' gen-sysinfo.go | \
556 sed -e 's/type _tms/type Tms/' \
557 -e 's/tms_utime/Utime/' \
558 -e 's/tms_stime/Stime/' \
559 -e 's/tms_cutime/Cutime/' \
560 -e 's/tms_cstime/Cstime/' \
564 # Prefer largefile variant if available.
565 stat=`grep '^type _stat64 ' gen-sysinfo.go || true`
566 if test "$stat" != ""; then
567 grep '^type _stat64 ' gen-sysinfo.go
569 grep '^type _stat ' gen-sysinfo.go
570 fi | sed -e 's/type _stat64/type Stat_t/' \
571 -e 's/type _stat/type Stat_t/' \
573 -e 's/st_ino/Ino/g' \
574 -e 's/st_nlink/Nlink/' \
575 -e 's/st_mode/Mode/' \
578 -e 's/st_rdev/Rdev/' \
579 -e 's/st_size/Size/' \
580 -e 's/st_blksize/Blksize/' \
581 -e 's/st_blocks/Blocks/' \
582 -e 's/st_atim/Atim/' \
583 -e 's/st_mtim/Mtim/' \
584 -e 's/st_ctim/Ctim/' \
585 -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
586 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
587 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
588 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
589 -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
592 # The directory searching types.
593 # Prefer largefile variant if available.
594 dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true`
595 if test "$dirent" != ""; then
596 grep '^type _dirent64 ' gen-sysinfo.go
598 grep '^type _dirent ' gen-sysinfo.go
599 fi | sed -e 's/type _dirent64/type Dirent/' \
600 -e 's/type _dirent/type Dirent/' \
601 -e 's/d_name \[0+1\]/d_name [0+256]/' \
602 -e 's/d_name/Name/' \
603 -e 's/]int8/]byte/' \
606 -e 's/d_reclen/Reclen/' \
607 -e 's/d_type/Type/' \
609 echo "type DIR _DIR
" >> ${OUT}
611 # Values for d_type field in dirent.
612 grep '^const _DT_' gen-sysinfo.go |
613 sed -e 's/^\(const \)_\(DT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
616 rusage=`grep '^type _rusage struct' gen-sysinfo.go`
617 if test "$rusage" != ""; then
618 # Remove anonymous unions from GNU/Linux <bits/resource.h>.
619 rusage=`echo $rusage | sed -e 's/Godump_[0-9]* struct {\([^}]*\)};/\1/g'`
620 rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
621 rusage=`echo $rusage | sed -e 's/^ *//'`
623 while test -n "$rusage"; do
624 field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
625 rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
626 # Drop the leading ru_, capitalize the next character.
627 field=`echo $field | sed -e 's/^ru_//'`
628 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
629 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
630 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
631 # Fix _timeval _timespec, and _timestruc_t.
632 r=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
633 r=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
634 r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
636 nrusage="$nrusage $field;"
638 echo "type Rusage struct
{$nrusage }" >> ${OUT}
640 echo "type Rusage struct
{}" >> ${OUT}
643 # The RUSAGE constants.
644 grep '^const _RUSAGE_' gen-sysinfo.go | \
645 sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
647 # The utsname struct.
648 grep '^type _utsname ' gen-sysinfo.go | \
649 sed -e 's/_utsname/Utsname/' \
650 -e 's/sysname/Sysname/' \
651 -e 's/nodename/Nodename/' \
652 -e 's/release/Release/' \
653 -e 's/version/Version/' \
654 -e 's/machine/Machine/' \
655 -e 's/domainname/Domainname/' \
659 iovec=`grep '^type _iovec ' gen-sysinfo.go`
660 iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
661 echo "type Iovec_len_t
$iovec_len" >> ${OUT}
663 sed -e 's/_iovec/Iovec/' \
664 -e 's/iov_base/Base/' \
665 -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
669 msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
670 msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
671 echo "type Msghdr_controllen_t
$msghdr_controllen" >> ${OUT}
673 sed -e 's/_msghdr/Msghdr/' \
674 -e 's/msg_name/Name/' \
675 -e 's/msg_namelen/Namelen/' \
676 -e 's/msg_iov/Iov/' \
677 -e 's/msg_iovlen/Iovlen/' \
678 -e 's/_iovec/Iovec/' \
679 -e 's/msg_control/Control/' \
680 -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
681 -e 's/msg_flags/Flags/' \
684 # The MSG_ flags for Msghdr.
685 grep '^const _MSG_' gen-sysinfo.go | \
686 sed -e 's/^\(const \)_\(MSG_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
688 # The cmsghdr struct.
689 cmsghdr=`grep '^type _cmsghdr ' gen-sysinfo.go`
690 if test -n "$cmsghdr"; then
691 cmsghdr_len=`echo $cmsghdr | sed -n -e 's/^.*cmsg_len \([^ ]*\);.*$/\1/p'`
692 echo "type Cmsghdr_len_t
$cmsghdr_len" >> ${OUT}
694 sed -e 's/_cmsghdr/Cmsghdr/' \
695 -e 's/cmsg_len *[a-zA-Z0-9_]*/Len Cmsghdr_len_t/' \
696 -e 's/cmsg_level/Level/' \
697 -e 's/cmsg_type/Type/' \
702 # The SCM_ flags for Cmsghdr.
703 grep '^const _SCM_' gen-sysinfo.go | \
704 sed -e 's/^\(const \)_\(SCM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
707 grep '^type _ucred ' gen-sysinfo.go | \
708 sed -e 's/_ucred/Ucred/' \
714 # The ip_mreq struct.
715 grep '^type _ip_mreq ' gen-sysinfo.go | \
716 sed -e 's/_ip_mreq/IPMreq/' \
717 -e 's/imr_multiaddr/Multiaddr/' \
718 -e 's/imr_interface/Interface/' \
719 -e 's/_in_addr/[4]byte/g' \
722 # We need IPMreq to compile the net package.
723 if ! grep 'type IPMreq ' ${OUT} >/dev/null 2>&1; then
724 echo 'type IPMreq struct { Multiaddr [4]byte; Interface [4]byte; }' >> ${OUT}
727 # The ipv6_mreq struct.
728 grep '^type _ipv6_mreq ' gen-sysinfo.go | \
729 sed -e 's/_ipv6_mreq/IPv6Mreq/' \
730 -e 's/ipv6mr_multiaddr/Multiaddr/' \
731 -e 's/ipv6mr_interface/Interface/' \
732 -e 's/_in6_addr/[16]byte/' \
735 # We need IPv6Mreq to compile the net package.
736 if ! grep 'type IPv6Mreq ' ${OUT} >/dev/null 2>&1; then
737 echo 'type IPv6Mreq struct { Multiaddr [16]byte; Interface uint32; }' >> ${OUT}
740 # The ip_mreqn struct.
741 grep '^type _ip_mreqn ' gen-sysinfo.go | \
742 sed -e 's/_ip_mreqn/IPMreqn/' \
743 -e 's/imr_multiaddr/Multiaddr/' \
744 -e 's/imr_address/Address/' \
745 -e 's/imr_ifindex/Ifindex/' \
746 -e 's/_in_addr/[4]byte/g' \
749 # We need IPMreq to compile the net package.
750 if ! grep 'type IPMreqn ' ${OUT} >/dev/null 2>&1; then
751 echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT}
754 # The icmp6_filter struct.
755 grep '^type _icmp6_filter ' gen-sysinfo.go | \
756 sed -e 's/_icmp6_filter/ICMPv6Filter/' \
761 # We need ICMPv6Filter to compile the syscall package.
762 if ! grep 'type ICMPv6Filter ' ${OUT} > /dev/null 2>&1; then
763 echo 'type ICMPv6Filter struct { Data [8]uint32 }' >> ${OUT}
766 # Try to guess the type to use for fd_set.
767 fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
768 fds_bits_type="_C_long
"
769 if test "$fd_set" != ""; then
770 fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
772 echo "type fds_bits_type
$fds_bits_type" >> ${OUT}
774 # The addrinfo struct.
775 grep '^type _addrinfo ' gen-sysinfo.go | \
776 sed -e 's/_addrinfo/Addrinfo/g' \
780 # The addrinfo flags and errors.
781 grep '^const _AI_' gen-sysinfo.go | \
782 sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
783 grep '^const _EAI_' gen-sysinfo.go | \
784 sed -e 's/^\(const \)_\(EAI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
787 grep '^type _passwd ' gen-sysinfo.go | \
788 sed -e 's/_passwd/Passwd/' \
792 # The ioctl flags for the controlling TTY.
793 grep '^const _TIOC' gen-sysinfo.go | \
795 sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
796 # We need TIOCGWINSZ.
797 if ! grep '^const TIOCGWINSZ' ${OUT} >/dev/null 2>&1; then
798 if grep '^const _TIOCGWINSZ_val' ${OUT} >/dev/null 2>&1; then
799 echo 'const TIOCGWINSZ = _TIOCGWINSZ_val' >> ${OUT}
802 if ! grep '^const TIOCSWINSZ' ${OUT} >/dev/null 2>&1; then
803 if grep '^const _TIOCSWINSZ_val' ${OUT} >/dev/null 2>&1; then
804 echo 'const TIOCSWINSZ = _TIOCSWINSZ_val' >> ${OUT}
807 if ! grep '^const TIOCNOTTY' ${OUT} >/dev/null 2>&1; then
808 if grep '^const _TIOCNOTTY_val' ${OUT} >/dev/null 2>&1; then
809 echo 'const TIOCNOTTY = _TIOCNOTTY_val' >> ${OUT}
812 if ! grep '^const TIOCSCTTY' ${OUT} >/dev/null 2>&1; then
813 if grep '^const _TIOCSCTTY_val' ${OUT} >/dev/null 2>&1; then
814 echo 'const TIOCSCTTY = _TIOCSCTTY_val' >> ${OUT}
817 if ! grep '^const TIOCGPTN' ${OUT} >/dev/null 2>&1; then
818 if grep '^const _TIOCGPTN_val' ${OUT} >/dev/null 2>&1; then
819 echo 'const TIOCGPTN = _TIOCGPTN_val' >> ${OUT}
822 if ! grep '^const TIOCSPTLCK' ${OUT} >/dev/null 2>&1; then
823 if grep '^const _TIOCSPTLCK_val' ${OUT} >/dev/null 2>&1; then
824 echo 'const TIOCSPTLCK = _TIOCSPTLCK_val' >> ${OUT}
827 if ! grep '^const TIOCGDEV' ${OUT} >/dev/null 2>&1; then
828 if grep '^const _TIOCGDEV_val' ${OUT} >/dev/null 2>&1; then
829 echo 'const TIOCGDEV = _TIOCGDEV_val' >> ${OUT}
832 if ! grep '^const TIOCSIG' ${OUT} >/dev/null 2>&1; then
833 if grep '^const _TIOCSIG_val' ${OUT} >/dev/null 2>&1; then
834 echo 'const TIOCSIG = _TIOCSIG_val' >> ${OUT}
838 # The ioctl flags for terminal control
839 grep '^const _TC[GS]ET' gen-sysinfo.go | grep -v _val | \
840 sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
841 if ! grep '^const TCGETS' ${OUT} >/dev/null 2>&1; then
842 if grep '^const _TCGETS_val' ${OUT} >/dev/null 2>&1; then
843 echo 'const TCGETS = _TCGETS_val' >> ${OUT}
846 if ! grep '^const TCSETS' ${OUT} >/dev/null 2>&1; then
847 if grep '^const _TCSETS_val' ${OUT} >/dev/null 2>&1; then
848 echo 'const TCSETS = _TCSETS_val' >> ${OUT}
852 # ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but
853 # needs handling in syscalls.exec.go.
854 if ! grep '^const _TIOCSCTTY ' gen-sysinfo.go >/dev/null 2>&1; then
855 if grep '^const _TIOCNXCL ' gen-sysinfo.go >/dev/null 2>&1; then
856 echo "const TIOCSCTTY
= TIOCNXCL
" >> ${OUT}
860 # The nlmsghdr struct.
861 grep '^type _nlmsghdr ' gen-sysinfo.go | \
862 sed -e 's/_nlmsghdr/NlMsghdr/' \
863 -e 's/nlmsg_len/Len/' \
864 -e 's/nlmsg_type/Type/' \
865 -e 's/nlmsg_flags/Flags/' \
866 -e 's/nlmsg_seq/Seq/' \
867 -e 's/nlmsg_pid/Pid/' \
870 # The nlmsg flags and operators.
871 grep '^const _NLM' gen-sysinfo.go | \
872 sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
874 # NLMSG_HDRLEN is defined as an expression using sizeof.
875 if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev/null 2>&1; then
876 if grep '^const _sizeof_nlmsghdr ' ${OUT} > /dev/null 2>&1; then
877 echo 'const NLMSG_HDRLEN = (_sizeof_nlmsghdr + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1)' >> ${OUT}
882 grep '^type _rtmsg ' gen-sysinfo.go | \
883 sed -e 's/_rtmsg/RtMsg/' \
884 -e 's/rtm_family/Family/' \
885 -e 's/rtm_dst_len/Dst_len/' \
886 -e 's/rtm_src_len/Src_len/' \
887 -e 's/rtm_tos/Tos/' \
888 -e 's/rtm_table/Table/' \
889 -e 's/rtm_protocol/Protocol/' \
890 -e 's/rtm_scope/Scope/' \
891 -e 's/rtm_type/Type/' \
892 -e 's/rtm_flags/Flags/' \
895 # The rtgenmsg struct.
896 grep '^type _rtgenmsg ' gen-sysinfo.go | \
897 sed -e 's/_rtgenmsg/RtGenmsg/' \
898 -e 's/rtgen_family/Family/' \
901 # The routing message flags.
902 grep '^const _RT_' gen-sysinfo.go | \
903 sed -e 's/^\(const \)_\(RT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
904 grep '^const _RTA' gen-sysinfo.go | \
905 sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
906 grep '^const _RTF' gen-sysinfo.go | \
907 sed -e 's/^\(const \)_\(RTF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
908 grep '^const _RTCF' gen-sysinfo.go | \
909 sed -e 's/^\(const \)_\(RTCF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
910 grep '^const _RTM' gen-sysinfo.go | \
911 sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
912 grep '^const _RTN' gen-sysinfo.go | \
913 sed -e 's/^\(const \)_\(RTN[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
914 grep '^const _RTPROT' gen-sysinfo.go | \
915 sed -e 's/^\(const \)_\(RTPROT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
917 # The ifinfomsg struct.
918 grep '^type _ifinfomsg ' gen-sysinfo.go | \
919 sed -e 's/_ifinfomsg/IfInfomsg/' \
920 -e 's/ifi_family/Family/' \
921 -e 's/ifi_type/Type/' \
922 -e 's/ifi_index/Index/' \
923 -e 's/ifi_flags/Flags/' \
924 -e 's/ifi_change/Change/' \
927 # The interface information types and flags.
928 grep '^const _IFA' gen-sysinfo.go | \
929 sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
930 grep '^const _IFLA' gen-sysinfo.go | \
931 sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
932 grep '^const _IFF' gen-sysinfo.go | \
933 sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
934 grep '^const _IFNAMSIZ' gen-sysinfo.go | \
935 sed -e 's/^\(const \)_\(IFNAMSIZ[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
936 grep '^const _SIOC' gen-sysinfo.go |
937 sed -e 's/^\(const \)_\(SIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
939 # The ifaddrmsg struct.
940 grep '^type _ifaddrmsg ' gen-sysinfo.go | \
941 sed -e 's/_ifaddrmsg/IfAddrmsg/' \
942 -e 's/ifa_family/Family/' \
943 -e 's/ifa_prefixlen/Prefixlen/' \
944 -e 's/ifa_flags/Flags/' \
945 -e 's/ifa_scope/Scope/' \
946 -e 's/ifa_index/Index/' \
950 grep '^type _rtattr ' gen-sysinfo.go | \
951 sed -e 's/_rtattr/RtAttr/' \
952 -e 's/rta_len/Len/' \
953 -e 's/rta_type/Type/' \
956 # The in_pktinfo struct.
957 grep '^type _in_pktinfo ' gen-sysinfo.go | \
958 sed -e 's/_in_pktinfo/Inet4Pktinfo/' \
959 -e 's/ipi_ifindex/Ifindex/' \
960 -e 's/ipi_spec_dst/Spec_dst/' \
961 -e 's/ipi_addr/Addr/' \
962 -e 's/_in_addr/[4]byte/g' \
965 # The in6_pktinfo struct.
966 grep '^type _in6_pktinfo ' gen-sysinfo.go | \
967 sed -e 's/_in6_pktinfo/Inet6Pktinfo/' \
968 -e 's/ipi6_addr/Addr/' \
969 -e 's/ipi6_ifindex/Ifindex/' \
970 -e 's/_in6_addr/[16]byte/' \
973 # The termios struct.
974 grep '^type _termios ' gen-sysinfo.go | \
975 sed -e 's/_termios/Termios/' \
976 -e 's/c_iflag/Iflag/' \
977 -e 's/c_oflag/Oflag/' \
978 -e 's/c_cflag/Cflag/' \
979 -e 's/c_lflag/Lflag/' \
980 -e 's/c_line/Line/' \
982 -e 's/c_ispeed/Ispeed/' \
983 -e 's/c_ospeed/Ospeed/' \
986 # The termios constants.
987 for n in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \
988 IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \
989 OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 CS5 CS6 CS7 CS8 TABDLY \
990 BSDLY VTDLY FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL \
991 CLOCAL LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE ECHO ECHOE ECHOK \
992 ECHONL ECHOCTL ECHOPRT ECHOKE DEFECHO FLUSHO NOFLSH TOSTOP PENDIN IEXTEN \
993 VINTR VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 VSWTCH VSTART VSTOP \
994 VSUSP VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS TCSANOW TCSADRAIN \
995 TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON TCIOFF TCION B0 B50 \
996 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 \
997 B38400 B57600 B115200 B230400 B460800 B500000 B576000 B921600 B1000000 \
998 B1152000 B1500000 B2000000 B2500000 B3000000 B3500000 B4000000; do
1000 grep "^const _
$n " gen-sysinfo.go | \
1001 sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1005 grep '^const _MNT_' gen-sysinfo.go |
1006 sed -e 's/^\(const \)_\(MNT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1007 grep '^const _MS_' gen-sysinfo.go |
1008 sed -e 's/^\(const \)_\(MS_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1010 # The fallocate flags.
1011 grep '^const _FALLOC_' gen-sysinfo.go |
1012 sed -e 's/^\(const \)_\(FALLOC_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1014 # The statfs struct.
1015 # Prefer largefile variant if available.
1016 statfs=`grep '^type _statfs64 ' gen-sysinfo.go || true`
1017 if test "$statfs" != ""; then
1018 grep '^type _statfs64 ' gen-sysinfo.go
1020 grep '^type _statfs ' gen-sysinfo.go
1021 fi | sed -e 's/type _statfs64/type Statfs_t/' \
1022 -e 's/type _statfs/type Statfs_t/' \
1023 -e 's/f_type/Type/' \
1024 -e 's/f_bsize/Bsize/' \
1025 -e 's/f_blocks/Blocks/' \
1026 -e 's/f_bfree/Bfree/' \
1027 -e 's/f_bavail/Bavail/' \
1028 -e 's/f_files/Files/' \
1029 -e 's/f_ffree/Ffree/' \
1030 -e 's/f_fsid/Fsid/' \
1031 -e 's/f_namelen/Namelen/' \
1032 -e 's/f_frsize/Frsize/' \
1033 -e 's/f_flags/Flags/' \
1034 -e 's/f_spare/Spare/' \
1038 timex=`grep '^type _timex ' gen-sysinfo.go || true`
1039 if test "$timex" = ""; then
1040 timex=`grep '^// type _timex ' gen-sysinfo.go || true`
1041 if test "$timex" != ""; then
1042 timex=`echo $timex | sed -e 's|// ||' -e 's/INVALID-bit-field/int32/g'`
1045 if test "$timex" != ""; then
1047 sed -e 's/_timex/Timex/' \
1048 -e 's/modes/Modes/' \
1049 -e 's/offset/Offset/' \
1051 -e 's/maxerror/Maxerror/' \
1052 -e 's/esterror/Esterror/' \
1053 -e 's/status/Status/' \
1054 -e 's/constant/Constant/' \
1055 -e 's/precision/Precision/' \
1056 -e 's/tolerance/Tolerance/' \
1057 -e 's/ time / Time /' \
1059 -e 's/ppsfreq/Ppsfreq/' \
1060 -e 's/jitter/Jitter/' \
1061 -e 's/shift/Shift/' \
1062 -e 's/stabil/Stabil/' \
1063 -e 's/jitcnt/Jitcnt/' \
1064 -e 's/calcnt/Calcnt/' \
1065 -e 's/errcnt/Errcnt/' \
1066 -e 's/stbcnt/Stbcnt/' \
1068 -e 's/_timeval/Timeval/' \
1072 # The rlimit struct.
1073 grep '^type _rlimit ' gen-sysinfo.go | \
1074 sed -e 's/_rlimit/Rlimit/' \
1075 -e 's/rlim_cur/Cur/' \
1076 -e 's/rlim_max/Max/' \
1079 # The RLIMIT constants.
1080 grep '^const _RLIMIT_' gen-sysinfo.go |
1081 sed -e 's/^\(const \)_\(RLIMIT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1082 grep '^const _RLIM_' gen-sysinfo.go |
1083 sed -e 's/^\(const \)_\(RLIM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1085 # The sysinfo struct.
1086 grep '^type _sysinfo ' gen-sysinfo.go | \
1087 sed -e 's/_sysinfo/Sysinfo_t/' \
1088 -e 's/uptime/Uptime/' \
1089 -e 's/loads/Loads/' \
1090 -e 's/totalram/Totalram/' \
1091 -e 's/freeram/Freeram/' \
1092 -e 's/sharedram/Sharedram/' \
1093 -e 's/bufferram/Bufferram/' \
1094 -e 's/totalswap/Totalswap/' \
1095 -e 's/freeswap/Freeswap/' \
1096 -e 's/procs/Procs/' \
1097 -e 's/totalhigh/Totalhigh/' \
1098 -e 's/freehigh/Freehigh/' \
1099 -e 's/mem_unit/Unit/' \
1103 grep '^type _ustat ' gen-sysinfo.go | \
1104 sed -e 's/_ustat/Ustat_t/' \
1105 -e 's/f_tfree/Tfree/' \
1106 -e 's/f_tinode/Tinoe/' \
1107 -e 's/f_fname/Fname/' \
1108 -e 's/f_fpack/Fpack/' \
1110 # Force it to be defined, as on some older GNU/Linux systems the
1111 # header file fails when using with <linux/filter.h>.
1112 if ! grep 'type _ustat ' gen-sysinfo.go >/dev/null 2>&1; then
1113 echo 'type Ustat_t struct { Tfree int32; Tinoe uint64; Fname [5+1]int8; Fpack [5+1]int8; }' >> ${OUT}
1116 # The utimbuf struct.
1117 grep '^type _utimbuf ' gen-sysinfo.go | \
1118 sed -e 's/_utimbuf/Utimbuf/' \
1119 -e 's/actime/Actime/' \
1120 -e 's/modtime/Modtime/' \
1123 # The LOCK flags for flock.
1124 grep '^const _LOCK_' gen-sysinfo.go |
1125 sed -e 's/^\(const \)_\(LOCK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1127 # The PRIO constants.
1128 grep '^const _PRIO_' gen-sysinfo.go | \
1129 sed -e 's/^\(const \)_\(PRIO_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1131 # The GNU/Linux LINUX_REBOOT flags.
1132 grep '^const _LINUX_REBOOT_' gen-sysinfo.go |
1133 sed -e 's/^\(const \)_\(LINUX_REBOOT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1135 # The GNU/Linux sock_filter struct.
1136 grep '^type _sock_filter ' gen-sysinfo.go | \
1137 sed -e 's/_sock_filter/SockFilter/' \
1144 # The GNU/Linux sock_fprog struct.
1145 grep '^type _sock_fprog ' gen-sysinfo.go | \
1146 sed -e 's/_sock_fprog/SockFprog/' \
1148 -e 's/filter/Filter/' \
1149 -e 's/_sock_filter/SockFilter/' \
1152 # The GNU/Linux filter flags.
1153 grep '^const _BPF_' gen-sysinfo.go | \
1154 sed -e 's/^\(const \)_\(BPF_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1156 # The GNU/Linux nlattr struct.
1157 grep '^type _nlattr ' gen-sysinfo.go | \
1158 sed -e 's/_nlattr/NlAttr/' \
1159 -e 's/nla_len/Len/' \
1160 -e 's/nla_type/Type/' \
1163 # The GNU/Linux nlmsgerr struct.
1164 grep '^type _nlmsgerr ' gen-sysinfo.go | \
1165 sed -e 's/_nlmsgerr/NlMsgerr/' \
1166 -e 's/error/Error/' \
1168 -e 's/_nlmsghdr/NlMsghdr/' \
1171 # The GNU/Linux rtnexthop struct.
1172 grep '^type _rtnexthop ' gen-sysinfo.go | \
1173 sed -e 's/_rtnexthop/RtNexthop/' \
1174 -e 's/rtnh_len/Len/' \
1175 -e 's/rtnh_flags/Flags/' \
1176 -e 's/rtnh_hops/Hops/' \
1177 -e 's/rtnh_ifindex/Ifindex/' \
1180 # The GNU/Linux netlink flags.
1181 grep '^const _NETLINK_' gen-sysinfo.go | \
1182 sed -e 's/^\(const \)_\(NETLINK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1183 grep '^const _NLA_' gen-sysinfo.go | \
1184 sed -e 's/^\(const \)_\(NLA_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1186 # The GNU/Linux packet socket flags.
1187 grep '^const _PACKET_' gen-sysinfo.go | \
1188 sed -e 's/^\(const \)_\(PACKET_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1190 # The GNU/Linux inotify_event struct.
1191 grep '^type _inotify_event ' gen-sysinfo.go | \
1192 sed -e 's/_inotify_event/InotifyEvent/' \
1195 -e 's/cookie/Cookie/' \
1199 -e 's/\[0\]byte/[0]int8/' \
1202 # The GNU/Linux CLONE flags.
1203 grep '^const _CLONE_' gen-sysinfo.go | \
1204 sed -e 's/^\(const \)_\(CLONE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1206 # The Solaris 11 Update 1 _zone_net_addr_t struct.
1207 grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
1208 sed -e 's/_in6_addr/[16]byte/' \
1212 set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \
1213 ifaddrmsg IfAddrmsg ifinfomsg IfInfomsg in_pktinfo Inet4Pktinfo \
1214 in6_pktinfo Inet6Pktinfo inotify_event InotifyEvent linger Linger \
1215 msghdr Msghdr nlattr NlAttr nlmsgerr NlMsgerr nlmsghdr NlMsghdr \
1216 rtattr RtAttr rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \
1217 sock_filter SockFilter sock_fprog SockFprog ucred Ucred \
1218 icmp6_filter ICMPv6Filter
1219 while test $# != 0; do
1224 if grep "^const _sizeof_
$nc =" gen-sysinfo.go >/dev/null 2>&1; then
1225 echo "const Sizeof
$ngo = _sizeof_
$nc" >> ${OUT}
1229 # In order to compile the net package, we need some sizes to exist
1230 # even if the types do not.
1231 if ! grep 'const SizeofIPMreq ' ${OUT} >/dev/null 2>&1; then
1232 echo 'const SizeofIPMreq = 8' >> ${OUT}
1234 if ! grep 'const SizeofIPv6Mreq ' ${OUT} >/dev/null 2>&1; then
1235 echo 'const SizeofIPv6Mreq = 20' >> ${OUT}
1237 if ! grep 'const SizeofIPMreqn ' ${OUT} >/dev/null 2>&1; then
1238 echo 'const SizeofIPMreqn = 12' >> ${OUT}
1240 if ! grep 'const SizeofICMPv6Filter ' ${OUT} >/dev/null 2>&1; then
1241 echo 'const SizeofICMPv6Filter = 32' >> ${OUT}