runtime: copy Go 1.7 runtime semaphore code
[official-gcc.git] / libgo / mksysinfo.sh
blobf79b5cfd7d8491e88edebd7f2526482be75862da
1 #!/bin/sh
3 # Copyright 2009 The Go Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style
5 # license that can be found in the LICENSE file.
7 # Create sysinfo.go from gen-sysinfo.go and errno.i.
9 # This shell script creates the sysinfo.go file which holds types and
10 # constants extracted from the system header files. This reads the
11 # raw data from gen-sysinfo.go which is generated using the
12 # -fdump-go-spec option.
14 # This currently exposes some names that ideally should not be
15 # exposed, as they match grep patterns. E.g., WCHAR_MIN gets exposed
16 # because it starts with W, like the wait flags.
18 OUT=tmp-sysinfo.go
20 set -e
22 echo 'package syscall' > ${OUT}
23 echo 'import "unsafe"' >> ${OUT}
24 echo 'type _ unsafe.Pointer' >> ${OUT}
26 # Get all the consts and types, skipping ones which could not be
27 # represented in Go and ones which we need to rewrite. We also skip
28 # function declarations, as we don't need them here. All the symbols
29 # will all have a leading underscore.
30 grep -v '^// ' gen-sysinfo.go | \
31 grep -v '^func' | \
32 grep -v '^type _timeval ' | \
33 grep -v '^type _timespec_t ' | \
34 grep -v '^type _timespec ' | \
35 grep -v '^type _timestruc_t ' | \
36 grep -v '^type _epoll_' | \
37 grep -v 'in6_addr' | \
38 grep -v 'sockaddr_in6' | \
39 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
40 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
41 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
42 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
43 >> ${OUT}
45 # The errno constants. These get type Errno.
46 egrep '#define E[A-Z0-9_]+ ' errno.i | \
47 sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(_\1)/' >> ${OUT}
49 # The O_xxx flags.
50 egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
51 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
52 if ! grep '^const O_ASYNC' ${OUT} >/dev/null 2>&1; then
53 echo "const O_ASYNC = 0" >> ${OUT}
55 if ! grep '^const O_CLOEXEC' ${OUT} >/dev/null 2>&1; then
56 echo "const O_CLOEXEC = 0" >> ${OUT}
59 # The os package requires F_DUPFD_CLOEXEC to be defined.
60 if ! grep '^const F_DUPFD_CLOEXEC' ${OUT} >/dev/null 2>&1; then
61 echo "const F_DUPFD_CLOEXEC = 0" >> ${OUT}
64 # These flags can be lost on i386 GNU/Linux when using
65 # -D_FILE_OFFSET_BITS=64, because we see "#define F_SETLK F_SETLK64"
66 # before we see the definition of F_SETLK64.
67 for flag in F_GETLK F_SETLK F_SETLKW; do
68 if ! grep "^const ${flag} " ${OUT} >/dev/null 2>&1 \
69 && grep "^const ${flag}64 " ${OUT} >/dev/null 2>&1; then
70 echo "const ${flag} = ${flag}64" >> ${OUT}
72 done
74 # The Flock_t struct for fcntl.
75 grep '^type _flock ' gen-sysinfo.go | \
76 sed -e 's/type _flock/type Flock_t/' \
77 -e 's/l_type/Type/' \
78 -e 's/l_whence/Whence/' \
79 -e 's/l_start/Start/' \
80 -e 's/l_len/Len/' \
81 -e 's/l_pid/Pid/' \
82 >> ${OUT}
84 # The signal numbers.
85 grep '^const _SIG[^_]' gen-sysinfo.go | \
86 grep -v '^const _SIGEV_' | \
87 sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = Signal(_\2)/' >> ${OUT}
88 if ! grep '^const SIGPOLL ' ${OUT} >/dev/null 2>&1; then
89 if grep '^const SIGIO ' ${OUT} > /dev/null 2>&1; then
90 echo "const SIGPOLL = SIGIO" >> ${OUT}
93 if ! grep '^const SIGCLD ' ${OUT} >/dev/null 2>&1; then
94 if grep '^const SIGCHLD ' ${OUT} >/dev/null 2>&1; then
95 echo "const SIGCLD = SIGCHLD" >> ${OUT}
99 # The syscall numbers. We force the names to upper case.
100 grep '^const _SYS_' gen-sysinfo.go | \
101 sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \
102 while read sys; do
103 sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
104 echo "const $sup = _$sys" >> ${OUT}
105 done
107 # The GNU/Linux support wants to use SYS_GETDENTS64 if available.
108 if ! grep '^const SYS_GETDENTS ' ${OUT} >/dev/null 2>&1; then
109 echo "const SYS_GETDENTS = 0" >> ${OUT}
111 if ! grep '^const SYS_GETDENTS64 ' ${OUT} >/dev/null 2>&1; then
112 echo "const SYS_GETDENTS64 = 0" >> ${OUT}
115 # Stat constants.
116 grep '^const _S_' gen-sysinfo.go | \
117 sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
119 # Mmap constants.
120 grep '^const _PROT_' gen-sysinfo.go | \
121 sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
122 grep '^const _MAP_' gen-sysinfo.go | \
123 sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
124 grep '^const _MADV_' gen-sysinfo.go | \
125 sed -e 's/^\(const \)_\(MADV_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
126 grep '^const _MCL_' gen-sysinfo.go | \
127 sed -e 's/^\(const \)_\(MCL_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
129 # Process status constants.
130 grep '^const _W' gen-sysinfo.go |
131 sed -e 's/^\(const \)_\(W[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
132 # WSTOPPED was introduced in glibc 2.3.4.
133 if ! grep '^const _WSTOPPED = ' gen-sysinfo.go >/dev/null 2>&1; then
134 if grep '^const _WUNTRACED = ' gen-sysinfo.go > /dev/null 2>&1; then
135 echo 'const WSTOPPED = _WUNTRACED' >> ${OUT}
136 else
137 echo 'const WSTOPPED = 2' >> ${OUT}
140 if grep '^const ___WALL = ' gen-sysinfo.go >/dev/null 2>&1 \
141 && ! grep '^const _WALL = ' gen-sysinfo.go >/dev/null 2>&1; then
142 echo 'const WALL = ___WALL' >> ${OUT}
145 # Networking constants.
146 egrep '^const _(AF|ARPHRD|ETH|IN|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
147 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
148 grep '^const _SOMAXCONN' gen-sysinfo.go |
149 sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
150 >> ${OUT}
151 grep '^const _SHUT_' gen-sysinfo.go |
152 sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
154 # The net package requires some const definitions.
155 for m in IP_PKTINFO IPV6_V6ONLY IPPROTO_IPV6 IPV6_JOIN_GROUP IPV6_LEAVE_GROUP IPV6_TCLASS SO_REUSEPORT; do
156 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
157 echo "const $m = 0" >> ${OUT}
159 done
160 for m in SOCK_CLOEXEC SOCK_NONBLOCK; do
161 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
162 echo "const $m = -1" >> ${OUT}
164 done
166 # The syscall package requires AF_LOCAL.
167 if ! grep '^const AF_LOCAL ' ${OUT} >/dev/null 2>&1; then
168 if grep '^const AF_UNIX ' ${OUT} >/dev/null 2>&1; then
169 echo "const AF_LOCAL = AF_UNIX" >> ${OUT}
173 # sysconf constants.
174 grep '^const __SC' gen-sysinfo.go |
175 sed -e 's/^\(const \)__\(SC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
177 # pathconf constants.
178 grep '^const __PC' gen-sysinfo.go |
179 sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
181 # The PATH_MAX constant.
182 if grep '^const _PATH_MAX ' gen-sysinfo.go >/dev/null 2>&1; then
183 echo 'const PathMax = _PATH_MAX' >> ${OUT}
186 # epoll constants.
187 grep '^const _EPOLL' gen-sysinfo.go |
188 sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
189 # Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
190 if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
191 echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
193 if ! grep '^const EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
194 echo "const EPOLL_CLOEXEC = 02000000" >> ${OUT}
197 # Prctl constants.
198 grep '^const _PR_' gen-sysinfo.go |
199 sed -e 's/^\(const \)_\(PR_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
201 # Ptrace constants.
202 grep '^const _PTRACE' gen-sysinfo.go |
203 sed -e 's/^\(const \)_\(PTRACE[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
204 # We need some ptrace options that are not defined in older versions
205 # of glibc.
206 if ! grep '^const PTRACE_SETOPTIONS' ${OUT} > /dev/null 2>&1; then
207 echo "const PTRACE_SETOPTIONS = 0x4200" >> ${OUT}
209 if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then
210 echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
212 if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then
213 echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
215 if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then
216 echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
218 if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then
219 echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
221 if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then
222 echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
224 if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then
225 echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
227 if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then
228 echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
230 if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then
231 echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
233 if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
234 echo "const PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
236 if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
237 echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
239 if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then
240 echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
242 if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then
243 echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
245 if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then
246 echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
248 if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then
249 echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
251 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
252 echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
254 if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
255 echo "const _PTRACE_TRACEME = 0" >> ${OUT}
258 # A helper function that prints a structure from gen-sysinfo.go with the first
259 # letter of the field names in upper case. $1 is the name of structure. If $2
260 # is not empty, the structure or type is renamed to $2.
261 upcase_fields () {
262 name="$1"
263 def=`grep "^type $name" gen-sysinfo.go`
264 fields=`echo $def | sed -e 's/^[^{]*{\(.*\)}$/\1/'`
265 prefix=`echo $def | sed -e 's/{.*//'`
266 if test "$2" != ""; then
267 prefix=`echo $prefix | sed -e "s/$1/$2/"`
269 if test "$fields" != ""; then
270 nfields=
271 while test -n "$fields"; do
272 field=`echo $fields | sed -e 's/^\([^;]*\);.*$/\1/'`
273 fields=`echo $fields | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
274 # capitalize the next character.
275 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
276 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
277 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
278 field="$f$r"
279 nfields="$nfields $field;"
280 done
281 echo "${prefix} {$nfields }"
285 # The registers returned by PTRACE_GETREGS. This is probably
286 # GNU/Linux specific; it should do no harm if there is no
287 # _user_regs_struct.
288 regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
289 if test "$regs" = ""; then
290 # s390
291 regs=`grep '^type __user_regs_struct struct' gen-sysinfo.go || true`
292 if test "$regs" != ""; then
293 # Substructures of __user_regs_struct on s390
294 upcase_fields "__user_psw_struct" "PtracePsw" >> ${OUT} || true
295 upcase_fields "__user_fpregs_struct" "PtraceFpregs" >> ${OUT} || true
296 upcase_fields "__user_per_struct" "PtracePer" >> ${OUT} || true
299 if test "$regs" != ""; then
300 regs=`echo $regs |
301 sed -e 's/type __*user_regs_struct struct //' -e 's/[{}]//g'`
302 regs=`echo $regs | sed -e s'/^ *//'`
303 nregs=
304 while test -n "$regs"; do
305 field=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
306 regs=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
307 # Capitalize the first character of the field.
308 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
309 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
310 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
311 field="$f$r"
312 field=`echo "$field" | sed \
313 -e 's/__user_psw_struct/PtracePsw/' \
314 -e 's/__user_fpregs_struct/PtraceFpregs/' \
315 -e 's/__user_per_struct/PtracePer/'`
316 nregs="$nregs $field;"
317 done
318 echo "type PtraceRegs struct {$nregs }" >> ${OUT}
321 # Some basic types.
322 echo 'type Size_t _size_t' >> ${OUT}
323 echo "type Ssize_t _ssize_t" >> ${OUT}
324 if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then
325 echo "type Offset_t _off64_t" >> ${OUT}
326 else
327 echo "type Offset_t _off_t" >> ${OUT}
329 echo "type Mode_t _mode_t" >> ${OUT}
330 echo "type Pid_t _pid_t" >> ${OUT}
331 echo "type Uid_t _uid_t" >> ${OUT}
332 echo "type Gid_t _gid_t" >> ${OUT}
333 echo "type Socklen_t _socklen_t" >> ${OUT}
335 # The C int type.
336 sizeof_int=`grep '^const ___SIZEOF_INT__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
337 if test "$sizeof_int" = "4"; then
338 echo "type _C_int int32" >> ${OUT}
339 echo "type _C_uint uint32" >> ${OUT}
340 elif test "$sizeof_int" = "8"; then
341 echo "type _C_int int64" >> ${OUT}
342 echo "type _C_uint uint64" >> ${OUT}
343 else
344 echo 1>&2 "mksysinfo.sh: could not determine size of int (got $sizeof_int)"
345 exit 1
348 # The C long type, needed because that is the type that ptrace returns.
349 sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
350 if test "$sizeof_long" = "4"; then
351 echo "type _C_long int32" >> ${OUT}
352 echo "type _C_ulong uint32" >> ${OUT}
353 elif test "$sizeof_long" = "8"; then
354 echo "type _C_long int64" >> ${OUT}
355 echo "type _C_ulong uint64" >> ${OUT}
356 else
357 echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
358 exit 1
361 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
362 # double is commented by -fdump-go-spec.
363 if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
364 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
366 if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
367 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
370 # The time_t type.
371 if grep '^type _time_t ' gen-sysinfo.go > /dev/null 2>&1; then
372 echo 'type Time_t _time_t' >> ${OUT}
375 # The time structures need special handling: we need to name the
376 # types, so that we can cast integers to the right types when
377 # assigning to the structures.
378 timeval=`grep '^type _timeval ' gen-sysinfo.go`
379 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
380 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
381 echo "type Timeval_sec_t $timeval_sec" >> ${OUT}
382 echo "type Timeval_usec_t $timeval_usec" >> ${OUT}
383 echo $timeval | \
384 sed -e 's/type _timeval /type Timeval /' \
385 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
386 -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
387 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
388 if test "$timespec" = ""; then
389 # IRIX 6.5 has __timespec instead.
390 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
392 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
393 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
394 echo "type Timespec_sec_t $timespec_sec" >> ${OUT}
395 echo "type Timespec_nsec_t $timespec_nsec" >> ${OUT}
396 echo $timespec | \
397 sed -e 's/^type ___timespec /type Timespec /' \
398 -e 's/^type _timespec /type Timespec /' \
399 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
400 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
402 timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
403 if test "$timestruc" != ""; then
404 timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
405 timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
406 echo "type Timestruc_sec_t $timestruc_sec" >> ${OUT}
407 echo "type Timestruc_nsec_t $timestruc_nsec" >> ${OUT}
408 echo $timestruc | \
409 sed -e 's/^type _timestruc_t /type Timestruc /' \
410 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
411 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
414 # The tms struct.
415 grep '^type _tms ' gen-sysinfo.go | \
416 sed -e 's/type _tms/type Tms/' \
417 -e 's/tms_utime/Utime/' \
418 -e 's/tms_stime/Stime/' \
419 -e 's/tms_cutime/Cutime/' \
420 -e 's/tms_cstime/Cstime/' \
421 >> ${OUT}
423 # The stat type.
424 # Prefer largefile variant if available.
425 stat=`grep '^type _stat64 ' gen-sysinfo.go || true`
426 if test "$stat" != ""; then
427 grep '^type _stat64 ' gen-sysinfo.go
428 else
429 grep '^type _stat ' gen-sysinfo.go
430 fi | sed -e 's/type _stat64/type Stat_t/' \
431 -e 's/type _stat/type Stat_t/' \
432 -e 's/st_dev/Dev/' \
433 -e 's/st_ino/Ino/g' \
434 -e 's/st_nlink/Nlink/' \
435 -e 's/st_mode/Mode/' \
436 -e 's/st_uid/Uid/' \
437 -e 's/st_gid/Gid/' \
438 -e 's/st_rdev/Rdev/' \
439 -e 's/st_size/Size/' \
440 -e 's/st_blksize/Blksize/' \
441 -e 's/st_blocks/Blocks/' \
442 -e 's/st_atim/Atim/' \
443 -e 's/st_mtim/Mtim/' \
444 -e 's/st_ctim/Ctim/' \
445 -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
446 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
447 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
448 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
449 -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
450 >> ${OUT}
452 # The directory searching types.
453 # Prefer largefile variant if available.
454 dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true`
455 if test "$dirent" != ""; then
456 grep '^type _dirent64 ' gen-sysinfo.go
457 else
458 grep '^type _dirent ' gen-sysinfo.go
459 fi | sed -e 's/type _dirent64/type Dirent/' \
460 -e 's/type _dirent/type Dirent/' \
461 -e 's/d_name \[0+1\]/d_name [0+256]/' \
462 -e 's/d_name/Name/' \
463 -e 's/]int8/]byte/' \
464 -e 's/d_ino/Ino/' \
465 -e 's/d_off/Off/' \
466 -e 's/d_reclen/Reclen/' \
467 -e 's/d_type/Type/' \
468 >> ${OUT}
469 echo "type DIR _DIR" >> ${OUT}
471 # Values for d_type field in dirent.
472 grep '^const _DT_' gen-sysinfo.go |
473 sed -e 's/^\(const \)_\(DT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
475 # The rusage struct.
476 rusage=`grep '^type _rusage struct' gen-sysinfo.go`
477 if test "$rusage" != ""; then
478 # Remove anonymous unions from GNU/Linux <bits/resource.h>.
479 rusage=`echo $rusage | sed -e 's/Godump_[0-9][0-9]* struct {\([^}]*\)};/\1/g'`
480 rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
481 rusage=`echo $rusage | sed -e 's/^ *//'`
482 nrusage=
483 while test -n "$rusage"; do
484 field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
485 rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
486 # Drop the leading ru_, capitalize the next character.
487 field=`echo $field | sed -e 's/^ru_//'`
488 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
489 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
490 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
491 # Fix _timeval _timespec, and _timestruc_t.
492 r=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
493 r=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
494 r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
495 field="$f$r"
496 nrusage="$nrusage $field;"
497 done
498 echo "type Rusage struct {$nrusage }" >> ${OUT}
499 else
500 echo "type Rusage struct {}" >> ${OUT}
503 # The RUSAGE constants.
504 grep '^const _RUSAGE_' gen-sysinfo.go | \
505 sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
507 # The utsname struct.
508 grep '^type _utsname ' gen-sysinfo.go | \
509 sed -e 's/_utsname/Utsname/' \
510 -e 's/sysname/Sysname/' \
511 -e 's/nodename/Nodename/' \
512 -e 's/release/Release/' \
513 -e 's/version/Version/' \
514 -e 's/machine/Machine/' \
515 -e 's/domainname/Domainname/' \
516 >> ${OUT}
518 # The iovec struct.
519 iovec=`grep '^type _iovec ' gen-sysinfo.go`
520 iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
521 echo "type Iovec_len_t $iovec_len" >> ${OUT}
522 echo $iovec | \
523 sed -e 's/_iovec/Iovec/' \
524 -e 's/iov_base/Base/' \
525 -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
526 >> ${OUT}
528 # The msghdr struct.
529 msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
530 msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
531 echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
532 echo $msghdr | \
533 sed -e 's/_msghdr/Msghdr/' \
534 -e 's/msg_name/Name/' \
535 -e 's/msg_namelen/Namelen/' \
536 -e 's/msg_iov/Iov/' \
537 -e 's/msg_iovlen/Iovlen/' \
538 -e 's/_iovec/Iovec/' \
539 -e 's/msg_control/Control/' \
540 -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
541 -e 's/msg_flags/Flags/' \
542 >> ${OUT}
544 # The MSG_ flags for Msghdr.
545 grep '^const _MSG_' gen-sysinfo.go | \
546 sed -e 's/^\(const \)_\(MSG_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
548 # The cmsghdr struct.
549 cmsghdr=`grep '^type _cmsghdr ' gen-sysinfo.go`
550 if test -n "$cmsghdr"; then
551 cmsghdr_len=`echo $cmsghdr | sed -n -e 's/^.*cmsg_len \([^ ]*\);.*$/\1/p'`
552 echo "type Cmsghdr_len_t $cmsghdr_len" >> ${OUT}
553 echo "$cmsghdr" | \
554 sed -e 's/_cmsghdr/Cmsghdr/' \
555 -e 's/cmsg_len *[a-zA-Z0-9_]*/Len Cmsghdr_len_t/' \
556 -e 's/cmsg_level/Level/' \
557 -e 's/cmsg_type/Type/' \
558 -e 's/\[\]/[0]/' \
559 >> ${OUT}
562 # The SCM_ flags for Cmsghdr.
563 grep '^const _SCM_' gen-sysinfo.go | \
564 sed -e 's/^\(const \)_\(SCM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
566 # The ucred struct.
567 upcase_fields "_ucred" "Ucred" >> ${OUT} || true
569 # The ip_mreq struct.
570 grep '^type _ip_mreq ' gen-sysinfo.go | \
571 sed -e 's/_ip_mreq/IPMreq/' \
572 -e 's/imr_multiaddr/Multiaddr/' \
573 -e 's/imr_interface/Interface/' \
574 -e 's/_in_addr/[4]byte/g' \
575 >> ${OUT}
577 # We need IPMreq to compile the net package.
578 if ! grep 'type IPMreq ' ${OUT} >/dev/null 2>&1; then
579 echo 'type IPMreq struct { Multiaddr [4]byte; Interface [4]byte; }' >> ${OUT}
582 # The ipv6_mreq struct.
583 grep '^type _ipv6_mreq ' gen-sysinfo.go | \
584 sed -e 's/_ipv6_mreq/IPv6Mreq/' \
585 -e 's/ipv6mr_multiaddr/Multiaddr/' \
586 -e 's/ipv6mr_interface/Interface/' \
587 -e 's/_in6_addr/[16]byte/' \
588 >> ${OUT}
590 # We need IPv6Mreq to compile the net package.
591 if ! grep 'type IPv6Mreq ' ${OUT} >/dev/null 2>&1; then
592 echo 'type IPv6Mreq struct { Multiaddr [16]byte; Interface uint32; }' >> ${OUT}
595 # The ip_mreqn struct.
596 grep '^type _ip_mreqn ' gen-sysinfo.go | \
597 sed -e 's/_ip_mreqn/IPMreqn/' \
598 -e 's/imr_multiaddr/Multiaddr/' \
599 -e 's/imr_address/Address/' \
600 -e 's/imr_ifindex/Ifindex/' \
601 -e 's/_in_addr/[4]byte/g' \
602 >> ${OUT}
604 # We need IPMreq to compile the net package.
605 if ! grep 'type IPMreqn ' ${OUT} >/dev/null 2>&1; then
606 echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT}
609 # The icmp6_filter struct.
610 grep '^type _icmp6_filter ' gen-sysinfo.go | \
611 sed -e 's/_icmp6_filter/ICMPv6Filter/' \
612 -e 's/data/Data/' \
613 -e 's/filt/Filt/' \
614 >> ${OUT}
616 # We need ICMPv6Filter to compile the syscall package.
617 if ! grep 'type ICMPv6Filter ' ${OUT} > /dev/null 2>&1; then
618 echo 'type ICMPv6Filter struct { Data [8]uint32 }' >> ${OUT}
621 # The ip6_mtuinfo struct.
622 grep '^type _ip6_mtuinfo ' gen-sysinfo.go | \
623 sed -e 's/_ip6_mtuinfo/IPv6MTUInfo/' \
624 -e 's/ip6m_addr/Addr/' \
625 -e 's/_sockaddr_in6/RawSockaddrInet6/' \
626 -e 's/ip6m_mtu/Mtu/' \
627 >> ${OUT}
629 # Try to guess the type to use for fd_set.
630 fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
631 fds_bits_type="_C_long"
632 if test "$fd_set" != ""; then
633 fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
635 echo "type fds_bits_type $fds_bits_type" >> ${OUT}
637 # The addrinfo struct.
638 grep '^type _addrinfo ' gen-sysinfo.go | \
639 sed -e 's/_addrinfo/Addrinfo/g' \
640 -e 's/ ai_/ Ai_/g' \
641 >> ${OUT}
643 # The addrinfo and nameinfo flags and errors.
644 grep '^const _AI_' gen-sysinfo.go | \
645 sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
646 grep '^const _EAI_' gen-sysinfo.go | \
647 sed -e 's/^\(const \)_\(EAI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
648 grep '^const _NI_' gen-sysinfo.go | \
649 sed -e 's/^\(const \)_\(NI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
651 # The passwd struct.
652 grep '^type _passwd ' gen-sysinfo.go | \
653 sed -e 's/_passwd/Passwd/' \
654 -e 's/ pw_/ Pw_/g' \
655 >> ${OUT}
657 # The group struct.
658 grep '^type _group ' gen-sysinfo.go | \
659 sed -e 's/_group/Group/' \
660 -e 's/ gr_/ Gr_/g' \
661 >> ${OUT}
663 # The ioctl flags for the controlling TTY.
664 grep '^const _TIOC' gen-sysinfo.go | \
665 grep -v '_val =' | \
666 sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
667 grep '^const _TUNSET' gen-sysinfo.go | \
668 grep -v '_val =' | \
669 sed -e 's/^\(const \)_\(TUNSET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
670 # We need TIOCGWINSZ.
671 if ! grep '^const TIOCGWINSZ' ${OUT} >/dev/null 2>&1; then
672 if grep '^const _TIOCGWINSZ_val' ${OUT} >/dev/null 2>&1; then
673 echo 'const TIOCGWINSZ = _TIOCGWINSZ_val' >> ${OUT}
676 if ! grep '^const TIOCSWINSZ' ${OUT} >/dev/null 2>&1; then
677 if grep '^const _TIOCSWINSZ_val' ${OUT} >/dev/null 2>&1; then
678 echo 'const TIOCSWINSZ = _TIOCSWINSZ_val' >> ${OUT}
681 if ! grep '^const TIOCNOTTY' ${OUT} >/dev/null 2>&1; then
682 if grep '^const _TIOCNOTTY_val' ${OUT} >/dev/null 2>&1; then
683 echo 'const TIOCNOTTY = _TIOCNOTTY_val' >> ${OUT}
686 if ! grep '^const TIOCSCTTY' ${OUT} >/dev/null 2>&1; then
687 if grep '^const _TIOCSCTTY_val' ${OUT} >/dev/null 2>&1; then
688 echo 'const TIOCSCTTY = _TIOCSCTTY_val' >> ${OUT}
691 if ! grep '^const TIOCGPGRP' ${OUT} >/dev/null 2>&1; then
692 if grep '^const _TIOCGPGRP_val' ${OUT} >/dev/null 2>&1; then
693 echo 'const TIOCGPGRP = _TIOCGPGRP_val' >> ${OUT}
696 if ! grep '^const TIOCSPGRP' ${OUT} >/dev/null 2>&1; then
697 if grep '^const _TIOCSPGRP_val' ${OUT} >/dev/null 2>&1; then
698 echo 'const TIOCSPGRP = _TIOCSPGRP_val' >> ${OUT}
701 if ! grep '^const TIOCGPTN' ${OUT} >/dev/null 2>&1; then
702 if grep '^const _TIOCGPTN_val' ${OUT} >/dev/null 2>&1; then
703 echo 'const TIOCGPTN = _TIOCGPTN_val' >> ${OUT}
706 if ! grep '^const TIOCSPTLCK' ${OUT} >/dev/null 2>&1; then
707 if grep '^const _TIOCSPTLCK_val' ${OUT} >/dev/null 2>&1; then
708 echo 'const TIOCSPTLCK = _TIOCSPTLCK_val' >> ${OUT}
711 if ! grep '^const TIOCGDEV' ${OUT} >/dev/null 2>&1; then
712 if grep '^const _TIOCGDEV_val' ${OUT} >/dev/null 2>&1; then
713 echo 'const TIOCGDEV = _TIOCGDEV_val' >> ${OUT}
716 if ! grep '^const TIOCSIG' ${OUT} >/dev/null 2>&1; then
717 if grep '^const _TIOCSIG_val' ${OUT} >/dev/null 2>&1; then
718 echo 'const TIOCSIG = _TIOCSIG_val' >> ${OUT}
722 if ! grep '^const TUNSETNOCSUM' ${OUT} >/dev/null 2>&1; then
723 if grep '^const _TUNSETNOCSUM_val' ${OUT} >/dev/null 2>&1; then
724 echo 'const TUNSETNOCSUM = _TUNSETNOCSUM_val' >> ${OUT}
728 if ! grep '^const TUNSETDEBUG' ${OUT} >/dev/null 2>&1; then
729 if grep '^const _TUNSETDEBUG_val' ${OUT} >/dev/null 2>&1; then
730 echo 'const TUNSETDEBUG = _TUNSETDEBUG_val' >> ${OUT}
734 if ! grep '^const TUNSETIFF' ${OUT} >/dev/null 2>&1; then
735 if grep '^const _TUNSETIFF_val' ${OUT} >/dev/null 2>&1; then
736 echo 'const TUNSETIFF = _TUNSETIFF_val' >> ${OUT}
740 if ! grep '^const TUNSETPERSIST' ${OUT} >/dev/null 2>&1; then
741 if grep '^const _TUNSETPERSIST_val' ${OUT} >/dev/null 2>&1; then
742 echo 'const TUNSETPERSIST = _TUNSETPERSIST_val' >> ${OUT}
746 if ! grep '^const TUNSETOWNER' ${OUT} >/dev/null 2>&1; then
747 if grep '^const _TUNSETOWNER_val' ${OUT} >/dev/null 2>&1; then
748 echo 'const TUNSETOWNER = _TUNSETOWNER_val' >> ${OUT}
752 if ! grep '^const TUNSETLINK' ${OUT} >/dev/null 2>&1; then
753 if grep '^const _TUNSETLINK_val' ${OUT} >/dev/null 2>&1; then
754 echo 'const TUNSETLINK = _TUNSETLINK_val' >> ${OUT}
758 if ! grep '^const TUNSETGROUP' ${OUT} >/dev/null 2>&1; then
759 if grep '^const _TUNSETGROUP_val' ${OUT} >/dev/null 2>&1; then
760 echo 'const TUNSETGROUP = _TUNSETGROUP_val' >> ${OUT}
764 if ! grep '^const TUNGETFEATURES' ${OUT} >/dev/null 2>&1; then
765 if grep '^const _TUNGETFEATURES_val' ${OUT} >/dev/null 2>&1; then
766 echo 'const TUNGETFEATURES = _TUNGETFEATURES_val' >> ${OUT}
770 if ! grep '^const TUNSETOFFLOAD' ${OUT} >/dev/null 2>&1; then
771 if grep '^const _TUNSETOFFLOAD_val' ${OUT} >/dev/null 2>&1; then
772 echo 'const TUNSETOFFLOAD = _TUNSETOFFLOAD_val' >> ${OUT}
776 if ! grep '^const TUNSETTXFILTER' ${OUT} >/dev/null 2>&1; then
777 if grep '^const _TUNSETTXFILTER_val' ${OUT} >/dev/null 2>&1; then
778 echo 'const TUNSETTXFILTER = _TUNSETTXFILTER_val' >> ${OUT}
782 if ! grep '^const TUNGETIFF' ${OUT} >/dev/null 2>&1; then
783 if grep '^const _TUNGETIFF_val' ${OUT} >/dev/null 2>&1; then
784 echo 'const TUNGETIFF = _TUNGETIFF_val' >> ${OUT}
788 if ! grep '^const TUNGETSNDBUF' ${OUT} >/dev/null 2>&1; then
789 if grep '^const _TUNGETSNDBUF_val' ${OUT} >/dev/null 2>&1; then
790 echo 'const TUNGETSNDBUF = _TUNGETSNDBUF_val' >> ${OUT}
794 if ! grep '^const TUNSETSNDBUF' ${OUT} >/dev/null 2>&1; then
795 if grep '^const _TUNSETSNDBUF_val' ${OUT} >/dev/null 2>&1; then
796 echo 'const TUNSETSNDBUF = _TUNSETSNDBUF_val' >> ${OUT}
800 if ! grep '^const TUNATTACHFILTER' ${OUT} >/dev/null 2>&1; then
801 if grep '^const _TUNATTACHFILTER_val' ${OUT} >/dev/null 2>&1; then
802 echo 'const TUNATTACHFILTER = _TUNATTACHFILTER_val' >> ${OUT}
806 if ! grep '^const TUNDETACHFILTER' ${OUT} >/dev/null 2>&1; then
807 if grep '^const _TUNDETACHFILTER_val' ${OUT} >/dev/null 2>&1; then
808 echo 'const TUNDETACHFILTER = _TUNDETACHFILTER_val' >> ${OUT}
812 if ! grep '^const TUNGETVNETHDRSZ' ${OUT} >/dev/null 2>&1; then
813 if grep '^const _TUNGETVNETHDRSZ_val' ${OUT} >/dev/null 2>&1; then
814 echo 'const TUNGETVNETHDRSZ = _TUNGETVNETHDRSZ_val' >> ${OUT}
818 if ! grep '^const TUNSETVNETHDRSZ' ${OUT} >/dev/null 2>&1; then
819 if grep '^const _TUNSETVNETHDRSZ_val' ${OUT} >/dev/null 2>&1; then
820 echo 'const TUNSETVNETHDRSZ = _TUNSETVNETHDRSZ_val' >> ${OUT}
824 if ! grep '^const TUNSETQUEUE' ${OUT} >/dev/null 2>&1; then
825 if grep '^const _TUNSETQUEUE_val' ${OUT} >/dev/null 2>&1; then
826 echo 'const TUNSETQUEUE = _TUNSETQUEUE_val' >> ${OUT}
831 if ! grep '^const TUNSETIFINDEX' ${OUT} >/dev/null 2>&1; then
832 if grep '^const _TUNSETIFINDEX_val' ${OUT} >/dev/null 2>&1; then
833 echo 'const TUNSETIFINDEX = _TUNSETIFINDEX_val' >> ${OUT}
837 if ! grep '^const TUNGETFILTER' ${OUT} >/dev/null 2>&1; then
838 if grep '^const _TUNGETFILTER_val' ${OUT} >/dev/null 2>&1; then
839 echo 'const TUNGETFILTER = _TUNGETFILTER_val' >> ${OUT}
843 # The ioctl flags for terminal control
844 grep '^const _TC[GS]ET' gen-sysinfo.go | grep -v _val | \
845 sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
846 if ! grep '^const TCGETS' ${OUT} >/dev/null 2>&1; then
847 if grep '^const _TCGETS_val' ${OUT} >/dev/null 2>&1; then
848 echo 'const TCGETS = _TCGETS_val' >> ${OUT}
851 if ! grep '^const TCSETS' ${OUT} >/dev/null 2>&1; then
852 if grep '^const _TCSETS_val' ${OUT} >/dev/null 2>&1; then
853 echo 'const TCSETS = _TCSETS_val' >> ${OUT}
857 # ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but
858 # needs handling in syscalls.exec.go.
859 if ! grep '^const _TIOCSCTTY ' gen-sysinfo.go >/dev/null 2>&1; then
860 if grep '^const _TIOCNXCL ' gen-sysinfo.go >/dev/null 2>&1; then
861 echo "const TIOCSCTTY = TIOCNXCL" >> ${OUT}
865 # The nlmsghdr struct.
866 grep '^type _nlmsghdr ' gen-sysinfo.go | \
867 sed -e 's/_nlmsghdr/NlMsghdr/' \
868 -e 's/nlmsg_len/Len/' \
869 -e 's/nlmsg_type/Type/' \
870 -e 's/nlmsg_flags/Flags/' \
871 -e 's/nlmsg_seq/Seq/' \
872 -e 's/nlmsg_pid/Pid/' \
873 >> ${OUT}
875 # The nlmsg flags and operators.
876 grep '^const _NLM' gen-sysinfo.go | \
877 sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
879 # NLMSG_HDRLEN is defined as an expression using sizeof.
880 if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev/null 2>&1; then
881 if grep '^const _sizeof_nlmsghdr ' ${OUT} > /dev/null 2>&1; then
882 echo 'const NLMSG_HDRLEN = (_sizeof_nlmsghdr + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1)' >> ${OUT}
886 # The rtmsg struct.
887 grep '^type _rtmsg ' gen-sysinfo.go | \
888 sed -e 's/_rtmsg/RtMsg/' \
889 -e 's/rtm_family/Family/' \
890 -e 's/rtm_dst_len/Dst_len/' \
891 -e 's/rtm_src_len/Src_len/' \
892 -e 's/rtm_tos/Tos/' \
893 -e 's/rtm_table/Table/' \
894 -e 's/rtm_protocol/Protocol/' \
895 -e 's/rtm_scope/Scope/' \
896 -e 's/rtm_type/Type/' \
897 -e 's/rtm_flags/Flags/' \
898 >> ${OUT}
900 # The rtgenmsg struct.
901 grep '^type _rtgenmsg ' gen-sysinfo.go | \
902 sed -e 's/_rtgenmsg/RtGenmsg/' \
903 -e 's/rtgen_family/Family/' \
904 >> ${OUT}
906 # The routing message flags.
907 grep '^const _RT_' gen-sysinfo.go | \
908 sed -e 's/^\(const \)_\(RT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
909 grep '^const _RTA' gen-sysinfo.go | \
910 sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
911 grep '^const _RTF' gen-sysinfo.go | \
912 sed -e 's/^\(const \)_\(RTF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
913 grep '^const _RTCF' gen-sysinfo.go | \
914 sed -e 's/^\(const \)_\(RTCF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
915 grep '^const _RTM' gen-sysinfo.go | \
916 sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
917 grep '^const _RTN' gen-sysinfo.go | \
918 sed -e 's/^\(const \)_\(RTN[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
919 grep '^const _RTPROT' gen-sysinfo.go | \
920 sed -e 's/^\(const \)_\(RTPROT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
922 # The ifinfomsg struct.
923 grep '^type _ifinfomsg ' gen-sysinfo.go | \
924 sed -e 's/_ifinfomsg/IfInfomsg/' \
925 -e 's/ifi_family/Family/' \
926 -e 's/ifi_type/Type/' \
927 -e 's/ifi_index/Index/' \
928 -e 's/ifi_flags/Flags/' \
929 -e 's/ifi_change/Change/' \
930 >> ${OUT}
932 # The interface information types and flags.
933 grep '^const _IFA' gen-sysinfo.go | \
934 sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
935 grep '^const _IFLA' gen-sysinfo.go | \
936 sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
937 grep '^const _IFF' gen-sysinfo.go | \
938 sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
939 grep '^const _IFNAMSIZ' gen-sysinfo.go | \
940 sed -e 's/^\(const \)_\(IFNAMSIZ[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
941 grep '^const _SIOC' gen-sysinfo.go |
942 sed -e 's/^\(const \)_\(SIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
944 # The ifaddrmsg struct.
945 grep '^type _ifaddrmsg ' gen-sysinfo.go | \
946 sed -e 's/_ifaddrmsg/IfAddrmsg/' \
947 -e 's/ifa_family/Family/' \
948 -e 's/ifa_prefixlen/Prefixlen/' \
949 -e 's/ifa_flags/Flags/' \
950 -e 's/ifa_scope/Scope/' \
951 -e 's/ifa_index/Index/' \
952 >> ${OUT}
954 # The rtattr struct.
955 grep '^type _rtattr ' gen-sysinfo.go | \
956 sed -e 's/_rtattr/RtAttr/' \
957 -e 's/rta_len/Len/' \
958 -e 's/rta_type/Type/' \
959 >> ${OUT}
961 # The in_pktinfo struct.
962 grep '^type _in_pktinfo ' gen-sysinfo.go | \
963 sed -e 's/_in_pktinfo/Inet4Pktinfo/' \
964 -e 's/ipi_ifindex/Ifindex/' \
965 -e 's/ipi_spec_dst/Spec_dst/' \
966 -e 's/ipi_addr/Addr/' \
967 -e 's/_in_addr/[4]byte/g' \
968 >> ${OUT}
970 # The in6_pktinfo struct.
971 grep '^type _in6_pktinfo ' gen-sysinfo.go | \
972 sed -e 's/_in6_pktinfo/Inet6Pktinfo/' \
973 -e 's/ipi6_addr/Addr/' \
974 -e 's/ipi6_ifindex/Ifindex/' \
975 -e 's/_in6_addr/[16]byte/' \
976 >> ${OUT}
978 # The termios struct.
979 grep '^type _termios ' gen-sysinfo.go | \
980 sed -e 's/_termios/Termios/' \
981 -e 's/c_iflag/Iflag/' \
982 -e 's/c_oflag/Oflag/' \
983 -e 's/c_cflag/Cflag/' \
984 -e 's/c_lflag/Lflag/' \
985 -e 's/c_line/Line/' \
986 -e 's/c_cc/Cc/' \
987 -e 's/c_ispeed/Ispeed/' \
988 -e 's/c_ospeed/Ospeed/' \
989 >> ${OUT}
991 # The termios constants.
992 for n in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \
993 IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \
994 OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 CS5 CS6 CS7 CS8 TABDLY \
995 BSDLY VTDLY FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL \
996 CLOCAL LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE ECHO ECHOE ECHOK \
997 ECHONL ECHOCTL ECHOPRT ECHOKE DEFECHO FLUSHO NOFLSH TOSTOP PENDIN IEXTEN \
998 VINTR VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 VSWTCH VSTART VSTOP \
999 VSUSP VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS TCSANOW TCSADRAIN \
1000 TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON TCIOFF TCION B0 B50 \
1001 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 \
1002 B38400 B57600 B115200 B230400 B460800 B500000 B576000 B921600 B1000000 \
1003 B1152000 B1500000 B2000000 B2500000 B3000000 B3500000 B4000000; do
1005 grep "^const _$n " gen-sysinfo.go | \
1006 sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1007 done
1009 # The mount flags
1010 grep '^const _MNT_' gen-sysinfo.go |
1011 sed -e 's/^\(const \)_\(MNT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1012 grep '^const _MS_' gen-sysinfo.go |
1013 sed -e 's/^\(const \)_\(MS_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1015 # The fallocate flags.
1016 grep '^const _FALLOC_' gen-sysinfo.go |
1017 sed -e 's/^\(const \)_\(FALLOC_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1019 # The statfs struct.
1020 # Prefer largefile variant if available.
1021 statfs=`grep '^type _statfs64 ' gen-sysinfo.go || true`
1022 if test "$statfs" != ""; then
1023 grep '^type _statfs64 ' gen-sysinfo.go
1024 else
1025 grep '^type _statfs ' gen-sysinfo.go
1026 fi | sed -e 's/type _statfs64/type Statfs_t/' \
1027 -e 's/type _statfs/type Statfs_t/' \
1028 -e 's/f_type/Type/' \
1029 -e 's/f_bsize/Bsize/' \
1030 -e 's/f_blocks/Blocks/' \
1031 -e 's/f_bfree/Bfree/' \
1032 -e 's/f_bavail/Bavail/' \
1033 -e 's/f_files/Files/' \
1034 -e 's/f_ffree/Ffree/' \
1035 -e 's/f_fsid/Fsid/' \
1036 -e 's/f_namelen/Namelen/' \
1037 -e 's/f_frsize/Frsize/' \
1038 -e 's/f_flags/Flags/' \
1039 -e 's/f_spare/Spare/' \
1040 >> ${OUT}
1042 # The timex struct.
1043 timex=`grep '^type _timex ' gen-sysinfo.go || true`
1044 if test "$timex" = ""; then
1045 timex=`grep '^// type _timex ' gen-sysinfo.go || true`
1046 if test "$timex" != ""; then
1047 timex=`echo $timex | sed -e 's|// ||' -e 's/INVALID-bit-field/int32/g'`
1050 if test "$timex" != ""; then
1051 echo "$timex" | \
1052 sed -e 's/_timex/Timex/' \
1053 -e 's/modes/Modes/' \
1054 -e 's/offset/Offset/' \
1055 -e 's/freq/Freq/' \
1056 -e 's/maxerror/Maxerror/' \
1057 -e 's/esterror/Esterror/' \
1058 -e 's/status/Status/' \
1059 -e 's/constant/Constant/' \
1060 -e 's/precision/Precision/' \
1061 -e 's/tolerance/Tolerance/' \
1062 -e 's/ time / Time /' \
1063 -e 's/tick/Tick/' \
1064 -e 's/ppsfreq/Ppsfreq/' \
1065 -e 's/jitter/Jitter/' \
1066 -e 's/shift/Shift/' \
1067 -e 's/stabil/Stabil/' \
1068 -e 's/jitcnt/Jitcnt/' \
1069 -e 's/calcnt/Calcnt/' \
1070 -e 's/errcnt/Errcnt/' \
1071 -e 's/stbcnt/Stbcnt/' \
1072 -e 's/tai/Tai/' \
1073 -e 's/_timeval/Timeval/' \
1074 >> ${OUT}
1077 # The rlimit struct.
1078 grep '^type _rlimit ' gen-sysinfo.go | \
1079 sed -e 's/_rlimit/Rlimit/' \
1080 -e 's/rlim_cur/Cur/' \
1081 -e 's/rlim_max/Max/' \
1082 >> ${OUT}
1084 # The RLIMIT constants.
1085 grep '^const _RLIMIT_' gen-sysinfo.go |
1086 sed -e 's/^\(const \)_\(RLIMIT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1087 grep '^const _RLIM_' gen-sysinfo.go |
1088 sed -e 's/^\(const \)_\(RLIM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1090 # The sysinfo struct.
1091 grep '^type _sysinfo ' gen-sysinfo.go | \
1092 sed -e 's/_sysinfo/Sysinfo_t/' \
1093 -e 's/uptime/Uptime/' \
1094 -e 's/loads/Loads/' \
1095 -e 's/totalram/Totalram/' \
1096 -e 's/freeram/Freeram/' \
1097 -e 's/sharedram/Sharedram/' \
1098 -e 's/bufferram/Bufferram/' \
1099 -e 's/totalswap/Totalswap/' \
1100 -e 's/freeswap/Freeswap/' \
1101 -e 's/procs/Procs/' \
1102 -e 's/totalhigh/Totalhigh/' \
1103 -e 's/freehigh/Freehigh/' \
1104 -e 's/mem_unit/Unit/' \
1105 >> ${OUT}
1107 # The ustat struct.
1108 grep '^type _ustat ' gen-sysinfo.go | \
1109 sed -e 's/_ustat/Ustat_t/' \
1110 -e 's/f_tfree/Tfree/' \
1111 -e 's/f_tinode/Tinoe/' \
1112 -e 's/f_fname/Fname/' \
1113 -e 's/f_fpack/Fpack/' \
1114 >> ${OUT}
1115 # Force it to be defined, as on some older GNU/Linux systems the
1116 # header file fails when using with <linux/filter.h>.
1117 if ! grep 'type _ustat ' gen-sysinfo.go >/dev/null 2>&1; then
1118 echo 'type Ustat_t struct { Tfree int32; Tinoe uint64; Fname [5+1]int8; Fpack [5+1]int8; }' >> ${OUT}
1121 # The utimbuf struct.
1122 grep '^type _utimbuf ' gen-sysinfo.go | \
1123 sed -e 's/_utimbuf/Utimbuf/' \
1124 -e 's/actime/Actime/' \
1125 -e 's/modtime/Modtime/' \
1126 >> ${OUT}
1128 # The LOCK flags for flock.
1129 grep '^const _LOCK_' gen-sysinfo.go |
1130 sed -e 's/^\(const \)_\(LOCK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1132 # The PRIO constants.
1133 grep '^const _PRIO_' gen-sysinfo.go | \
1134 sed -e 's/^\(const \)_\(PRIO_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1136 # The GNU/Linux LINUX_REBOOT flags.
1137 grep '^const _LINUX_REBOOT_' gen-sysinfo.go |
1138 sed -e 's/^\(const \)_\(LINUX_REBOOT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1140 # The GNU/Linux sock_filter struct.
1141 grep '^type _sock_filter ' gen-sysinfo.go | \
1142 sed -e 's/_sock_filter/SockFilter/' \
1143 -e 's/code/Code/' \
1144 -e 's/jt/Jt/' \
1145 -e 's/jf/Jf/' \
1146 -e 's/k /K /' \
1147 >> ${OUT}
1149 # The GNU/Linux sock_fprog struct.
1150 grep '^type _sock_fprog ' gen-sysinfo.go | \
1151 sed -e 's/_sock_fprog/SockFprog/' \
1152 -e 's/len/Len/' \
1153 -e 's/filter/Filter/' \
1154 -e 's/_sock_filter/SockFilter/' \
1155 >> ${OUT}
1157 # The GNU/Linux filter flags.
1158 grep '^const _BPF_' gen-sysinfo.go | \
1159 sed -e 's/^\(const \)_\(BPF_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1161 # The GNU/Linux nlattr struct.
1162 grep '^type _nlattr ' gen-sysinfo.go | \
1163 sed -e 's/_nlattr/NlAttr/' \
1164 -e 's/nla_len/Len/' \
1165 -e 's/nla_type/Type/' \
1166 >> ${OUT}
1168 # The GNU/Linux nlmsgerr struct.
1169 grep '^type _nlmsgerr ' gen-sysinfo.go | \
1170 sed -e 's/_nlmsgerr/NlMsgerr/' \
1171 -e 's/error/Error/' \
1172 -e 's/msg/Msg/' \
1173 -e 's/_nlmsghdr/NlMsghdr/' \
1174 >> ${OUT}
1176 # The GNU/Linux rtnexthop struct.
1177 grep '^type _rtnexthop ' gen-sysinfo.go | \
1178 sed -e 's/_rtnexthop/RtNexthop/' \
1179 -e 's/rtnh_len/Len/' \
1180 -e 's/rtnh_flags/Flags/' \
1181 -e 's/rtnh_hops/Hops/' \
1182 -e 's/rtnh_ifindex/Ifindex/' \
1183 >> ${OUT}
1185 # The GNU/Linux netlink flags.
1186 grep '^const _NETLINK_' gen-sysinfo.go | \
1187 sed -e 's/^\(const \)_\(NETLINK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1188 grep '^const _NLA_' gen-sysinfo.go | grep -v '_val =' | \
1189 sed -e 's/^\(const \)_\(NLA_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1191 if ! grep '^const NLA_HDRLEN' ${OUT} >/dev/null 2>&1; then
1192 if grep '^const _NLA_HDRLEN_val' ${OUT} >/dev/null 2>&1; then
1193 echo 'const NLA_HDRLEN = _NLA_HDRLEN_val' >> ${OUT}
1197 # The GNU/Linux packet socket flags.
1198 grep '^const _PACKET_' gen-sysinfo.go | \
1199 sed -e 's/^\(const \)_\(PACKET_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1201 # The GNU/Linux inotify_event struct.
1202 grep '^type _inotify_event ' gen-sysinfo.go | \
1203 sed -e 's/_inotify_event/InotifyEvent/' \
1204 -e 's/wd/Wd/' \
1205 -e 's/mask/Mask/' \
1206 -e 's/cookie/Cookie/' \
1207 -e 's/len/Len/' \
1208 -e 's/name/Name/' \
1209 -e 's/\[\]/[0]/' \
1210 -e 's/\[0\]byte/[0]int8/' \
1211 >> ${OUT}
1213 # The GNU/Linux CLONE flags.
1214 grep '^const _CLONE_' gen-sysinfo.go | \
1215 sed -e 's/^\(const \)_\(CLONE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1216 # We need some CLONE constants that are not defined in older versions
1217 # of glibc.
1218 if ! grep '^const CLONE_NEWUSER ' ${OUT} > /dev/null 2>&1; then
1219 echo "const CLONE_NEWUSER = 0x10000000" >> ${OUT}
1221 if ! grep '^const CLONE_NEWNET ' ${OUT} > /dev/null 2>&1; then
1222 echo "const CLONE_NEWNET = 0x40000000" >> ${OUT}
1225 # Struct sizes.
1226 set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \
1227 ifaddrmsg IfAddrmsg ifinfomsg IfInfomsg in_pktinfo Inet4Pktinfo \
1228 in6_pktinfo Inet6Pktinfo inotify_event InotifyEvent linger Linger \
1229 msghdr Msghdr nlattr NlAttr nlmsgerr NlMsgerr nlmsghdr NlMsghdr \
1230 rtattr RtAttr rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \
1231 sock_filter SockFilter sock_fprog SockFprog ucred Ucred \
1232 icmp6_filter ICMPv6Filter ip6_mtuinfo IPv6MTUInfo
1233 while test $# != 0; do
1234 nc=$1
1235 ngo=$2
1236 shift
1237 shift
1238 if grep "^const _sizeof_$nc =" gen-sysinfo.go >/dev/null 2>&1; then
1239 echo "const Sizeof$ngo = _sizeof_$nc" >> ${OUT}
1241 done
1243 # In order to compile the net package, we need some sizes to exist
1244 # even if the types do not.
1245 if ! grep 'const SizeofIPMreq ' ${OUT} >/dev/null 2>&1; then
1246 echo 'const SizeofIPMreq = 8' >> ${OUT}
1248 if ! grep 'const SizeofIPv6Mreq ' ${OUT} >/dev/null 2>&1; then
1249 echo 'const SizeofIPv6Mreq = 20' >> ${OUT}
1251 if ! grep 'const SizeofIPMreqn ' ${OUT} >/dev/null 2>&1; then
1252 echo 'const SizeofIPMreqn = 12' >> ${OUT}
1254 if ! grep 'const SizeofICMPv6Filter ' ${OUT} >/dev/null 2>&1; then
1255 echo 'const SizeofICMPv6Filter = 32' >> ${OUT}
1258 # The Solaris 11 Update 1 _zone_net_addr_t struct.
1259 grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
1260 sed -e 's/_in6_addr/[16]byte/' \
1261 >> ${OUT}
1263 # The Solaris 12 _flow_arp_desc_t struct.
1264 grep '^type _flow_arp_desc_t ' gen-sysinfo.go | \
1265 sed -e 's/_in6_addr_t/[16]byte/g' \
1266 >> ${OUT}
1268 # The Solaris 12 _flow_l3_desc_t struct.
1269 grep '^type _flow_l3_desc_t ' gen-sysinfo.go | \
1270 sed -e 's/_in6_addr_t/[16]byte/g' \
1271 >> ${OUT}
1273 # The Solaris 12 _mac_ipaddr_t struct.
1274 grep '^type _mac_ipaddr_t ' gen-sysinfo.go | \
1275 sed -e 's/_in6_addr_t/[16]byte/g' \
1276 >> ${OUT}
1278 # The Solaris 12 _mactun_info_t struct.
1279 grep '^type _mactun_info_t ' gen-sysinfo.go | \
1280 sed -e 's/_in6_addr_t/[16]byte/g' \
1281 >> ${OUT}
1283 exit $?