OSDN Git Service

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