ac5f08631995d34ae3e09dafc4665cf413c726a4
[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 #include <grp.h>
101 #if defined(HAVE_LINUX_FILTER_H)
102 #include <linux/filter.h>
103 #endif
104 #if defined(HAVE_LINUX_IF_ADDR_H)
105 #include <linux/if_addr.h>
106 #endif
107 #if defined(HAVE_LINUX_IF_ETHER_H)
108 #include <linux/if_ether.h>
109 #endif
110 #if defined(HAVE_LINUX_IF_TUN_H)
111 #include <linux/if_tun.h>
112 #endif
113 #if defined(HAVE_LINUX_NETLINK_H)
114 #include <linux/netlink.h>
115 #endif
116 #if defined(HAVE_LINUX_RTNETLINK_H)
117 #include <linux/rtnetlink.h>
118 #endif
119 #if defined(HAVE_NET_IF_H)
120 #include <net/if.h>
121 #endif
122 #if defined(HAVE_NET_IF_ARP_H)
123 #include <net/if_arp.h>
124 #endif
125 #if defined(HAVE_NET_ROUTE_H)
126 #include <net/route.h>
127 #endif
128 #if defined (HAVE_NETPACKET_PACKET_H)
129 #include <netpacket/packet.h>
130 #endif
131 #if defined(HAVE_SYS_MOUNT_H)
132 #include <sys/mount.h>
133 #endif
134 #if defined(HAVE_SYS_VFS_H)
135 #include <sys/vfs.h>
136 #endif
137 #if defined(HAVE_STATFS_H)
138 #include <sys/statfs.h>
139 #endif
140 #if defined(HAVE_SYS_TIMEX_H)
141 #include <sys/timex.h>
142 #endif
143 #if defined(HAVE_SYS_SYSINFO_H)
144 #include <sys/sysinfo.h>
145 #endif
146 #if defined(HAVE_USTAT_H)
147 #include <ustat.h>
148 #endif
149 #if defined(HAVE_UTIME_H)
150 #include <utime.h>
151 #endif
152 #if defined(HAVE_LINUX_ETHER_H)
153 #include <linux/ether.h>
154 #endif
155 #if defined(HAVE_LINUX_FS_H)
156 #include <linux/fs.h>
157 #endif
158 #if defined(HAVE_LINUX_REBOOT_H)
159 #include <linux/reboot.h>
160 #endif
161 #if defined(HAVE_SYS_INOTIFY_H)
162 #include <sys/inotify.h>
163 #endif
164 #if defined(HAVE_NETINET_ICMP6_H)
165 #include <netinet/icmp6.h>
166 #endif
167 #if defined(HAVE_SCHED_H)
168 #include <sched.h>
169 #endif
170
171 /* Constants that may only be defined as expressions on some systems,
172 expressions too complex for -fdump-go-spec to handle. These are
173 handled specially below. */
174 enum {
175 #ifdef TIOCGWINSZ
176 TIOCGWINSZ_val = TIOCGWINSZ,
177 #endif
178 #ifdef TIOCSWINSZ
179 TIOCSWINSZ_val = TIOCSWINSZ,
180 #endif
181 #ifdef TIOCNOTTY
182 TIOCNOTTY_val = TIOCNOTTY,
183 #endif
184 #ifdef TIOCSCTTY
185 TIOCSCTTY_val = TIOCSCTTY,
186 #endif
187 #ifdef TIOCGPGRP
188 TIOCGPGRP_val = TIOCGPGRP,
189 #endif
190 #ifdef TIOCSPGRP
191 TIOCSPGRP_val = TIOCSPGRP,
192 #endif
193 #ifdef TIOCGPTN
194 TIOCGPTN_val = TIOCGPTN,
195 #endif
196 #ifdef TIOCSPTLCK
197 TIOCSPTLCK_val = TIOCSPTLCK,
198 #endif
199 #ifdef TIOCGDEV
200 TIOCGDEV_val = TIOCGDEV,
201 #endif
202 #ifdef TIOCSIG
203 TIOCSIG_val = TIOCSIG,
204 #endif
205 #ifdef TCGETS
206 TCGETS_val = TCGETS,
207 #endif
208 #ifdef TCSETS
209 TCSETS_val = TCSETS,
210 #endif
211 #ifdef TUNSETIFF
212 TUNSETIFF_val = TUNSETIFF,
213 #endif
214 #ifdef TUNSETNOCSUM
215 TUNSETNOCSUM_val = TUNSETNOCSUM,
216 #endif
217 #ifdef TUNSETDEBUG
218 TUNSETDEBUG_val = TUNSETDEBUG,
219 #endif
220 #ifdef TUNSETPERSIST
221 TUNSETPERSIST_val = TUNSETPERSIST,
222 #endif
223 #ifdef TUNSETOWNER
224 TUNSETOWNER_val = TUNSETOWNER,
225 #endif
226 #ifdef TUNSETLINK
227 TUNSETLINK_val = TUNSETLINK,
228 #endif
229 #ifdef TUNSETGROUP
230 TUNSETGROUP_val = TUNSETGROUP,
231 #endif
232 #ifdef TUNGETFEATURES
233 TUNGETFEATURES_val = TUNGETFEATURES,
234 #endif
235 #ifdef TUNSETOFFLOAD
236 TUNSETOFFLOAD_val = TUNSETOFFLOAD,
237 #endif
238 #ifdef TUNSETTXFILTER
239 TUNSETTXFILTER_val = TUNSETTXFILTER,
240 #endif
241 #ifdef TUNGETIFF
242 TUNGETIFF_val = TUNGETIFF,
243 #endif
244 #ifdef TUNGETSNDBUF
245 TUNGETSNDBUF_val = TUNGETSNDBUF,
246 #endif
247 #ifdef TUNSETSNDBUF
248 TUNSETSNDBUF_val = TUNSETSNDBUF,
249 #endif
250 #ifdef TUNATTACHFILTER
251 TUNATTACHFILTER_val = TUNATTACHFILTER,
252 #endif
253 #ifdef TUNDETACHFILTER
254 TUNDETACHFILTER_val = TUNDETACHFILTER,
255 #endif
256 #ifdef TUNGETVNETHDRSZ
257 TUNGETVNETHDRSZ_val = TUNGETVNETHDRSZ,
258 #endif
259 #ifdef TUNSETVNETHDRSZ
260 TUNSETVNETHDRSZ_val = TUNSETVNETHDRSZ,
261 #endif
262 #ifdef TUNSETQUEUE
263 TUNSETQUEUE_val = TUNSETQUEUE,
264 #endif
265 #ifdef TUNSETIFINDEX
266 TUNSETIFINDEX_val = TUNSETIFINDEX,
267 #endif
268 #ifdef TUNGETFILTER
269 TUNGETFILTER_val = TUNGETFILTER,
270 #endif
271 #ifdef NLA_HDRLEN
272 NLA_HDRLEN_val = NLA_HDRLEN,
273 #endif
274
275 };
276 EOF
277
278 ${CC} -fdump-go-spec=gen-sysinfo.go -std=gnu99 -S -o sysinfo.s sysinfo.c
279
280 echo 'package syscall' > ${OUT}
281 echo 'import "unsafe"' >> ${OUT}
282 echo 'type _ unsafe.Pointer' >> ${OUT}
283
284 # Get all the consts and types, skipping ones which could not be
285 # represented in Go and ones which we need to rewrite. We also skip
286 # function declarations, as we don't need them here. All the symbols
287 # will all have a leading underscore.
288 grep -v '^// ' gen-sysinfo.go | \
289 grep -v '^func' | \
290 grep -v '^type _timeval ' | \
291 grep -v '^type _timespec_t ' | \
292 grep -v '^type _timespec ' | \
293 grep -v '^type _timestruc_t ' | \
294 grep -v '^type _epoll_' | \
295 grep -v 'in6_addr' | \
296 grep -v 'sockaddr_in6' | \
297 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
298 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
299 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
300 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
301 >> ${OUT}
302
303 # The errno constants. These get type Errno.
304 echo '#include <errno.h>' | ${CC} -x c - -E -dM | \
305 egrep '#define E[A-Z0-9_]+ ' | \
306 sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(_\1)/' >> ${OUT}
307
308 # The O_xxx flags.
309 egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
310 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
311 if ! grep '^const O_ASYNC' ${OUT} >/dev/null 2>&1; then
312 echo "const O_ASYNC = 0" >> ${OUT}
313 fi
314 if ! grep '^const O_CLOEXEC' ${OUT} >/dev/null 2>&1; then
315 echo "const O_CLOEXEC = 0" >> ${OUT}
316 fi
317
318 # The os package requires F_DUPFD_CLOEXEC to be defined.
319 if ! grep '^const F_DUPFD_CLOEXEC' ${OUT} >/dev/null 2>&1; then
320 echo "const F_DUPFD_CLOEXEC = 0" >> ${OUT}
321 fi
322
323 # These flags can be lost on i386 GNU/Linux when using
324 # -D_FILE_OFFSET_BITS=64, because we see "#define F_SETLK F_SETLK64"
325 # before we see the definition of F_SETLK64.
326 for flag in F_GETLK F_SETLK F_SETLKW; do
327 if ! grep "^const ${flag} " ${OUT} >/dev/null 2>&1 \
328 && grep "^const ${flag}64 " ${OUT} >/dev/null 2>&1; then
329 echo "const ${flag} = ${flag}64" >> ${OUT}
330 fi
331 done
332
333 # The Flock_t struct for fcntl.
334 grep '^type _flock ' gen-sysinfo.go | \
335 sed -e 's/type _flock/type Flock_t/' \
336 -e 's/l_type/Type/' \
337 -e 's/l_whence/Whence/' \
338 -e 's/l_start/Start/' \
339 -e 's/l_len/Len/' \
340 -e 's/l_pid/Pid/' \
341 >> ${OUT}
342
343 # The signal numbers.
344 grep '^const _SIG[^_]' gen-sysinfo.go | \
345 grep -v '^const _SIGEV_' | \
346 sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = Signal(_\2)/' >> ${OUT}
347 if ! grep '^const SIGPOLL ' ${OUT} >/dev/null 2>&1; then
348 if grep '^const SIGIO ' ${OUT} > /dev/null 2>&1; then
349 echo "const SIGPOLL = SIGIO" >> ${OUT}
350 fi
351 fi
352 if ! grep '^const SIGCLD ' ${OUT} >/dev/null 2>&1; then
353 if grep '^const SIGCHLD ' ${OUT} >/dev/null 2>&1; then
354 echo "const SIGCLD = SIGCHLD" >> ${OUT}
355 fi
356 fi
357
358 # The syscall numbers. We force the names to upper case.
359 grep '^const _SYS_' gen-sysinfo.go | \
360 sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \
361 while read sys; do
362 sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
363 echo "const $sup = _$sys" >> ${OUT}
364 done
365
366 # The GNU/Linux support wants to use SYS_GETDENTS64 if available.
367 if ! grep '^const SYS_GETDENTS ' ${OUT} >/dev/null 2>&1; then
368 echo "const SYS_GETDENTS = 0" >> ${OUT}
369 fi
370 if ! grep '^const SYS_GETDENTS64 ' ${OUT} >/dev/null 2>&1; then
371 echo "const SYS_GETDENTS64 = 0" >> ${OUT}
372 fi
373
374 # Stat constants.
375 grep '^const _S_' gen-sysinfo.go | \
376 sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
377
378 # Mmap constants.
379 grep '^const _PROT_' gen-sysinfo.go | \
380 sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
381 grep '^const _MAP_' gen-sysinfo.go | \
382 sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
383 grep '^const _MADV_' gen-sysinfo.go | \
384 sed -e 's/^\(const \)_\(MADV_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
385 grep '^const _MCL_' gen-sysinfo.go | \
386 sed -e 's/^\(const \)_\(MCL_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
387
388 # Process status constants.
389 grep '^const _W' gen-sysinfo.go |
390 sed -e 's/^\(const \)_\(W[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
391 # WSTOPPED was introduced in glibc 2.3.4.
392 if ! grep '^const _WSTOPPED = ' gen-sysinfo.go >/dev/null 2>&1; then
393 if grep '^const _WUNTRACED = ' gen-sysinfo.go > /dev/null 2>&1; then
394 echo 'const WSTOPPED = _WUNTRACED' >> ${OUT}
395 else
396 echo 'const WSTOPPED = 2' >> ${OUT}
397 fi
398 fi
399 if grep '^const ___WALL = ' gen-sysinfo.go >/dev/null 2>&1 \
400 && ! grep '^const _WALL = ' gen-sysinfo.go >/dev/null 2>&1; then
401 echo 'const WALL = ___WALL' >> ${OUT}
402 fi
403
404 # Networking constants.
405 egrep '^const _(AF|ARPHRD|ETH|IN|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
406 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
407 grep '^const _SOMAXCONN' gen-sysinfo.go |
408 sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
409 >> ${OUT}
410 grep '^const _SHUT_' gen-sysinfo.go |
411 sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
412
413 # The net package requires some const definitions.
414 for m in IP_PKTINFO IPV6_V6ONLY IPPROTO_IPV6 IPV6_JOIN_GROUP IPV6_LEAVE_GROUP IPV6_TCLASS SO_REUSEPORT; do
415 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
416 echo "const $m = 0" >> ${OUT}
417 fi
418 done
419 for m in SOCK_CLOEXEC SOCK_NONBLOCK; do
420 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
421 echo "const $m = -1" >> ${OUT}
422 fi
423 done
424
425 # The syscall package requires AF_LOCAL.
426 if ! grep '^const AF_LOCAL ' ${OUT} >/dev/null 2>&1; then
427 if grep '^const AF_UNIX ' ${OUT} >/dev/null 2>&1; then
428 echo "const AF_LOCAL = AF_UNIX" >> ${OUT}
429 fi
430 fi
431
432 # sysconf constants.
433 grep '^const __SC' gen-sysinfo.go |
434 sed -e 's/^\(const \)__\(SC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
435
436 # pathconf constants.
437 grep '^const __PC' gen-sysinfo.go |
438 sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
439
440 # The PATH_MAX constant.
441 if grep '^const _PATH_MAX ' gen-sysinfo.go >/dev/null 2>&1; then
442 echo 'const PathMax = _PATH_MAX' >> ${OUT}
443 fi
444
445 # epoll constants.
446 grep '^const _EPOLL' gen-sysinfo.go |
447 sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
448 # Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
449 if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
450 echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
451 fi
452 if ! grep '^const EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
453 echo "const EPOLL_CLOEXEC = 02000000" >> ${OUT}
454 fi
455
456 # Prctl constants.
457 grep '^const _PR_' gen-sysinfo.go |
458 sed -e 's/^\(const \)_\(PR_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
459
460 # Ptrace constants.
461 grep '^const _PTRACE' gen-sysinfo.go |
462 sed -e 's/^\(const \)_\(PTRACE[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
463 # We need some ptrace options that are not defined in older versions
464 # of glibc.
465 if ! grep '^const PTRACE_SETOPTIONS' ${OUT} > /dev/null 2>&1; then
466 echo "const PTRACE_SETOPTIONS = 0x4200" >> ${OUT}
467 fi
468 if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then
469 echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
470 fi
471 if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then
472 echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
473 fi
474 if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then
475 echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
476 fi
477 if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then
478 echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
479 fi
480 if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then
481 echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
482 fi
483 if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then
484 echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
485 fi
486 if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then
487 echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
488 fi
489 if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then
490 echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
491 fi
492 if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
493 echo "const PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
494 fi
495 if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
496 echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
497 fi
498 if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then
499 echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
500 fi
501 if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then
502 echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
503 fi
504 if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then
505 echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
506 fi
507 if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then
508 echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
509 fi
510 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
511 echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
512 fi
513 if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
514 echo "const _PTRACE_TRACEME = 0" >> ${OUT}
515 fi
516
517 # A helper function that prints a structure from gen-sysinfo.go with the first
518 # letter of the field names in upper case. $1 is the name of structure. If $2
519 # is not empty, the structure or type is renamed to $2.
520 upcase_fields () {
521 name="$1"
522 def=`grep "^type $name" gen-sysinfo.go`
523 fields=`echo $def | sed -e 's/^[^{]*{\(.*\)}$/\1/'`
524 prefix=`echo $def | sed -e 's/{.*//'`
525 if test "$2" != ""; then
526 prefix=`echo $prefix | sed -e "s/$1/$2/"`
527 fi
528 if test "$fields" != ""; then
529 nfields=
530 while test -n "$fields"; do
531 field=`echo $fields | sed -e 's/^\([^;]*\);.*$/\1/'`
532 fields=`echo $fields | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
533 # capitalize the next character.
534 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
535 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
536 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
537 field="$f$r"
538 nfields="$nfields $field;"
539 done
540 echo "${prefix} {$nfields }"
541 fi
542 }
543
544 # The registers returned by PTRACE_GETREGS. This is probably
545 # GNU/Linux specific; it should do no harm if there is no
546 # _user_regs_struct.
547 regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
548 if test "$regs" = ""; then
549 # s390
550 regs=`grep '^type __user_regs_struct struct' gen-sysinfo.go || true`
551 if test "$regs" != ""; then
552 # Substructures of __user_regs_struct on s390
553 upcase_fields "__user_psw_struct" "PtracePsw" >> ${OUT} || true
554 upcase_fields "__user_fpregs_struct" "PtraceFpregs" >> ${OUT} || true
555 upcase_fields "__user_per_struct" "PtracePer" >> ${OUT} || true
556 fi
557 fi
558 if test "$regs" != ""; then
559 regs=`echo $regs |
560 sed -e 's/type __*user_regs_struct struct //' -e 's/[{}]//g'`
561 regs=`echo $regs | sed -e s'/^ *//'`
562 nregs=
563 while test -n "$regs"; do
564 field=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
565 regs=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
566 # Capitalize the first character of the field.
567 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
568 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
569 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
570 field="$f$r"
571 field=`echo "$field" | sed \
572 -e 's/__user_psw_struct/PtracePsw/' \
573 -e 's/__user_fpregs_struct/PtraceFpregs/' \
574 -e 's/__user_per_struct/PtracePer/'`
575 nregs="$nregs $field;"
576 done
577 echo "type PtraceRegs struct {$nregs }" >> ${OUT}
578 fi
579
580 # Some basic types.
581 echo 'type Size_t _size_t' >> ${OUT}
582 echo "type Ssize_t _ssize_t" >> ${OUT}
583 if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then
584 echo "type Offset_t _off64_t" >> ${OUT}
585 else
586 echo "type Offset_t _off_t" >> ${OUT}
587 fi
588 echo "type Mode_t _mode_t" >> ${OUT}
589 echo "type Pid_t _pid_t" >> ${OUT}
590 echo "type Uid_t _uid_t" >> ${OUT}
591 echo "type Gid_t _gid_t" >> ${OUT}
592 echo "type Socklen_t _socklen_t" >> ${OUT}
593
594 # The C int type.
595 sizeof_int=`grep '^const ___SIZEOF_INT__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
596 if test "$sizeof_int" = "4"; then
597 echo "type _C_int int32" >> ${OUT}
598 echo "type _C_uint uint32" >> ${OUT}
599 elif test "$sizeof_int" = "8"; then
600 echo "type _C_int int64" >> ${OUT}
601 echo "type _C_uint uint64" >> ${OUT}
602 else
603 echo 1>&2 "mksysinfo.sh: could not determine size of int (got $sizeof_int)"
604 exit 1
605 fi
606
607 # The C long type, needed because that is the type that ptrace returns.
608 sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
609 if test "$sizeof_long" = "4"; then
610 echo "type _C_long int32" >> ${OUT}
611 elif test "$sizeof_long" = "8"; then
612 echo "type _C_long int64" >> ${OUT}
613 else
614 echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
615 exit 1
616 fi
617
618 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
619 # double is commented by -fdump-go-spec.
620 if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
621 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
622 fi
623 if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
624 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
625 fi
626
627 # The time_t type.
628 if grep '^type _time_t ' gen-sysinfo.go > /dev/null 2>&1; then
629 echo 'type Time_t _time_t' >> ${OUT}
630 fi
631
632 # The time structures need special handling: we need to name the
633 # types, so that we can cast integers to the right types when
634 # assigning to the structures.
635 timeval=`grep '^type _timeval ' gen-sysinfo.go`
636 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
637 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
638 echo "type Timeval_sec_t $timeval_sec" >> ${OUT}
639 echo "type Timeval_usec_t $timeval_usec" >> ${OUT}
640 echo $timeval | \
641 sed -e 's/type _timeval /type Timeval /' \
642 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
643 -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
644 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
645 if test "$timespec" = ""; then
646 # IRIX 6.5 has __timespec instead.
647 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
648 fi
649 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
650 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
651 echo "type Timespec_sec_t $timespec_sec" >> ${OUT}
652 echo "type Timespec_nsec_t $timespec_nsec" >> ${OUT}
653 echo $timespec | \
654 sed -e 's/^type ___timespec /type Timespec /' \
655 -e 's/^type _timespec /type Timespec /' \
656 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
657 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
658
659 timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
660 if test "$timestruc" != ""; then
661 timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
662 timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
663 echo "type Timestruc_sec_t $timestruc_sec" >> ${OUT}
664 echo "type Timestruc_nsec_t $timestruc_nsec" >> ${OUT}
665 echo $timestruc | \
666 sed -e 's/^type _timestruc_t /type Timestruc /' \
667 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
668 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
669 fi
670
671 # The tms struct.
672 grep '^type _tms ' gen-sysinfo.go | \
673 sed -e 's/type _tms/type Tms/' \
674 -e 's/tms_utime/Utime/' \
675 -e 's/tms_stime/Stime/' \
676 -e 's/tms_cutime/Cutime/' \
677 -e 's/tms_cstime/Cstime/' \
678 >> ${OUT}
679
680 # The stat type.
681 # Prefer largefile variant if available.
682 stat=`grep '^type _stat64 ' gen-sysinfo.go || true`
683 if test "$stat" != ""; then
684 grep '^type _stat64 ' gen-sysinfo.go
685 else
686 grep '^type _stat ' gen-sysinfo.go
687 fi | sed -e 's/type _stat64/type Stat_t/' \
688 -e 's/type _stat/type Stat_t/' \
689 -e 's/st_dev/Dev/' \
690 -e 's/st_ino/Ino/g' \
691 -e 's/st_nlink/Nlink/' \
692 -e 's/st_mode/Mode/' \
693 -e 's/st_uid/Uid/' \
694 -e 's/st_gid/Gid/' \
695 -e 's/st_rdev/Rdev/' \
696 -e 's/st_size/Size/' \
697 -e 's/st_blksize/Blksize/' \
698 -e 's/st_blocks/Blocks/' \
699 -e 's/st_atim/Atim/' \
700 -e 's/st_mtim/Mtim/' \
701 -e 's/st_ctim/Ctim/' \
702 -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
703 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
704 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
705 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
706 -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
707 >> ${OUT}
708
709 # The directory searching types.
710 # Prefer largefile variant if available.
711 dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true`
712 if test "$dirent" != ""; then
713 grep '^type _dirent64 ' gen-sysinfo.go
714 else
715 grep '^type _dirent ' gen-sysinfo.go
716 fi | sed -e 's/type _dirent64/type Dirent/' \
717 -e 's/type _dirent/type Dirent/' \
718 -e 's/d_name \[0+1\]/d_name [0+256]/' \
719 -e 's/d_name/Name/' \
720 -e 's/]int8/]byte/' \
721 -e 's/d_ino/Ino/' \
722 -e 's/d_off/Off/' \
723 -e 's/d_reclen/Reclen/' \
724 -e 's/d_type/Type/' \
725 >> ${OUT}
726 echo "type DIR _DIR" >> ${OUT}
727
728 # Values for d_type field in dirent.
729 grep '^const _DT_' gen-sysinfo.go |
730 sed -e 's/^\(const \)_\(DT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
731
732 # The rusage struct.
733 rusage=`grep '^type _rusage struct' gen-sysinfo.go`
734 if test "$rusage" != ""; then
735 # Remove anonymous unions from GNU/Linux <bits/resource.h>.
736 rusage=`echo $rusage | sed -e 's/Godump_[0-9][0-9]* struct {\([^}]*\)};/\1/g'`
737 rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
738 rusage=`echo $rusage | sed -e 's/^ *//'`
739 nrusage=
740 while test -n "$rusage"; do
741 field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
742 rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
743 # Drop the leading ru_, capitalize the next character.
744 field=`echo $field | sed -e 's/^ru_//'`
745 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
746 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
747 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
748 # Fix _timeval _timespec, and _timestruc_t.
749 r=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
750 r=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
751 r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
752 field="$f$r"
753 nrusage="$nrusage $field;"
754 done
755 echo "type Rusage struct {$nrusage }" >> ${OUT}
756 else
757 echo "type Rusage struct {}" >> ${OUT}
758 fi
759
760 # The RUSAGE constants.
761 grep '^const _RUSAGE_' gen-sysinfo.go | \
762 sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
763
764 # The utsname struct.
765 grep '^type _utsname ' gen-sysinfo.go | \
766 sed -e 's/_utsname/Utsname/' \
767 -e 's/sysname/Sysname/' \
768 -e 's/nodename/Nodename/' \
769 -e 's/release/Release/' \
770 -e 's/version/Version/' \
771 -e 's/machine/Machine/' \
772 -e 's/domainname/Domainname/' \
773 >> ${OUT}
774
775 # The iovec struct.
776 iovec=`grep '^type _iovec ' gen-sysinfo.go`
777 iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
778 echo "type Iovec_len_t $iovec_len" >> ${OUT}
779 echo $iovec | \
780 sed -e 's/_iovec/Iovec/' \
781 -e 's/iov_base/Base/' \
782 -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
783 >> ${OUT}
784
785 # The msghdr struct.
786 msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
787 msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
788 echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
789 echo $msghdr | \
790 sed -e 's/_msghdr/Msghdr/' \
791 -e 's/msg_name/Name/' \
792 -e 's/msg_namelen/Namelen/' \
793 -e 's/msg_iov/Iov/' \
794 -e 's/msg_iovlen/Iovlen/' \
795 -e 's/_iovec/Iovec/' \
796 -e 's/msg_control/Control/' \
797 -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
798 -e 's/msg_flags/Flags/' \
799 >> ${OUT}
800
801 # The MSG_ flags for Msghdr.
802 grep '^const _MSG_' gen-sysinfo.go | \
803 sed -e 's/^\(const \)_\(MSG_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
804
805 # The cmsghdr struct.
806 cmsghdr=`grep '^type _cmsghdr ' gen-sysinfo.go`
807 if test -n "$cmsghdr"; then
808 cmsghdr_len=`echo $cmsghdr | sed -n -e 's/^.*cmsg_len \([^ ]*\);.*$/\1/p'`
809 echo "type Cmsghdr_len_t $cmsghdr_len" >> ${OUT}
810 echo "$cmsghdr" | \
811 sed -e 's/_cmsghdr/Cmsghdr/' \
812 -e 's/cmsg_len *[a-zA-Z0-9_]*/Len Cmsghdr_len_t/' \
813 -e 's/cmsg_level/Level/' \
814 -e 's/cmsg_type/Type/' \
815 -e 's/\[\]/[0]/' \
816 >> ${OUT}
817 fi
818
819 # The SCM_ flags for Cmsghdr.
820 grep '^const _SCM_' gen-sysinfo.go | \
821 sed -e 's/^\(const \)_\(SCM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
822
823 # The ucred struct.
824 upcase_fields "_ucred" "Ucred" >> ${OUT} || true
825
826 # The ip_mreq struct.
827 grep '^type _ip_mreq ' gen-sysinfo.go | \
828 sed -e 's/_ip_mreq/IPMreq/' \
829 -e 's/imr_multiaddr/Multiaddr/' \
830 -e 's/imr_interface/Interface/' \
831 -e 's/_in_addr/[4]byte/g' \
832 >> ${OUT}
833
834 # We need IPMreq to compile the net package.
835 if ! grep 'type IPMreq ' ${OUT} >/dev/null 2>&1; then
836 echo 'type IPMreq struct { Multiaddr [4]byte; Interface [4]byte; }' >> ${OUT}
837 fi
838
839 # The ipv6_mreq struct.
840 grep '^type _ipv6_mreq ' gen-sysinfo.go | \
841 sed -e 's/_ipv6_mreq/IPv6Mreq/' \
842 -e 's/ipv6mr_multiaddr/Multiaddr/' \
843 -e 's/ipv6mr_interface/Interface/' \
844 -e 's/_in6_addr/[16]byte/' \
845 >> ${OUT}
846
847 # We need IPv6Mreq to compile the net package.
848 if ! grep 'type IPv6Mreq ' ${OUT} >/dev/null 2>&1; then
849 echo 'type IPv6Mreq struct { Multiaddr [16]byte; Interface uint32; }' >> ${OUT}
850 fi
851
852 # The ip_mreqn struct.
853 grep '^type _ip_mreqn ' gen-sysinfo.go | \
854 sed -e 's/_ip_mreqn/IPMreqn/' \
855 -e 's/imr_multiaddr/Multiaddr/' \
856 -e 's/imr_address/Address/' \
857 -e 's/imr_ifindex/Ifindex/' \
858 -e 's/_in_addr/[4]byte/g' \
859 >> ${OUT}
860
861 # We need IPMreq to compile the net package.
862 if ! grep 'type IPMreqn ' ${OUT} >/dev/null 2>&1; then
863 echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT}
864 fi
865
866 # The icmp6_filter struct.
867 grep '^type _icmp6_filter ' gen-sysinfo.go | \
868 sed -e 's/_icmp6_filter/ICMPv6Filter/' \
869 -e 's/data/Data/' \
870 -e 's/filt/Filt/' \
871 >> ${OUT}
872
873 # We need ICMPv6Filter to compile the syscall package.
874 if ! grep 'type ICMPv6Filter ' ${OUT} > /dev/null 2>&1; then
875 echo 'type ICMPv6Filter struct { Data [8]uint32 }' >> ${OUT}
876 fi
877
878 # The ip6_mtuinfo struct.
879 grep '^type _ip6_mtuinfo ' gen-sysinfo.go | \
880 sed -e 's/_ip6_mtuinfo/IPv6MTUInfo/' \
881 -e 's/ip6m_addr/Addr/' \
882 -e 's/_sockaddr_in6/RawSockaddrInet6/' \
883 -e 's/ip6m_mtu/Mtu/' \
884 >> ${OUT}
885
886 # Try to guess the type to use for fd_set.
887 fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
888 fds_bits_type="_C_long"
889 if test "$fd_set" != ""; then
890 fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
891 fi
892 echo "type fds_bits_type $fds_bits_type" >> ${OUT}
893
894 # The addrinfo struct.
895 grep '^type _addrinfo ' gen-sysinfo.go | \
896 sed -e 's/_addrinfo/Addrinfo/g' \
897 -e 's/ ai_/ Ai_/g' \
898 >> ${OUT}
899
900 # The addrinfo and nameinfo flags and errors.
901 grep '^const _AI_' gen-sysinfo.go | \
902 sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
903 grep '^const _EAI_' gen-sysinfo.go | \
904 sed -e 's/^\(const \)_\(EAI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
905 grep '^const _NI_' gen-sysinfo.go | \
906 sed -e 's/^\(const \)_\(NI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
907
908 # The passwd struct.
909 grep '^type _passwd ' gen-sysinfo.go | \
910 sed -e 's/_passwd/Passwd/' \
911 -e 's/ pw_/ Pw_/g' \
912 >> ${OUT}
913
914 # The group struct.
915 grep '^type _group ' gen-sysinfo.go | \
916 sed -e 's/_group/Group/' \
917 -e 's/ gr_/ Gr_/g' \
918 >> ${OUT}
919
920 # The ioctl flags for the controlling TTY.
921 grep '^const _TIOC' gen-sysinfo.go | \
922 grep -v '_val =' | \
923 sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
924 grep '^const _TUNSET' gen-sysinfo.go | \
925 grep -v '_val =' | \
926 sed -e 's/^\(const \)_\(TUNSET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
927 # We need TIOCGWINSZ.
928 if ! grep '^const TIOCGWINSZ' ${OUT} >/dev/null 2>&1; then
929 if grep '^const _TIOCGWINSZ_val' ${OUT} >/dev/null 2>&1; then
930 echo 'const TIOCGWINSZ = _TIOCGWINSZ_val' >> ${OUT}
931 fi
932 fi
933 if ! grep '^const TIOCSWINSZ' ${OUT} >/dev/null 2>&1; then
934 if grep '^const _TIOCSWINSZ_val' ${OUT} >/dev/null 2>&1; then
935 echo 'const TIOCSWINSZ = _TIOCSWINSZ_val' >> ${OUT}
936 fi
937 fi
938 if ! grep '^const TIOCNOTTY' ${OUT} >/dev/null 2>&1; then
939 if grep '^const _TIOCNOTTY_val' ${OUT} >/dev/null 2>&1; then
940 echo 'const TIOCNOTTY = _TIOCNOTTY_val' >> ${OUT}
941 fi
942 fi
943 if ! grep '^const TIOCSCTTY' ${OUT} >/dev/null 2>&1; then
944 if grep '^const _TIOCSCTTY_val' ${OUT} >/dev/null 2>&1; then
945 echo 'const TIOCSCTTY = _TIOCSCTTY_val' >> ${OUT}
946 fi
947 fi
948 if ! grep '^const TIOCGPGRP' ${OUT} >/dev/null 2>&1; then
949 if grep '^const _TIOCGPGRP_val' ${OUT} >/dev/null 2>&1; then
950 echo 'const TIOCGPGRP = _TIOCGPGRP_val' >> ${OUT}
951 fi
952 fi
953 if ! grep '^const TIOCSPGRP' ${OUT} >/dev/null 2>&1; then
954 if grep '^const _TIOCSPGRP_val' ${OUT} >/dev/null 2>&1; then
955 echo 'const TIOCSPGRP = _TIOCSPGRP_val' >> ${OUT}
956 fi
957 fi
958 if ! grep '^const TIOCGPTN' ${OUT} >/dev/null 2>&1; then
959 if grep '^const _TIOCGPTN_val' ${OUT} >/dev/null 2>&1; then
960 echo 'const TIOCGPTN = _TIOCGPTN_val' >> ${OUT}
961 fi
962 fi
963 if ! grep '^const TIOCSPTLCK' ${OUT} >/dev/null 2>&1; then
964 if grep '^const _TIOCSPTLCK_val' ${OUT} >/dev/null 2>&1; then
965 echo 'const TIOCSPTLCK = _TIOCSPTLCK_val' >> ${OUT}
966 fi
967 fi
968 if ! grep '^const TIOCGDEV' ${OUT} >/dev/null 2>&1; then
969 if grep '^const _TIOCGDEV_val' ${OUT} >/dev/null 2>&1; then
970 echo 'const TIOCGDEV = _TIOCGDEV_val' >> ${OUT}
971 fi
972 fi
973 if ! grep '^const TIOCSIG' ${OUT} >/dev/null 2>&1; then
974 if grep '^const _TIOCSIG_val' ${OUT} >/dev/null 2>&1; then
975 echo 'const TIOCSIG = _TIOCSIG_val' >> ${OUT}
976 fi
977 fi
978
979 if ! grep '^const TUNSETNOCSUM' ${OUT} >/dev/null 2>&1; then
980 if grep '^const _TUNSETNOCSUM_val' ${OUT} >/dev/null 2>&1; then
981 echo 'const TUNSETNOCSUM = _TUNSETNOCSUM_val' >> ${OUT}
982 fi
983 fi
984
985 if ! grep '^const TUNSETDEBUG' ${OUT} >/dev/null 2>&1; then
986 if grep '^const _TUNSETDEBUG_val' ${OUT} >/dev/null 2>&1; then
987 echo 'const TUNSETDEBUG = _TUNSETDEBUG_val' >> ${OUT}
988 fi
989 fi
990
991 if ! grep '^const TUNSETIFF' ${OUT} >/dev/null 2>&1; then
992 if grep '^const _TUNSETIFF_val' ${OUT} >/dev/null 2>&1; then
993 echo 'const TUNSETIFF = _TUNSETIFF_val' >> ${OUT}
994 fi
995 fi
996
997 if ! grep '^const TUNSETPERSIST' ${OUT} >/dev/null 2>&1; then
998 if grep '^const _TUNSETPERSIST_val' ${OUT} >/dev/null 2>&1; then
999 echo 'const TUNSETPERSIST = _TUNSETPERSIST_val' >> ${OUT}
1000 fi
1001 fi
1002
1003 if ! grep '^const TUNSETOWNER' ${OUT} >/dev/null 2>&1; then
1004 if grep '^const _TUNSETOWNER_val' ${OUT} >/dev/null 2>&1; then
1005 echo 'const TUNSETOWNER = _TUNSETOWNER_val' >> ${OUT}
1006 fi
1007 fi
1008
1009 if ! grep '^const TUNSETLINK' ${OUT} >/dev/null 2>&1; then
1010 if grep '^const _TUNSETLINK_val' ${OUT} >/dev/null 2>&1; then
1011 echo 'const TUNSETLINK = _TUNSETLINK_val' >> ${OUT}
1012 fi
1013 fi
1014
1015 if ! grep '^const TUNSETGROUP' ${OUT} >/dev/null 2>&1; then
1016 if grep '^const _TUNSETGROUP_val' ${OUT} >/dev/null 2>&1; then
1017 echo 'const TUNSETGROUP = _TUNSETGROUP_val' >> ${OUT}
1018 fi
1019 fi
1020
1021 if ! grep '^const TUNGETFEATURES' ${OUT} >/dev/null 2>&1; then
1022 if grep '^const _TUNGETFEATURES_val' ${OUT} >/dev/null 2>&1; then
1023 echo 'const TUNGETFEATURES = _TUNGETFEATURES_val' >> ${OUT}
1024 fi
1025 fi
1026
1027 if ! grep '^const TUNSETOFFLOAD' ${OUT} >/dev/null 2>&1; then
1028 if grep '^const _TUNSETOFFLOAD_val' ${OUT} >/dev/null 2>&1; then
1029 echo 'const TUNSETOFFLOAD = _TUNSETOFFLOAD_val' >> ${OUT}
1030 fi
1031 fi
1032
1033 if ! grep '^const TUNSETTXFILTER' ${OUT} >/dev/null 2>&1; then
1034 if grep '^const _TUNSETTXFILTER_val' ${OUT} >/dev/null 2>&1; then
1035 echo 'const TUNSETTXFILTER = _TUNSETTXFILTER_val' >> ${OUT}
1036 fi
1037 fi
1038
1039 if ! grep '^const TUNGETIFF' ${OUT} >/dev/null 2>&1; then
1040 if grep '^const _TUNGETIFF_val' ${OUT} >/dev/null 2>&1; then
1041 echo 'const TUNGETIFF = _TUNGETIFF_val' >> ${OUT}
1042 fi
1043 fi
1044
1045 if ! grep '^const TUNGETSNDBUF' ${OUT} >/dev/null 2>&1; then
1046 if grep '^const _TUNGETSNDBUF_val' ${OUT} >/dev/null 2>&1; then
1047 echo 'const TUNGETSNDBUF = _TUNGETSNDBUF_val' >> ${OUT}
1048 fi
1049 fi
1050
1051 if ! grep '^const TUNSETSNDBUF' ${OUT} >/dev/null 2>&1; then
1052 if grep '^const _TUNSETSNDBUF_val' ${OUT} >/dev/null 2>&1; then
1053 echo 'const TUNSETSNDBUF = _TUNSETSNDBUF_val' >> ${OUT}
1054 fi
1055 fi
1056
1057 if ! grep '^const TUNATTACHFILTER' ${OUT} >/dev/null 2>&1; then
1058 if grep '^const _TUNATTACHFILTER_val' ${OUT} >/dev/null 2>&1; then
1059 echo 'const TUNATTACHFILTER = _TUNATTACHFILTER_val' >> ${OUT}
1060 fi
1061 fi
1062
1063 if ! grep '^const TUNDETACHFILTER' ${OUT} >/dev/null 2>&1; then
1064 if grep '^const _TUNDETACHFILTER_val' ${OUT} >/dev/null 2>&1; then
1065 echo 'const TUNDETACHFILTER = _TUNDETACHFILTER_val' >> ${OUT}
1066 fi
1067 fi
1068
1069 if ! grep '^const TUNGETVNETHDRSZ' ${OUT} >/dev/null 2>&1; then
1070 if grep '^const _TUNGETVNETHDRSZ_val' ${OUT} >/dev/null 2>&1; then
1071 echo 'const TUNGETVNETHDRSZ = _TUNGETVNETHDRSZ_val' >> ${OUT}
1072 fi
1073 fi
1074
1075 if ! grep '^const TUNSETVNETHDRSZ' ${OUT} >/dev/null 2>&1; then
1076 if grep '^const _TUNSETVNETHDRSZ_val' ${OUT} >/dev/null 2>&1; then
1077 echo 'const TUNSETVNETHDRSZ = _TUNSETVNETHDRSZ_val' >> ${OUT}
1078 fi
1079 fi
1080
1081 if ! grep '^const TUNSETQUEUE' ${OUT} >/dev/null 2>&1; then
1082 if grep '^const _TUNSETQUEUE_val' ${OUT} >/dev/null 2>&1; then
1083 echo 'const TUNSETQUEUE = _TUNSETQUEUE_val' >> ${OUT}
1084 fi
1085 fi
1086
1087
1088 if ! grep '^const TUNSETIFINDEX' ${OUT} >/dev/null 2>&1; then
1089 if grep '^const _TUNSETIFINDEX_val' ${OUT} >/dev/null 2>&1; then
1090 echo 'const TUNSETIFINDEX = _TUNSETIFINDEX_val' >> ${OUT}
1091 fi
1092 fi
1093
1094 if ! grep '^const TUNGETFILTER' ${OUT} >/dev/null 2>&1; then
1095 if grep '^const _TUNGETFILTER_val' ${OUT} >/dev/null 2>&1; then
1096 echo 'const TUNGETFILTER = _TUNGETFILTER_val' >> ${OUT}
1097 fi
1098 fi
1099
1100 # The ioctl flags for terminal control
1101 grep '^const _TC[GS]ET' gen-sysinfo.go | grep -v _val | \
1102 sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1103 if ! grep '^const TCGETS' ${OUT} >/dev/null 2>&1; then
1104 if grep '^const _TCGETS_val' ${OUT} >/dev/null 2>&1; then
1105 echo 'const TCGETS = _TCGETS_val' >> ${OUT}
1106 fi
1107 fi
1108 if ! grep '^const TCSETS' ${OUT} >/dev/null 2>&1; then
1109 if grep '^const _TCSETS_val' ${OUT} >/dev/null 2>&1; then
1110 echo 'const TCSETS = _TCSETS_val' >> ${OUT}
1111 fi
1112 fi
1113
1114 # ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but
1115 # needs handling in syscalls.exec.go.
1116 if ! grep '^const _TIOCSCTTY ' gen-sysinfo.go >/dev/null 2>&1; then
1117 if grep '^const _TIOCNXCL ' gen-sysinfo.go >/dev/null 2>&1; then
1118 echo "const TIOCSCTTY = TIOCNXCL" >> ${OUT}
1119 fi
1120 fi
1121
1122 # The nlmsghdr struct.
1123 grep '^type _nlmsghdr ' gen-sysinfo.go | \
1124 sed -e 's/_nlmsghdr/NlMsghdr/' \
1125 -e 's/nlmsg_len/Len/' \
1126 -e 's/nlmsg_type/Type/' \
1127 -e 's/nlmsg_flags/Flags/' \
1128 -e 's/nlmsg_seq/Seq/' \
1129 -e 's/nlmsg_pid/Pid/' \
1130 >> ${OUT}
1131
1132 # The nlmsg flags and operators.
1133 grep '^const _NLM' gen-sysinfo.go | \
1134 sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1135
1136 # NLMSG_HDRLEN is defined as an expression using sizeof.
1137 if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev/null 2>&1; then
1138 if grep '^const _sizeof_nlmsghdr ' ${OUT} > /dev/null 2>&1; then
1139 echo 'const NLMSG_HDRLEN = (_sizeof_nlmsghdr + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1)' >> ${OUT}
1140 fi
1141 fi
1142
1143 # The rtmsg struct.
1144 grep '^type _rtmsg ' gen-sysinfo.go | \
1145 sed -e 's/_rtmsg/RtMsg/' \
1146 -e 's/rtm_family/Family/' \
1147 -e 's/rtm_dst_len/Dst_len/' \
1148 -e 's/rtm_src_len/Src_len/' \
1149 -e 's/rtm_tos/Tos/' \
1150 -e 's/rtm_table/Table/' \
1151 -e 's/rtm_protocol/Protocol/' \
1152 -e 's/rtm_scope/Scope/' \
1153 -e 's/rtm_type/Type/' \
1154 -e 's/rtm_flags/Flags/' \
1155 >> ${OUT}
1156
1157 # The rtgenmsg struct.
1158 grep '^type _rtgenmsg ' gen-sysinfo.go | \
1159 sed -e 's/_rtgenmsg/RtGenmsg/' \
1160 -e 's/rtgen_family/Family/' \
1161 >> ${OUT}
1162
1163 # The routing message flags.
1164 grep '^const _RT_' gen-sysinfo.go | \
1165 sed -e 's/^\(const \)_\(RT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1166 grep '^const _RTA' gen-sysinfo.go | \
1167 sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1168 grep '^const _RTF' gen-sysinfo.go | \
1169 sed -e 's/^\(const \)_\(RTF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1170 grep '^const _RTCF' gen-sysinfo.go | \
1171 sed -e 's/^\(const \)_\(RTCF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1172 grep '^const _RTM' gen-sysinfo.go | \
1173 sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1174 grep '^const _RTN' gen-sysinfo.go | \
1175 sed -e 's/^\(const \)_\(RTN[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1176 grep '^const _RTPROT' gen-sysinfo.go | \
1177 sed -e 's/^\(const \)_\(RTPROT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1178
1179 # The ifinfomsg struct.
1180 grep '^type _ifinfomsg ' gen-sysinfo.go | \
1181 sed -e 's/_ifinfomsg/IfInfomsg/' \
1182 -e 's/ifi_family/Family/' \
1183 -e 's/ifi_type/Type/' \
1184 -e 's/ifi_index/Index/' \
1185 -e 's/ifi_flags/Flags/' \
1186 -e 's/ifi_change/Change/' \
1187 >> ${OUT}
1188
1189 # The interface information types and flags.
1190 grep '^const _IFA' gen-sysinfo.go | \
1191 sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1192 grep '^const _IFLA' gen-sysinfo.go | \
1193 sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1194 grep '^const _IFF' gen-sysinfo.go | \
1195 sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1196 grep '^const _IFNAMSIZ' gen-sysinfo.go | \
1197 sed -e 's/^\(const \)_\(IFNAMSIZ[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1198 grep '^const _SIOC' gen-sysinfo.go |
1199 sed -e 's/^\(const \)_\(SIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1200
1201 # The ifaddrmsg struct.
1202 grep '^type _ifaddrmsg ' gen-sysinfo.go | \
1203 sed -e 's/_ifaddrmsg/IfAddrmsg/' \
1204 -e 's/ifa_family/Family/' \
1205 -e 's/ifa_prefixlen/Prefixlen/' \
1206 -e 's/ifa_flags/Flags/' \
1207 -e 's/ifa_scope/Scope/' \
1208 -e 's/ifa_index/Index/' \
1209 >> ${OUT}
1210
1211 # The rtattr struct.
1212 grep '^type _rtattr ' gen-sysinfo.go | \
1213 sed -e 's/_rtattr/RtAttr/' \
1214 -e 's/rta_len/Len/' \
1215 -e 's/rta_type/Type/' \
1216 >> ${OUT}
1217
1218 # The in_pktinfo struct.
1219 grep '^type _in_pktinfo ' gen-sysinfo.go | \
1220 sed -e 's/_in_pktinfo/Inet4Pktinfo/' \
1221 -e 's/ipi_ifindex/Ifindex/' \
1222 -e 's/ipi_spec_dst/Spec_dst/' \
1223 -e 's/ipi_addr/Addr/' \
1224 -e 's/_in_addr/[4]byte/g' \
1225 >> ${OUT}
1226
1227 # The in6_pktinfo struct.
1228 grep '^type _in6_pktinfo ' gen-sysinfo.go | \
1229 sed -e 's/_in6_pktinfo/Inet6Pktinfo/' \
1230 -e 's/ipi6_addr/Addr/' \
1231 -e 's/ipi6_ifindex/Ifindex/' \
1232 -e 's/_in6_addr/[16]byte/' \
1233 >> ${OUT}
1234
1235 # The termios struct.
1236 grep '^type _termios ' gen-sysinfo.go | \
1237 sed -e 's/_termios/Termios/' \
1238 -e 's/c_iflag/Iflag/' \
1239 -e 's/c_oflag/Oflag/' \
1240 -e 's/c_cflag/Cflag/' \
1241 -e 's/c_lflag/Lflag/' \
1242 -e 's/c_line/Line/' \
1243 -e 's/c_cc/Cc/' \
1244 -e 's/c_ispeed/Ispeed/' \
1245 -e 's/c_ospeed/Ospeed/' \
1246 >> ${OUT}
1247
1248 # The termios constants.
1249 for n in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \
1250 IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \
1251 OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 CS5 CS6 CS7 CS8 TABDLY \
1252 BSDLY VTDLY FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL \
1253 CLOCAL LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE ECHO ECHOE ECHOK \
1254 ECHONL ECHOCTL ECHOPRT ECHOKE DEFECHO FLUSHO NOFLSH TOSTOP PENDIN IEXTEN \
1255 VINTR VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 VSWTCH VSTART VSTOP \
1256 VSUSP VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS TCSANOW TCSADRAIN \
1257 TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON TCIOFF TCION B0 B50 \
1258 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 \
1259 B38400 B57600 B115200 B230400 B460800 B500000 B576000 B921600 B1000000 \
1260 B1152000 B1500000 B2000000 B2500000 B3000000 B3500000 B4000000; do
1261
1262 grep "^const _$n " gen-sysinfo.go | \
1263 sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1264 done
1265
1266 # The mount flags
1267 grep '^const _MNT_' gen-sysinfo.go |
1268 sed -e 's/^\(const \)_\(MNT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1269 grep '^const _MS_' gen-sysinfo.go |
1270 sed -e 's/^\(const \)_\(MS_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1271
1272 # The fallocate flags.
1273 grep '^const _FALLOC_' gen-sysinfo.go |
1274 sed -e 's/^\(const \)_\(FALLOC_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1275
1276 # The statfs struct.
1277 # Prefer largefile variant if available.
1278 statfs=`grep '^type _statfs64 ' gen-sysinfo.go || true`
1279 if test "$statfs" != ""; then
1280 grep '^type _statfs64 ' gen-sysinfo.go
1281 else
1282 grep '^type _statfs ' gen-sysinfo.go
1283 fi | sed -e 's/type _statfs64/type Statfs_t/' \
1284 -e 's/type _statfs/type Statfs_t/' \
1285 -e 's/f_type/Type/' \
1286 -e 's/f_bsize/Bsize/' \
1287 -e 's/f_blocks/Blocks/' \
1288 -e 's/f_bfree/Bfree/' \
1289 -e 's/f_bavail/Bavail/' \
1290 -e 's/f_files/Files/' \
1291 -e 's/f_ffree/Ffree/' \
1292 -e 's/f_fsid/Fsid/' \
1293 -e 's/f_namelen/Namelen/' \
1294 -e 's/f_frsize/Frsize/' \
1295 -e 's/f_flags/Flags/' \
1296 -e 's/f_spare/Spare/' \
1297 >> ${OUT}
1298
1299 # The timex struct.
1300 timex=`grep '^type _timex ' gen-sysinfo.go || true`
1301 if test "$timex" = ""; then
1302 timex=`grep '^// type _timex ' gen-sysinfo.go || true`
1303 if test "$timex" != ""; then
1304 timex=`echo $timex | sed -e 's|// ||' -e 's/INVALID-bit-field/int32/g'`
1305 fi
1306 fi
1307 if test "$timex" != ""; then
1308 echo "$timex" | \
1309 sed -e 's/_timex/Timex/' \
1310 -e 's/modes/Modes/' \
1311 -e 's/offset/Offset/' \
1312 -e 's/freq/Freq/' \
1313 -e 's/maxerror/Maxerror/' \
1314 -e 's/esterror/Esterror/' \
1315 -e 's/status/Status/' \
1316 -e 's/constant/Constant/' \
1317 -e 's/precision/Precision/' \
1318 -e 's/tolerance/Tolerance/' \
1319 -e 's/ time / Time /' \
1320 -e 's/tick/Tick/' \
1321 -e 's/ppsfreq/Ppsfreq/' \
1322 -e 's/jitter/Jitter/' \
1323 -e 's/shift/Shift/' \
1324 -e 's/stabil/Stabil/' \
1325 -e 's/jitcnt/Jitcnt/' \
1326 -e 's/calcnt/Calcnt/' \
1327 -e 's/errcnt/Errcnt/' \
1328 -e 's/stbcnt/Stbcnt/' \
1329 -e 's/tai/Tai/' \
1330 -e 's/_timeval/Timeval/' \
1331 >> ${OUT}
1332 fi
1333
1334 # The rlimit struct.
1335 grep '^type _rlimit ' gen-sysinfo.go | \
1336 sed -e 's/_rlimit/Rlimit/' \
1337 -e 's/rlim_cur/Cur/' \
1338 -e 's/rlim_max/Max/' \
1339 >> ${OUT}
1340
1341 # The RLIMIT constants.
1342 grep '^const _RLIMIT_' gen-sysinfo.go |
1343 sed -e 's/^\(const \)_\(RLIMIT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1344 grep '^const _RLIM_' gen-sysinfo.go |
1345 sed -e 's/^\(const \)_\(RLIM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1346
1347 # The sysinfo struct.
1348 grep '^type _sysinfo ' gen-sysinfo.go | \
1349 sed -e 's/_sysinfo/Sysinfo_t/' \
1350 -e 's/uptime/Uptime/' \
1351 -e 's/loads/Loads/' \
1352 -e 's/totalram/Totalram/' \
1353 -e 's/freeram/Freeram/' \
1354 -e 's/sharedram/Sharedram/' \
1355 -e 's/bufferram/Bufferram/' \
1356 -e 's/totalswap/Totalswap/' \
1357 -e 's/freeswap/Freeswap/' \
1358 -e 's/procs/Procs/' \
1359 -e 's/totalhigh/Totalhigh/' \
1360 -e 's/freehigh/Freehigh/' \
1361 -e 's/mem_unit/Unit/' \
1362 >> ${OUT}
1363
1364 # The ustat struct.
1365 grep '^type _ustat ' gen-sysinfo.go | \
1366 sed -e 's/_ustat/Ustat_t/' \
1367 -e 's/f_tfree/Tfree/' \
1368 -e 's/f_tinode/Tinoe/' \
1369 -e 's/f_fname/Fname/' \
1370 -e 's/f_fpack/Fpack/' \
1371 >> ${OUT}
1372 # Force it to be defined, as on some older GNU/Linux systems the
1373 # header file fails when using with <linux/filter.h>.
1374 if ! grep 'type _ustat ' gen-sysinfo.go >/dev/null 2>&1; then
1375 echo 'type Ustat_t struct { Tfree int32; Tinoe uint64; Fname [5+1]int8; Fpack [5+1]int8; }' >> ${OUT}
1376 fi
1377
1378 # The utimbuf struct.
1379 grep '^type _utimbuf ' gen-sysinfo.go | \
1380 sed -e 's/_utimbuf/Utimbuf/' \
1381 -e 's/actime/Actime/' \
1382 -e 's/modtime/Modtime/' \
1383 >> ${OUT}
1384
1385 # The LOCK flags for flock.
1386 grep '^const _LOCK_' gen-sysinfo.go |
1387 sed -e 's/^\(const \)_\(LOCK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1388
1389 # The PRIO constants.
1390 grep '^const _PRIO_' gen-sysinfo.go | \
1391 sed -e 's/^\(const \)_\(PRIO_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1392
1393 # The GNU/Linux LINUX_REBOOT flags.
1394 grep '^const _LINUX_REBOOT_' gen-sysinfo.go |
1395 sed -e 's/^\(const \)_\(LINUX_REBOOT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1396
1397 # The GNU/Linux sock_filter struct.
1398 grep '^type _sock_filter ' gen-sysinfo.go | \
1399 sed -e 's/_sock_filter/SockFilter/' \
1400 -e 's/code/Code/' \
1401 -e 's/jt/Jt/' \
1402 -e 's/jf/Jf/' \
1403 -e 's/k /K /' \
1404 >> ${OUT}
1405
1406 # The GNU/Linux sock_fprog struct.
1407 grep '^type _sock_fprog ' gen-sysinfo.go | \
1408 sed -e 's/_sock_fprog/SockFprog/' \
1409 -e 's/len/Len/' \
1410 -e 's/filter/Filter/' \
1411 -e 's/_sock_filter/SockFilter/' \
1412 >> ${OUT}
1413
1414 # The GNU/Linux filter flags.
1415 grep '^const _BPF_' gen-sysinfo.go | \
1416 sed -e 's/^\(const \)_\(BPF_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1417
1418 # The GNU/Linux nlattr struct.
1419 grep '^type _nlattr ' gen-sysinfo.go | \
1420 sed -e 's/_nlattr/NlAttr/' \
1421 -e 's/nla_len/Len/' \
1422 -e 's/nla_type/Type/' \
1423 >> ${OUT}
1424
1425 # The GNU/Linux nlmsgerr struct.
1426 grep '^type _nlmsgerr ' gen-sysinfo.go | \
1427 sed -e 's/_nlmsgerr/NlMsgerr/' \
1428 -e 's/error/Error/' \
1429 -e 's/msg/Msg/' \
1430 -e 's/_nlmsghdr/NlMsghdr/' \
1431 >> ${OUT}
1432
1433 # The GNU/Linux rtnexthop struct.
1434 grep '^type _rtnexthop ' gen-sysinfo.go | \
1435 sed -e 's/_rtnexthop/RtNexthop/' \
1436 -e 's/rtnh_len/Len/' \
1437 -e 's/rtnh_flags/Flags/' \
1438 -e 's/rtnh_hops/Hops/' \
1439 -e 's/rtnh_ifindex/Ifindex/' \
1440 >> ${OUT}
1441
1442 # The GNU/Linux netlink flags.
1443 grep '^const _NETLINK_' gen-sysinfo.go | \
1444 sed -e 's/^\(const \)_\(NETLINK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1445 grep '^const _NLA_' gen-sysinfo.go | grep -v '_val =' | \
1446 sed -e 's/^\(const \)_\(NLA_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1447
1448 if ! grep '^const NLA_HDRLEN' ${OUT} >/dev/null 2>&1; then
1449 if grep '^const _NLA_HDRLEN_val' ${OUT} >/dev/null 2>&1; then
1450 echo 'const NLA_HDRLEN = _NLA_HDRLEN_val' >> ${OUT}
1451 fi
1452 fi
1453
1454 # The GNU/Linux packet socket flags.
1455 grep '^const _PACKET_' gen-sysinfo.go | \
1456 sed -e 's/^\(const \)_\(PACKET_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1457
1458 # The GNU/Linux inotify_event struct.
1459 grep '^type _inotify_event ' gen-sysinfo.go | \
1460 sed -e 's/_inotify_event/InotifyEvent/' \
1461 -e 's/wd/Wd/' \
1462 -e 's/mask/Mask/' \
1463 -e 's/cookie/Cookie/' \
1464 -e 's/len/Len/' \
1465 -e 's/name/Name/' \
1466 -e 's/\[\]/[0]/' \
1467 -e 's/\[0\]byte/[0]int8/' \
1468 >> ${OUT}
1469
1470 # The GNU/Linux CLONE flags.
1471 grep '^const _CLONE_' gen-sysinfo.go | \
1472 sed -e 's/^\(const \)_\(CLONE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1473 # We need some CLONE constants that are not defined in older versions
1474 # of glibc.
1475 if ! grep '^const CLONE_NEWUSER ' ${OUT} > /dev/null 2>&1; then
1476 echo "const CLONE_NEWUSER = 0x10000000" >> ${OUT}
1477 fi
1478 if ! grep '^const CLONE_NEWNET ' ${OUT} > /dev/null 2>&1; then
1479 echo "const CLONE_NEWNET = 0x40000000" >> ${OUT}
1480 fi
1481
1482 # Struct sizes.
1483 set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \
1484 ifaddrmsg IfAddrmsg ifinfomsg IfInfomsg in_pktinfo Inet4Pktinfo \
1485 in6_pktinfo Inet6Pktinfo inotify_event InotifyEvent linger Linger \
1486 msghdr Msghdr nlattr NlAttr nlmsgerr NlMsgerr nlmsghdr NlMsghdr \
1487 rtattr RtAttr rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \
1488 sock_filter SockFilter sock_fprog SockFprog ucred Ucred \
1489 icmp6_filter ICMPv6Filter ip6_mtuinfo IPv6MTUInfo
1490 while test $# != 0; do
1491 nc=$1
1492 ngo=$2
1493 shift
1494 shift
1495 if grep "^const _sizeof_$nc =" gen-sysinfo.go >/dev/null 2>&1; then
1496 echo "const Sizeof$ngo = _sizeof_$nc" >> ${OUT}
1497 fi
1498 done
1499
1500 # In order to compile the net package, we need some sizes to exist
1501 # even if the types do not.
1502 if ! grep 'const SizeofIPMreq ' ${OUT} >/dev/null 2>&1; then
1503 echo 'const SizeofIPMreq = 8' >> ${OUT}
1504 fi
1505 if ! grep 'const SizeofIPv6Mreq ' ${OUT} >/dev/null 2>&1; then
1506 echo 'const SizeofIPv6Mreq = 20' >> ${OUT}
1507 fi
1508 if ! grep 'const SizeofIPMreqn ' ${OUT} >/dev/null 2>&1; then
1509 echo 'const SizeofIPMreqn = 12' >> ${OUT}
1510 fi
1511 if ! grep 'const SizeofICMPv6Filter ' ${OUT} >/dev/null 2>&1; then
1512 echo 'const SizeofICMPv6Filter = 32' >> ${OUT}
1513 fi
1514
1515 # The Solaris 11 Update 1 _zone_net_addr_t struct.
1516 grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
1517 sed -e 's/_in6_addr/[16]byte/' \
1518 >> ${OUT}
1519
1520 # The Solaris 12 _flow_arp_desc_t struct.
1521 grep '^type _flow_arp_desc_t ' gen-sysinfo.go | \
1522 sed -e 's/_in6_addr_t/[16]byte/g' \
1523 >> ${OUT}
1524
1525 # The Solaris 12 _flow_l3_desc_t struct.
1526 grep '^type _flow_l3_desc_t ' gen-sysinfo.go | \
1527 sed -e 's/_in6_addr_t/[16]byte/g' \
1528 >> ${OUT}
1529
1530 # The Solaris 12 _mac_ipaddr_t struct.
1531 grep '^type _mac_ipaddr_t ' gen-sysinfo.go | \
1532 sed -e 's/_in6_addr_t/[16]byte/g' \
1533 >> ${OUT}
1534
1535 # The Solaris 12 _mactun_info_t struct.
1536 grep '^type _mactun_info_t ' gen-sysinfo.go | \
1537 sed -e 's/_in6_addr_t/[16]byte/g' \
1538 >> ${OUT}
1539
1540 exit $?