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