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