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