Fix CL entry
[official-gcc.git] / libgo / mksysinfo.sh
blobea1fa17d4189c5e9b7647ad9e61489666dcad4fb
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 '^var' | \
33 grep -v '^type _timeval ' | \
34 grep -v '^type _timespec_t ' | \
35 grep -v '^type _timespec ' | \
36 grep -v '^type _timestruc_t ' | \
37 grep -v '^type _epoll_' | \
38 grep -v '^type _*locale[_ ]' | \
39 grep -v '^type _in6_addr' | \
40 grep -v 'sockaddr_in6' | \
41 egrep -v '^const _*FLT(64|128)_(NORM_)?MAX' | \
42 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
43 -e 's/\([^a-zA-Z0-9_]\)_timeval$/\1Timeval/g' \
44 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
45 -e 's/\([^a-zA-Z0-9_]\)_timespec_t$/\1Timespec/g' \
46 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
47 -e 's/\([^a-zA-Z0-9_]\)_timespec$/\1Timespec/g' \
48 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
49 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t$/\1Timestruc/g' \
50 -e 's/\([^a-zA-Z0-9_]\)_in6_addr\([^a-zA-Z0-9_]\)/\1[16]byte\2/g' \
51 -e 's/\([^a-zA-Z0-9_]\)_in6_addr$/\1[16]byte/g' \
52 -e 's/\([^a-zA-Z0-9_]\)_in6_addr_t\([^a-zA-Z0-9_]\)/\1[16]byte\2/g' \
53 -e 's/\([^a-zA-Z0-9_]\)_in6_addr_t$/\1[16]byte/g' \
54 >> ${OUT}
56 # The errno constants. These get type Errno.
57 egrep '#define E[A-Z0-9_]+ [0-9E]' errno.i | \
58 sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(_\1)/' >> ${OUT}
60 # Workaround for GNU/Hurd _EMIG_* errors having negative values
61 egrep '#define E[A-Z0-9_]+ -[0-9]' errno.i | \
62 sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(-_\1)/' >> ${OUT}
64 # The O_xxx flags.
65 egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
66 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
67 if ! grep '^const O_ASYNC' ${OUT} >/dev/null 2>&1; then
68 echo "const O_ASYNC = 0" >> ${OUT}
70 if ! grep '^const O_CLOEXEC' ${OUT} >/dev/null 2>&1; then
71 echo "const O_CLOEXEC = 0" >> ${OUT}
74 # The os package requires F_DUPFD_CLOEXEC to be defined.
75 if ! grep '^const F_DUPFD_CLOEXEC' ${OUT} >/dev/null 2>&1; then
76 echo "const F_DUPFD_CLOEXEC = 0" >> ${OUT}
79 # The internal/poll package requires F_GETPIPE_SZ to be defined.
80 if ! grep '^const F_GETPIPE_SZ' ${OUT} >/dev/null 2>&1; then
81 echo "const F_GETPIPE_SZ = 0" >> ${OUT}
84 # AIX 7.1 is a 64 bits value for _FCLOEXEC (referenced by O_CLOEXEC)
85 # which leads to a constant overflow when using O_CLOEXEC in some
86 # go code. Issue wan not present in 6.1 (no O_CLOEXEC) and is no
87 # more present in 7.2 (_FCLOEXEC is a 32 bit value).
88 if test "${GOOS}" = "aix" && `oslevel | grep -q "^7.1"`; then
89 sed -e 's/const __FCLOEXEC = .*/const __FCLOEXEC = 0/' ${OUT} > ${OUT}-2
90 mv ${OUT}-2 ${OUT}
93 # These flags can be lost on i386 GNU/Linux when using
94 # -D_FILE_OFFSET_BITS=64, because we see "#define F_SETLK F_SETLK64"
95 # before we see the definition of F_SETLK64.
96 for flag in F_GETLK F_SETLK F_SETLKW; do
97 if ! grep "^const ${flag} " ${OUT} >/dev/null 2>&1 \
98 && grep "^const ${flag}64 " ${OUT} >/dev/null 2>&1; then
99 echo "const ${flag} = ${flag}64" >> ${OUT}
101 done
103 # The Flock_t struct for fcntl.
104 grep '^type _flock ' gen-sysinfo.go | \
105 sed -e 's/type _flock/type Flock_t/' \
106 -e 's/l_type/Type/' \
107 -e 's/l_whence/Whence/' \
108 -e 's/l_start/Start/' \
109 -e 's/l_len/Len/' \
110 -e 's/l_pid/Pid/' \
111 >> ${OUT}
113 # The signal numbers.
114 grep '^const _SIG[^_]' gen-sysinfo.go | \
115 grep -v '^const _SIGEV_' | \
116 sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = Signal(_\2)/' >> ${OUT}
117 if ! grep '^const SIGPOLL ' ${OUT} >/dev/null 2>&1; then
118 if grep '^const SIGIO ' ${OUT} > /dev/null 2>&1; then
119 echo "const SIGPOLL = SIGIO" >> ${OUT}
122 if ! grep '^const SIGCLD ' ${OUT} >/dev/null 2>&1; then
123 if grep '^const SIGCHLD ' ${OUT} >/dev/null 2>&1; then
124 echo "const SIGCLD = SIGCHLD" >> ${OUT}
128 # The syscall numbers. We force the names to upper case.
129 grep '^const _SYS_' gen-sysinfo.go | \
130 grep -v '^const _SYS_SECCOMP = ' | \
131 sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \
132 while read sys; do
133 sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
134 echo "const $sup = _$sys" >> ${OUT}
135 done
137 # Special treatment of SYS_IOCTL for GNU/Hurd.
138 if ! grep '^const SYS_IOCTL' ${OUT} > /dev/null 2>&1; then
139 echo "const SYS_IOCTL = 0" >> ${OUT}
142 # The GNU/Linux support wants to use SYS_GETDENTS64 if available.
143 if ! grep '^const SYS_GETDENTS ' ${OUT} >/dev/null 2>&1; then
144 echo "const SYS_GETDENTS = 0" >> ${OUT}
146 if ! grep '^const SYS_GETDENTS64 ' ${OUT} >/dev/null 2>&1; then
147 echo "const SYS_GETDENTS64 = 0" >> ${OUT}
150 # The syscall package wants the geteuid system call number. It isn't
151 # defined on Alpha, which only provides the getresuid system call.
152 if ! grep '^const SYS_GETEUID ' ${OUT} >/dev/null 2>&1; then
153 echo "const SYS_GETEUID = 0" >> ${OUT}
156 # Stat constants.
157 grep '^const _S_' gen-sysinfo.go | \
158 sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
160 # Mmap constants.
161 grep '^const _PROT_' gen-sysinfo.go | \
162 sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
163 grep '^const _MAP_' gen-sysinfo.go | \
164 sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
165 grep '^const _MADV_' gen-sysinfo.go | \
166 sed -e 's/^\(const \)_\(MADV_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
167 grep '^const _MCL_' gen-sysinfo.go | \
168 sed -e 's/^\(const \)_\(MCL_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
170 # Process status constants.
171 grep '^const _W' gen-sysinfo.go |
172 sed -e 's/^\(const \)_\(W[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
173 # WSTOPPED was introduced in glibc 2.3.4.
174 if ! grep '^const _WSTOPPED = ' gen-sysinfo.go >/dev/null 2>&1; then
175 if grep '^const _WUNTRACED = ' gen-sysinfo.go > /dev/null 2>&1; then
176 echo 'const WSTOPPED = _WUNTRACED' >> ${OUT}
177 else
178 echo 'const WSTOPPED = 2' >> ${OUT}
181 if grep '^const ___WALL = ' gen-sysinfo.go >/dev/null 2>&1 \
182 && ! grep '^const _WALL = ' gen-sysinfo.go >/dev/null 2>&1; then
183 echo 'const WALL = ___WALL' >> ${OUT}
185 # On GNU/Linux the os package requires WEXITED and WNOWAIT.
186 if test "${GOOS}" = "linux"; then
187 if ! grep '^const WEXITED = ' ${OUT} >/dev/null 2>&1; then
188 echo 'const WEXITED = 4' >> ${OUT}
190 if ! grep '^const WNOWAIT = ' ${OUT} >/dev/null 2>&1; then
191 echo 'const WNOWAIT = 0x01000000' >> ${OUT}
195 # Networking constants.
196 egrep '^const _(AF|ARPHRD|ETH|IN|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
197 grep -v '_val =' |
198 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
199 grep '^const _SOMAXCONN' gen-sysinfo.go |
200 sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
201 >> ${OUT}
202 grep '^const _SHUT_' gen-sysinfo.go |
203 sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
205 # The net package requires some const definitions.
206 for m in IP_PKTINFO IPV6_V6ONLY IPPROTO_IPV6 IPV6_JOIN_GROUP IPV6_LEAVE_GROUP IPV6_TCLASS SO_REUSEPORT; do
207 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
208 echo "const $m = 0" >> ${OUT}
210 done
211 for m in SOCK_CLOEXEC SOCK_NONBLOCK; do
212 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
213 echo "const $m = -1" >> ${OUT}
215 done
217 # On 32-bit GNU/Linux the expression for SO_RCVTIMEO is too complicated
218 # for -fdump-go-spec.
219 if ! grep '^const SO_RCVTIMEO ' ${OUT} >/dev/null 2>&1; then
220 if grep '^const _SO_RCVTIMEO_val' ${OUT} >/dev/null 2>&1; then
221 echo 'const SO_RCVTIMEO = _SO_RCVTIMEO_val' >> ${OUT}
225 # The syscall package requires AF_LOCAL.
226 if ! grep '^const AF_LOCAL ' ${OUT} >/dev/null 2>&1; then
227 if grep '^const AF_UNIX ' ${OUT} >/dev/null 2>&1; then
228 echo "const AF_LOCAL = AF_UNIX" >> ${OUT}
232 # The syscall package requires _AT_FDCWD, but doesn't export it.
233 if ! grep '^const _AT_FDCWD = ' ${OUT} >/dev/null 2>&1; then
234 echo "const _AT_FDCWD = -100" >> ${OUT}
237 # sysctl constants.
238 grep '^const _CTL' gen-sysinfo.go |
239 sed -e 's/^\(const \)_\(CTL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
240 grep '^const _SYSCTL' gen-sysinfo.go |
241 sed -e 's/^\(const \)_\(SYSCTL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
242 grep '^const _NET_RT' gen-sysinfo.go |
243 sed -e 's/^\(const \)_\(NET_RT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
245 # The sysctlnode struct.
246 grep '^type _sysctlnode ' gen-sysinfo.go | \
247 sed -e 's/_sysctlnode/Sysctlnode/' \
248 -e 's/sysctl_flags/Flags/' \
249 -e 's/sysctl_name/Name/' \
250 -e 's/sysctl_num/Num/' \
251 >> ${OUT}
253 # sysconf constants.
254 grep '^const __SC' gen-sysinfo.go |
255 sed -e 's/^\(const \)__\(SC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
257 # pathconf constants.
258 grep '^const __PC' gen-sysinfo.go |
259 sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
261 # The PATH_MAX constant.
262 if grep '^const _PATH_MAX ' gen-sysinfo.go >/dev/null 2>&1; then
263 echo 'const PathMax = _PATH_MAX' >> ${OUT}
266 # epoll constants.
267 grep '^const _EPOLL' gen-sysinfo.go |
268 grep -v EPOLLET |
269 sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
270 # Make sure EPOLLET is positive.
271 if grep '^const _EPOLLET = [0-9]' gen-sysinfo.go >/dev/null 2>&1; then
272 grep '^const _EPOLLET ' gen-sysinfo.go |
273 sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
274 else
275 echo "const EPOLLET = 0x80000000" >> ${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}
281 if ! grep '^const EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
282 echo "const EPOLL_CLOEXEC = 02000000" >> ${OUT}
285 # Prctl constants.
286 grep '^const _PR_' gen-sysinfo.go |
287 sed -e 's/^\(const \)_\(PR_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
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}
297 if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then
298 echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
300 if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then
301 echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
303 if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then
304 echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
306 if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then
307 echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
309 if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then
310 echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
312 if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then
313 echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
315 if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then
316 echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
318 if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then
319 echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
321 if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
322 echo "const PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
324 if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
325 echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
327 if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then
328 echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
330 if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then
331 echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
333 if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then
334 echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
336 if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then
337 echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
339 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
340 echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
342 if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
343 echo "const _PTRACE_TRACEME = 0" >> ${OUT}
346 # A helper function that prints a structure from gen-sysinfo.go with the first
347 # letter of the field names in upper case. $1 is the name of structure. If $2
348 # is not empty, the structure or type is renamed to $2.
349 upcase_fields () {
350 name="$1"
351 def=`grep "^type $name " gen-sysinfo.go`
352 fields=`echo $def | sed -e 's/^[^{]*{\(.*\)}$/\1/'`
353 prefix=`echo $def | sed -e 's/{.*//'`
354 if test "$2" != ""; then
355 prefix=`echo $prefix | sed -e "s/$1/$2/"`
357 if test "$fields" != ""; then
358 nfields=
359 while test -n "$fields"; do
360 field=`echo $fields | sed -e 's/^\([^;]*\);.*$/\1/'`
361 fields=`echo $fields | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
362 # capitalize the next character.
363 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
364 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
365 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
366 field="$f$r"
367 nfields="$nfields $field;"
368 done
369 echo "${prefix} {$nfields }"
373 # The registers returned by PTRACE_GETREGS. This is probably
374 # GNU/Linux specific; it should do no harm if there is no
375 # _user_regs_struct.
376 regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
377 if test "$regs" = ""; then
378 # mips*
379 regs=`grep '^type _pt_regs struct' gen-sysinfo.go || true`
381 if test "$regs" != ""; then
382 regs=`echo $regs | sed -e 's/type _pt_regs struct//'`
383 regs=`echo $regs |
384 sed -e 's/type __*user_regs_struct struct //' -e 's/[{}]//g'`
385 regs=`echo $regs | sed -e s'/^ *//'`
386 nregs=
387 while test -n "$regs"; do
388 field=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
389 regs=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
390 # Capitalize the first character of the field.
391 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
392 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
393 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
394 field="$f$r"
395 field=`echo "$field" | sed \
396 -e 's/__user_psw_struct/PtracePsw/' \
397 -e 's/__user_fpregs_struct/PtraceFpregs/' \
398 -e 's/__user_per_struct/PtracePer/'`
399 nregs="$nregs $field;"
400 done
401 echo "type PtraceRegs struct {$nregs }" >> ${OUT}
404 # Some basic types.
405 echo 'type Size_t _size_t' >> ${OUT}
406 echo "type Ssize_t _ssize_t" >> ${OUT}
407 echo "type Offset_t _libgo_off_t_type" >> ${OUT}
408 echo "type Mode_t _mode_t" >> ${OUT}
409 echo "type Pid_t _pid_t" >> ${OUT}
410 echo "type Uid_t _uid_t" >> ${OUT}
411 echo "type Gid_t _gid_t" >> ${OUT}
412 echo "type Socklen_t _socklen_t" >> ${OUT}
414 # The C int type.
415 sizeof_int=`grep '^const ___SIZEOF_INT__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
416 if test "$sizeof_int" = "4"; then
417 echo "type _C_int int32" >> ${OUT}
418 echo "type _C_uint uint32" >> ${OUT}
419 elif test "$sizeof_int" = "8"; then
420 echo "type _C_int int64" >> ${OUT}
421 echo "type _C_uint uint64" >> ${OUT}
422 else
423 echo 1>&2 "mksysinfo.sh: could not determine size of int (got $sizeof_int)"
424 exit 1
427 # The C long type, needed because that is the type that ptrace returns.
428 sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
429 if test "$sizeof_long" = "4"; then
430 echo "type _C_long int32" >> ${OUT}
431 echo "type _C_ulong uint32" >> ${OUT}
432 elif test "$sizeof_long" = "8"; then
433 echo "type _C_long int64" >> ${OUT}
434 echo "type _C_ulong uint64" >> ${OUT}
435 else
436 echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
437 exit 1
440 # The time_t type.
441 if grep '^type _time_t ' gen-sysinfo.go > /dev/null 2>&1; then
442 echo 'type Time_t _time_t' >> ${OUT}
445 # The time structures need special handling: we need to name the
446 # types, so that we can cast integers to the right types when
447 # assigning to the structures.
448 timeval=`grep '^type _timeval ' gen-sysinfo.go`
449 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
450 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
451 echo "type Timeval_sec_t = $timeval_sec" >> ${OUT}
452 echo "type Timeval_usec_t = $timeval_usec" >> ${OUT}
453 echo $timeval | \
454 sed -e 's/type _timeval /type Timeval /' \
455 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
456 -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
457 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
458 if test "$timespec" = ""; then
459 # IRIX 6.5 has __timespec instead.
460 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
462 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
463 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
464 echo "type Timespec_sec_t = $timespec_sec" >> ${OUT}
465 echo "type Timespec_nsec_t = $timespec_nsec" >> ${OUT}
466 echo $timespec | \
467 sed -e 's/^type ___timespec /type Timespec /' \
468 -e 's/^type _timespec /type Timespec /' \
469 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
470 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
472 timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
473 if test "$timestruc" = "type _timestruc_t _timespec"; then
474 echo "type Timestruc Timespec" >> ${OUT}
475 elif test "$timestruc" != ""; then
476 timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
477 timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
478 echo "type Timestruc_sec_t = $timestruc_sec" >> ${OUT}
479 echo "type Timestruc_nsec_t = $timestruc_nsec" >> ${OUT}
480 echo $timestruc | \
481 sed -e 's/^type _timestruc_t /type Timestruc /' \
482 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
483 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
486 # The tms struct.
487 grep '^type _tms ' gen-sysinfo.go | \
488 sed -e 's/type _tms/type Tms/' \
489 -e 's/tms_utime/Utime/' \
490 -e 's/tms_stime/Stime/' \
491 -e 's/tms_cutime/Cutime/' \
492 -e 's/tms_cstime/Cstime/' \
493 >> ${OUT}
495 # AIX uses st_timespec struct for stat.
496 grep '^type _st_timespec ' gen-sysinfo.go | \
497 sed -e 's/type _st_timespec /type StTimespec /' \
498 -e 's/tv_sec/Sec/' \
499 -e 's/tv_nsec/Nsec/' >> ${OUT}
501 # Special treatment of struct stat st_dev for GNU/Hurd
502 # /usr/include/i386-gnu/bits/stat.h: #define st_dev st_fsid
503 st_dev='-e s/st_dev/Dev/'
504 if grep 'define st_dev st_fsid' gen-sysinfo.go > /dev/null 2>&1; then
505 st_dev='-e s/st_fsid/Dev/'
508 # For historical reasons Go uses the suffix "timespec" instead of "tim" for
509 # stat_t's time fields on NetBSD.
510 st_times='-e s/st_atim/Atim/g -e s/st_mtim/Mtim/g -e s/st_ctim/Ctim/g'
511 if test "${GOOS}" = "netbsd"; then
512 st_times='-e s/st_atim/Atimespec/ -e s/st_mtim/Mtimespec/ -e s/st_ctim/Ctimespec/'
515 # The stat type.
516 # Prefer largefile variant if available.
517 stat=`grep '^type _stat64 ' gen-sysinfo.go || true`
518 if test "$stat" != ""; then
519 grep '^type _stat64 ' gen-sysinfo.go
520 else
521 grep '^type _stat ' gen-sysinfo.go
522 fi | sed -e 's/type _stat64/type Stat_t/' \
523 -e 's/type _stat/type Stat_t/' \
524 ${st_dev} \
525 ${st_times} \
526 -e 's/st_ino/Ino/g' \
527 -e 's/st_nlink/Nlink/' \
528 -e 's/st_mode/Mode/' \
529 -e 's/st_uid/Uid/' \
530 -e 's/st_gid/Gid/' \
531 -e 's/st_rdev/Rdev/' \
532 -e 's/st_size/Size/' \
533 -e 's/st_blksize/Blksize/' \
534 -e 's/st_blocks/Blocks/' \
535 -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
536 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
537 -e 's/\([^a-zA-Z0-9_]\)_st_timespec_t\([^a-zA-Z0-9_]\)/\1StTimespec\2/g' \
538 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
539 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
540 -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
541 >> ${OUT}
543 # The directory searching types.
544 # Prefer largefile variant if available.
545 dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true`
546 if test "$dirent" != ""; then
547 grep '^type _dirent64 ' gen-sysinfo.go
548 else
549 grep '^type _dirent ' gen-sysinfo.go
550 fi | sed -e 's/type _dirent64/type Dirent/' \
551 -e 's/type _dirent/type Dirent/' \
552 -e 's/d_name \[0+1\]/d_name [0+256]/' \
553 -e 's/d_name/Name/' \
554 -e 's/]int8/]byte/' \
555 -e 's/d_fileno/Fileno/' \
556 -e 's/d_ino/Ino/' \
557 -e 's/d_namlen/Namlen/' \
558 -e 's/d_off/Off/' \
559 -e 's/d_reclen/Reclen/' \
560 -e 's/d_type/Type/' \
561 >> ${OUT}
562 echo "type DIR _DIR" >> ${OUT}
564 # Values for d_type field in dirent.
565 grep '^const _DT_' gen-sysinfo.go |
566 sed -e 's/^\(const \)_\(DT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
568 # The rusage struct.
569 rusage=`grep '^type _rusage struct' gen-sysinfo.go`
570 if test "$rusage" != ""; then
571 # Remove anonymous unions from GNU/Linux <bits/resource.h>.
572 rusage=`echo $rusage | sed -e 's/Godump_[0-9][0-9]* struct {\([^}]*\)};/\1/g'`
573 rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
574 rusage=`echo $rusage | sed -e 's/^ *//'`
575 nrusage=
576 while test -n "$rusage"; do
577 field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
578 rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
579 # Drop the leading ru_, capitalize the next character.
580 field=`echo $field | sed -e 's/^ru_//'`
581 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
582 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
583 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
584 # Fix _timeval _timespec, and _timestruc_t.
585 r=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
586 r=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
587 r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
588 field="$f$r"
589 nrusage="$nrusage $field;"
590 done
591 echo "type Rusage struct {$nrusage }" >> ${OUT}
592 else
593 echo "type Rusage struct {}" >> ${OUT}
596 # The RUSAGE constants.
597 grep '^const _RUSAGE_' gen-sysinfo.go | \
598 sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
600 # The utsname struct.
601 grep '^type _utsname ' gen-sysinfo.go | \
602 sed -e 's/_utsname/Utsname/' \
603 -e 's/sysname/Sysname/' \
604 -e 's/nodename/Nodename/' \
605 -e 's/release/Release/' \
606 -e 's/version/Version/' \
607 -e 's/machine/Machine/' \
608 -e 's/domainname/Domainname/' \
609 >> ${OUT}
611 # The iovec struct.
612 iovec=`grep '^type _iovec ' gen-sysinfo.go`
613 iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
614 echo "type Iovec_len_t $iovec_len" >> ${OUT}
615 echo $iovec | \
616 sed -e 's/_iovec/Iovec/' \
617 -e 's/iov_base/Base/' \
618 -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
619 >> ${OUT}
621 # The msghdr struct.
622 msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
623 msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
624 echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
625 echo $msghdr | \
626 sed -e 's/_msghdr/Msghdr/' \
627 -e 's/msg_name/Name/' \
628 -e 's/msg_namelen/Namelen/' \
629 -e 's/msg_iov/Iov/' \
630 -e 's/msg_iovlen/Iovlen/' \
631 -e 's/_iovec/Iovec/' \
632 -e 's/msg_control/Control/' \
633 -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
634 -e 's/msg_flags/Flags/' \
635 >> ${OUT}
637 # The MSG_ flags for Msghdr.
638 grep '^const _MSG_' gen-sysinfo.go | \
639 sed -e 's/^\(const \)_\(MSG_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
641 # The cmsghdr struct.
642 cmsghdr=`grep '^type _cmsghdr ' gen-sysinfo.go`
643 if test -n "$cmsghdr"; then
644 cmsghdr_len=`echo $cmsghdr | sed -n -e 's/^.*cmsg_len \([^ ]*\);.*$/\1/p'`
645 echo "type Cmsghdr_len_t $cmsghdr_len" >> ${OUT}
646 echo "$cmsghdr" | \
647 sed -e 's/_cmsghdr/Cmsghdr/' \
648 -e 's/cmsg_len *[a-zA-Z0-9_]*/Len Cmsghdr_len_t/' \
649 -e 's/cmsg_level/Level/' \
650 -e 's/cmsg_type/Type/' \
651 -e 's/\[\]/[0]/' \
652 >> ${OUT}
655 # The SCM_ flags for Cmsghdr.
656 grep '^const _SCM_' gen-sysinfo.go | \
657 sed -e 's/^\(const \)_\(SCM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
659 # The ucred struct.
660 upcase_fields "_ucred" "Ucred" >> ${OUT} || true
662 # The ip_mreq struct.
663 grep '^type _ip_mreq ' gen-sysinfo.go | \
664 sed -e 's/_ip_mreq/IPMreq/' \
665 -e 's/imr_multiaddr/Multiaddr/' \
666 -e 's/imr_interface/Interface/' \
667 -e 's/_in_addr/[4]byte/g' \
668 >> ${OUT}
670 # We need IPMreq to compile the net package.
671 if ! grep 'type IPMreq ' ${OUT} >/dev/null 2>&1; then
672 echo 'type IPMreq struct { Multiaddr [4]byte; Interface [4]byte; }' >> ${OUT}
675 # The ipv6_mreq struct.
676 grep '^type _ipv6_mreq ' gen-sysinfo.go | \
677 sed -e 's/_ipv6_mreq/IPv6Mreq/' \
678 -e 's/ipv6mr_multiaddr/Multiaddr/' \
679 -e 's/ipv6mr_interface/Interface/' \
680 -e 's/_in6_addr/[16]byte/' \
681 >> ${OUT}
683 # We need IPv6Mreq to compile the net package.
684 if ! grep 'type IPv6Mreq ' ${OUT} >/dev/null 2>&1; then
685 echo 'type IPv6Mreq struct { Multiaddr [16]byte; Interface uint32; }' >> ${OUT}
688 # The ip_mreqn struct.
689 grep '^type _ip_mreqn ' gen-sysinfo.go | \
690 sed -e 's/_ip_mreqn/IPMreqn/' \
691 -e 's/imr_multiaddr/Multiaddr/' \
692 -e 's/imr_address/Address/' \
693 -e 's/imr_ifindex/Ifindex/' \
694 -e 's/_in_addr/[4]byte/g' \
695 >> ${OUT}
697 # We need IPMreq to compile the net package.
698 if ! grep 'type IPMreqn ' ${OUT} >/dev/null 2>&1; then
699 echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT}
702 # The icmp6_filter struct.
703 grep '^type _icmp6_filter ' gen-sysinfo.go | \
704 sed -e 's/_icmp6_filter/ICMPv6Filter/' \
705 -e 's/data/Data/' \
706 -e 's/filt/Filt/' \
707 >> ${OUT}
709 # We need ICMPv6Filter to compile the syscall package.
710 if ! grep 'type ICMPv6Filter ' ${OUT} > /dev/null 2>&1; then
711 echo 'type ICMPv6Filter struct { Data [8]uint32 }' >> ${OUT}
714 # The ip6_mtuinfo struct.
715 grep '^type _ip6_mtuinfo ' gen-sysinfo.go | \
716 sed -e 's/_ip6_mtuinfo/IPv6MTUInfo/' \
717 -e 's/ip6m_addr/Addr/' \
718 -e 's/_sockaddr_in6/RawSockaddrInet6/' \
719 -e 's/ip6m_mtu/Mtu/' \
720 >> ${OUT}
722 # We need IPv6MTUInfo to compile the syscall package.
723 if ! grep 'type IPv6MTUInfo ' ${OUT} >/dev/null 2>&1; then
724 echo 'type IPv6MTUInfo struct { Addr RawSockaddrInet6; Mtu uint32; }' >> ${OUT}
726 if ! grep 'const _sizeof_ip6_mtuinfo = ' ${OUT} >/dev/null 2>&1; then
727 echo 'const SizeofIPv6MTUInfo = 32' >> ${OUT}
730 # Try to guess the type to use for fd_set.
731 fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
732 fds_bits_type="_C_long"
733 if test "$fd_set" != ""; then
734 fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
736 echo "type fds_bits_type $fds_bits_type" >> ${OUT}
738 # The addrinfo struct.
739 grep '^type _addrinfo ' gen-sysinfo.go | \
740 sed -e 's/_addrinfo/Addrinfo/g' \
741 -e 's/ ai_/ Ai_/g' \
742 >> ${OUT}
744 # The addrinfo and nameinfo flags and errors.
745 grep '^const _AI_' gen-sysinfo.go | \
746 sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
747 grep '^const _EAI_' gen-sysinfo.go | \
748 sed -e 's/^\(const \)_\(EAI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
749 grep '^const _NI_' gen-sysinfo.go | \
750 sed -e 's/^\(const \)_\(NI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
752 # If nothing else defined EAI_OVERFLOW, make sure it has a value.
753 if ! grep "const EAI_OVERFLOW " ${OUT} >/dev/null 2>&1; then
754 echo "const EAI_OVERFLOW = 0" >> ${OUT}
757 # The passwd struct.
758 grep '^type _passwd ' gen-sysinfo.go | \
759 sed -e 's/_passwd/Passwd/' \
760 -e 's/ pw_/ Pw_/g' \
761 >> ${OUT}
763 # The group struct.
764 grep '^type _group ' gen-sysinfo.go | \
765 sed -e 's/_group/Group/' \
766 -e 's/ gr_/ Gr_/g' \
767 >> ${OUT}
769 # The ioctl flags for the controlling TTY.
770 grep '^const _TIOC' gen-sysinfo.go | \
771 grep -v '_val =' | \
772 sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
773 grep '^const _TUNSET' gen-sysinfo.go | \
774 grep -v '_val =' | \
775 sed -e 's/^\(const \)_\(TUNSET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
776 # We need TIOCGWINSZ.
777 if ! grep '^const TIOCGWINSZ' ${OUT} >/dev/null 2>&1; then
778 if grep '^const _TIOCGWINSZ_val' ${OUT} >/dev/null 2>&1; then
779 echo 'const TIOCGWINSZ = _TIOCGWINSZ_val' >> ${OUT}
782 if ! grep '^const TIOCSWINSZ' ${OUT} >/dev/null 2>&1; then
783 if grep '^const _TIOCSWINSZ_val' ${OUT} >/dev/null 2>&1; then
784 echo 'const TIOCSWINSZ = _TIOCSWINSZ_val' >> ${OUT}
787 if ! grep '^const TIOCNOTTY' ${OUT} >/dev/null 2>&1; then
788 if grep '^const _TIOCNOTTY_val' ${OUT} >/dev/null 2>&1; then
789 echo 'const TIOCNOTTY = _TIOCNOTTY_val' >> ${OUT}
792 if ! grep '^const TIOCSCTTY' ${OUT} >/dev/null 2>&1; then
793 if grep '^const _TIOCSCTTY_val' ${OUT} >/dev/null 2>&1; then
794 echo 'const TIOCSCTTY = _TIOCSCTTY_val' >> ${OUT}
797 if ! grep '^const TIOCGPGRP' ${OUT} >/dev/null 2>&1; then
798 if grep '^const _TIOCGPGRP_val' ${OUT} >/dev/null 2>&1; then
799 echo 'const TIOCGPGRP = _TIOCGPGRP_val' >> ${OUT}
802 if ! grep '^const TIOCSPGRP' ${OUT} >/dev/null 2>&1; then
803 if grep '^const _TIOCSPGRP_val' ${OUT} >/dev/null 2>&1; then
804 echo 'const TIOCSPGRP = _TIOCSPGRP_val' >> ${OUT}
807 if ! grep '^const TIOCGPTN' ${OUT} >/dev/null 2>&1; then
808 if grep '^const _TIOCGPTN_val' ${OUT} >/dev/null 2>&1; then
809 echo 'const TIOCGPTN = _TIOCGPTN_val' >> ${OUT}
812 if ! grep '^const TIOCSPTLCK' ${OUT} >/dev/null 2>&1; then
813 if grep '^const _TIOCSPTLCK_val' ${OUT} >/dev/null 2>&1; then
814 echo 'const TIOCSPTLCK = _TIOCSPTLCK_val' >> ${OUT}
817 if ! grep '^const TIOCGDEV' ${OUT} >/dev/null 2>&1; then
818 if grep '^const _TIOCGDEV_val' ${OUT} >/dev/null 2>&1; then
819 echo 'const TIOCGDEV = _TIOCGDEV_val' >> ${OUT}
822 if ! grep '^const TIOCSIG' ${OUT} >/dev/null 2>&1; then
823 if grep '^const _TIOCSIG_val' ${OUT} >/dev/null 2>&1; then
824 echo 'const TIOCSIG = _TIOCSIG_val' >> ${OUT}
828 if ! grep '^const TUNSETNOCSUM' ${OUT} >/dev/null 2>&1; then
829 if grep '^const _TUNSETNOCSUM_val' ${OUT} >/dev/null 2>&1; then
830 echo 'const TUNSETNOCSUM = _TUNSETNOCSUM_val' >> ${OUT}
834 if ! grep '^const TUNSETDEBUG' ${OUT} >/dev/null 2>&1; then
835 if grep '^const _TUNSETDEBUG_val' ${OUT} >/dev/null 2>&1; then
836 echo 'const TUNSETDEBUG = _TUNSETDEBUG_val' >> ${OUT}
840 if ! grep '^const TUNSETIFF' ${OUT} >/dev/null 2>&1; then
841 if grep '^const _TUNSETIFF_val' ${OUT} >/dev/null 2>&1; then
842 echo 'const TUNSETIFF = _TUNSETIFF_val' >> ${OUT}
846 if ! grep '^const TUNSETPERSIST' ${OUT} >/dev/null 2>&1; then
847 if grep '^const _TUNSETPERSIST_val' ${OUT} >/dev/null 2>&1; then
848 echo 'const TUNSETPERSIST = _TUNSETPERSIST_val' >> ${OUT}
852 if ! grep '^const TUNSETOWNER' ${OUT} >/dev/null 2>&1; then
853 if grep '^const _TUNSETOWNER_val' ${OUT} >/dev/null 2>&1; then
854 echo 'const TUNSETOWNER = _TUNSETOWNER_val' >> ${OUT}
858 if ! grep '^const TUNSETLINK' ${OUT} >/dev/null 2>&1; then
859 if grep '^const _TUNSETLINK_val' ${OUT} >/dev/null 2>&1; then
860 echo 'const TUNSETLINK = _TUNSETLINK_val' >> ${OUT}
864 if ! grep '^const TUNSETGROUP' ${OUT} >/dev/null 2>&1; then
865 if grep '^const _TUNSETGROUP_val' ${OUT} >/dev/null 2>&1; then
866 echo 'const TUNSETGROUP = _TUNSETGROUP_val' >> ${OUT}
870 if ! grep '^const TUNGETFEATURES' ${OUT} >/dev/null 2>&1; then
871 if grep '^const _TUNGETFEATURES_val' ${OUT} >/dev/null 2>&1; then
872 echo 'const TUNGETFEATURES = _TUNGETFEATURES_val' >> ${OUT}
876 if ! grep '^const TUNSETOFFLOAD' ${OUT} >/dev/null 2>&1; then
877 if grep '^const _TUNSETOFFLOAD_val' ${OUT} >/dev/null 2>&1; then
878 echo 'const TUNSETOFFLOAD = _TUNSETOFFLOAD_val' >> ${OUT}
882 if ! grep '^const TUNSETTXFILTER' ${OUT} >/dev/null 2>&1; then
883 if grep '^const _TUNSETTXFILTER_val' ${OUT} >/dev/null 2>&1; then
884 echo 'const TUNSETTXFILTER = _TUNSETTXFILTER_val' >> ${OUT}
888 if ! grep '^const TUNGETIFF' ${OUT} >/dev/null 2>&1; then
889 if grep '^const _TUNGETIFF_val' ${OUT} >/dev/null 2>&1; then
890 echo 'const TUNGETIFF = _TUNGETIFF_val' >> ${OUT}
894 if ! grep '^const TUNGETSNDBUF' ${OUT} >/dev/null 2>&1; then
895 if grep '^const _TUNGETSNDBUF_val' ${OUT} >/dev/null 2>&1; then
896 echo 'const TUNGETSNDBUF = _TUNGETSNDBUF_val' >> ${OUT}
900 if ! grep '^const TUNSETSNDBUF' ${OUT} >/dev/null 2>&1; then
901 if grep '^const _TUNSETSNDBUF_val' ${OUT} >/dev/null 2>&1; then
902 echo 'const TUNSETSNDBUF = _TUNSETSNDBUF_val' >> ${OUT}
906 if ! grep '^const TUNATTACHFILTER' ${OUT} >/dev/null 2>&1; then
907 if grep '^const _TUNATTACHFILTER_val' ${OUT} >/dev/null 2>&1; then
908 echo 'const TUNATTACHFILTER = _TUNATTACHFILTER_val' >> ${OUT}
912 if ! grep '^const TUNDETACHFILTER' ${OUT} >/dev/null 2>&1; then
913 if grep '^const _TUNDETACHFILTER_val' ${OUT} >/dev/null 2>&1; then
914 echo 'const TUNDETACHFILTER = _TUNDETACHFILTER_val' >> ${OUT}
918 if ! grep '^const TUNGETVNETHDRSZ' ${OUT} >/dev/null 2>&1; then
919 if grep '^const _TUNGETVNETHDRSZ_val' ${OUT} >/dev/null 2>&1; then
920 echo 'const TUNGETVNETHDRSZ = _TUNGETVNETHDRSZ_val' >> ${OUT}
924 if ! grep '^const TUNSETVNETHDRSZ' ${OUT} >/dev/null 2>&1; then
925 if grep '^const _TUNSETVNETHDRSZ_val' ${OUT} >/dev/null 2>&1; then
926 echo 'const TUNSETVNETHDRSZ = _TUNSETVNETHDRSZ_val' >> ${OUT}
930 if ! grep '^const TUNSETQUEUE' ${OUT} >/dev/null 2>&1; then
931 if grep '^const _TUNSETQUEUE_val' ${OUT} >/dev/null 2>&1; then
932 echo 'const TUNSETQUEUE = _TUNSETQUEUE_val' >> ${OUT}
937 if ! grep '^const TUNSETIFINDEX' ${OUT} >/dev/null 2>&1; then
938 if grep '^const _TUNSETIFINDEX_val' ${OUT} >/dev/null 2>&1; then
939 echo 'const TUNSETIFINDEX = _TUNSETIFINDEX_val' >> ${OUT}
943 if ! grep '^const TUNGETFILTER' ${OUT} >/dev/null 2>&1; then
944 if grep '^const _TUNGETFILTER_val' ${OUT} >/dev/null 2>&1; then
945 echo 'const TUNGETFILTER = _TUNGETFILTER_val' >> ${OUT}
949 # The ioctl flags for terminal control
950 grep '^const _TC[GS]ET' gen-sysinfo.go | grep -v _val | \
951 sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
952 if ! grep '^const TCGETS' ${OUT} >/dev/null 2>&1; then
953 if grep '^const _TCGETS_val' ${OUT} >/dev/null 2>&1; then
954 echo 'const TCGETS = _TCGETS_val' >> ${OUT}
957 if ! grep '^const TCSETS' ${OUT} >/dev/null 2>&1; then
958 if grep '^const _TCSETS_val' ${OUT} >/dev/null 2>&1; then
959 echo 'const TCSETS = _TCSETS_val' >> ${OUT}
963 # ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but
964 # needs handling in syscalls.exec.go.
965 if ! grep '^const _TIOCSCTTY ' gen-sysinfo.go >/dev/null 2>&1; then
966 if grep '^const _TIOCNXCL ' gen-sysinfo.go >/dev/null 2>&1; then
967 echo "const TIOCSCTTY = TIOCNXCL" >> ${OUT}
971 # If nothing else defined TIOCSCTTY, make sure it has a value.
972 if ! grep "const TIOCSCTTY " ${OUT} >/dev/null 2>&1; then
973 echo "const TIOCSCTTY = 0" >> ${OUT}
976 # The nlmsghdr struct.
977 grep '^type _nlmsghdr ' gen-sysinfo.go | \
978 sed -e 's/_nlmsghdr/NlMsghdr/' \
979 -e 's/nlmsg_len/Len/' \
980 -e 's/nlmsg_type/Type/' \
981 -e 's/nlmsg_flags/Flags/' \
982 -e 's/nlmsg_seq/Seq/' \
983 -e 's/nlmsg_pid/Pid/' \
984 >> ${OUT}
986 # The nlmsg flags and operators.
987 grep '^const _NLM' gen-sysinfo.go | \
988 sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
990 # NLMSG_HDRLEN is defined as an expression using sizeof.
991 if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev/null 2>&1; then
992 if grep '^const _sizeof_nlmsghdr ' ${OUT} > /dev/null 2>&1; then
993 echo 'const NLMSG_HDRLEN = (_sizeof_nlmsghdr + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1)' >> ${OUT}
997 # The rtmsg struct.
998 grep '^type _rtmsg ' gen-sysinfo.go | \
999 sed -e 's/_rtmsg/RtMsg/' \
1000 -e 's/rtm_family/Family/' \
1001 -e 's/rtm_dst_len/Dst_len/' \
1002 -e 's/rtm_src_len/Src_len/' \
1003 -e 's/rtm_tos/Tos/' \
1004 -e 's/rtm_table/Table/' \
1005 -e 's/rtm_protocol/Protocol/' \
1006 -e 's/rtm_scope/Scope/' \
1007 -e 's/rtm_type/Type/' \
1008 -e 's/rtm_flags/Flags/' \
1009 >> ${OUT}
1011 # The rtgenmsg struct.
1012 grep '^type _rtgenmsg ' gen-sysinfo.go | \
1013 sed -e 's/_rtgenmsg/RtGenmsg/' \
1014 -e 's/rtgen_family/Family/' \
1015 >> ${OUT}
1017 # The rt_msghdr struct.
1018 grep '^type _rt_msghdr ' gen-sysinfo.go | \
1019 sed -e 's/_rt_msghdr/RtMsghdr/g' \
1020 -e 's/rtm_msglen/Msglen/' \
1021 -e 's/rtm_version/Version/' \
1022 -e 's/rtm_type/Type/' \
1023 -e 's/rtm_index/Index/' \
1024 -e 's/rtm_flags/Flags/' \
1025 -e 's/rtm_addrs/Addrs/' \
1026 -e 's/rtm_pid/Pid/' \
1027 -e 's/rtm_seq/Seq/' \
1028 -e 's/rtm_errno/Errno/' \
1029 -e 's/rtm_use/Use/' \
1030 -e 's/rtm_inits/Inits/' \
1031 -e 's/rtm_rmx/Rmx/' \
1032 -e 's/_rt_metrics/RtMetrics/' \
1033 >> ${OUT}
1035 # The rt_metrics struct.
1036 grep '^type _rt_metrics ' gen-sysinfo.go | \
1037 sed -e 's/_rt_metrics/RtMetrics/g' \
1038 -e 's/rmx_locks/Locks/' \
1039 -e 's/rmx_mtu/Mtu/' \
1040 -e 's/rmx_hopcount/Hopcount/' \
1041 -e 's/rmx_recvpipe/Recvpipe/' \
1042 -e 's/rmx_sendpipe/Sendpipe/' \
1043 -e 's/rmx_ssthresh/Ssthresh/' \
1044 -e 's/rmx_rtt/Rtt/' \
1045 -e 's/rmx_rttvar/Rttvar/' \
1046 -e 's/rmx_expire/Expire/' \
1047 -e 's/rmx_pksent/Pksent/' \
1048 >> ${OUT}
1050 # The routing message flags.
1051 grep '^const _RT_' gen-sysinfo.go | \
1052 sed -e 's/^\(const \)_\(RT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1053 grep '^const _RTA' gen-sysinfo.go | \
1054 sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1055 grep '^const _RTF' gen-sysinfo.go | \
1056 sed -e 's/^\(const \)_\(RTF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1057 grep '^const _RTCF' gen-sysinfo.go | \
1058 sed -e 's/^\(const \)_\(RTCF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1059 grep '^const _RTM' gen-sysinfo.go | \
1060 sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1061 if test "${GOOS}" = "netbsd"; then
1062 if ! grep "RTM_RESOLVE" ${OUT} >/dev/null 2>&1; then
1063 # NetBSD 8.0 removed RTM_RESOLVE, but it is part of the syscall package's
1064 # stable API, so add it manually.
1065 echo "const RTM_RESOLVE = 0xb" >> ${OUT}
1068 grep '^const _RTN' gen-sysinfo.go | \
1069 sed -e 's/^\(const \)_\(RTN[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1070 grep '^const _RTPROT' gen-sysinfo.go | \
1071 sed -e 's/^\(const \)_\(RTPROT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1073 # The ifinfomsg struct.
1074 grep '^type _ifinfomsg ' gen-sysinfo.go | \
1075 sed -e 's/_ifinfomsg/IfInfomsg/' \
1076 -e 's/ifi_family/Family/' \
1077 -e 's/ifi_type/Type/' \
1078 -e 's/ifi_index/Index/' \
1079 -e 's/ifi_flags/Flags/' \
1080 -e 's/ifi_change/Change/' \
1081 >> ${OUT}
1083 # The if_msghdr struct. Upstream uses inconsistent capitalization for this type
1084 # on AIX, so we do too.
1085 ifmsghdr_name=IfMsghdr
1086 if test "${GOOS}" = "aix"; then
1087 ifmsghdr_name=IfMsgHdr
1089 grep '^type _if_msghdr ' gen-sysinfo.go | \
1090 sed -e "s/_if_msghdr/${ifmsghdr_name}/" \
1091 -e 's/ifm_msglen/Msglen/' \
1092 -e 's/ifm_version/Version/' \
1093 -e 's/ifm_type/Type/' \
1094 -e 's/ifm_addrs/Addrs/' \
1095 -e 's/ifm_flags/Flags/' \
1096 -e 's/ifm_index/Index/' \
1097 -e 's/ifm_addrlen/Addrlen/' \
1098 >> ${OUT}
1100 # The if_announcemsghdr struct.
1101 grep '^type _if_announcemsghdr ' gen-sysinfo.go | \
1102 sed -e 's/_if_announcemsghdr/IfAnnounceMsghdr/g' \
1103 -e 's/ifan_msglen/Msglen/' \
1104 -e 's/ifan_version/Version/' \
1105 -e 's/ifan_type/Type/' \
1106 -e 's/ifan_index/Index/' \
1107 -e 's/ifan_name/Name/' \
1108 -e 's/ifan_what/What/' \
1109 >> ${OUT}
1111 # The interface information types and flags.
1112 grep '^const _IFA' gen-sysinfo.go | \
1113 sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1114 grep '^const _IFLA' gen-sysinfo.go | \
1115 sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1116 grep '^const _IFF' gen-sysinfo.go | \
1117 sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1118 grep '^const _IFNAMSIZ' gen-sysinfo.go | \
1119 sed -e 's/^\(const \)_\(IFNAMSIZ[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1120 grep '^const _SIOC' gen-sysinfo.go | \
1121 grep -v '_val =' | \
1122 sed -e 's/^\(const \)_\(SIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1124 if ! grep '^const SIOCGIFMTU' ${OUT} >/dev/null 2>&1; then
1125 if grep '^const _SIOCGIFMTU_val' ${OUT} >/dev/null 2>&1; then
1126 echo 'const SIOCGIFMTU = _SIOCGIFMTU_val' >> ${OUT}
1130 # The ifaddrmsg struct.
1131 grep '^type _ifaddrmsg ' gen-sysinfo.go | \
1132 sed -e 's/_ifaddrmsg/IfAddrmsg/' \
1133 -e 's/ifa_family/Family/' \
1134 -e 's/ifa_prefixlen/Prefixlen/' \
1135 -e 's/ifa_flags/Flags/' \
1136 -e 's/ifa_scope/Scope/' \
1137 -e 's/ifa_index/Index/' \
1138 >> ${OUT}
1140 # The ifa_msghdr struct.
1141 grep '^type _ifa_msghdr ' gen-sysinfo.go | \
1142 sed -e 's/_ifa_msghdr/IfaMsghdr/g' \
1143 -e 's/ifam_msglen/Msglen/' \
1144 -e 's/ifam_version/Version/' \
1145 -e 's/ifam_type/Type/' \
1146 -e 's/ifam_addrs/Addrs/' \
1147 -e 's/ifam_flags/Flags/' \
1148 -e 's/ifam_metric/Metric/' \
1149 -e 's/ifam_index/Index/' \
1150 >> ${OUT}
1152 # The rtattr struct.
1153 grep '^type _rtattr ' gen-sysinfo.go | \
1154 sed -e 's/_rtattr/RtAttr/' \
1155 -e 's/rta_len/Len/' \
1156 -e 's/rta_type/Type/' \
1157 >> ${OUT}
1159 # The bpf_version struct.
1160 grep '^type _bpf_version ' gen-sysinfo.go | \
1161 sed -e 's/_bpf_version/BpfVersion/g' \
1162 -e 's/bv_major/Major/' \
1163 -e 's/bv_minor/Minor/' \
1164 >> ${OUT}
1166 # The bpf_stat struct.
1167 grep '^type _bpf_stat ' gen-sysinfo.go | \
1168 sed -e 's/_bpf_stat/BpfStat/g' \
1169 -e 's/bs_recv/Recv/' \
1170 -e 's/bs_drop/Drop/' \
1171 -e 's/bs_capt/Capt/' \
1172 -e 's/bs_padding/Padding/' \
1173 >> ${OUT}
1175 # The bpf_insn struct.
1176 grep '^type _bpf_insn ' gen-sysinfo.go | \
1177 sed -e 's/_bpf_insn/BpfInsn/g' \
1178 -e 's/code/Code/' \
1179 -e 's/jt/Jt/' \
1180 -e 's/jf/Jf/' \
1181 -e 's/k/K/' \
1182 >> ${OUT}
1184 # The bpf_program struct.
1185 grep '^type _bpf_program ' gen-sysinfo.go | \
1186 sed -e 's/_bpf_program/BpfProgram/g' \
1187 -e 's/bf_len/Len/' \
1188 -e 's/bf_insns/Insns/' \
1189 -e 's/_bpf_insn/BpfInsn/' \
1190 >> ${OUT}
1192 # The BPF ioctl constants.
1193 grep '^const _BIOC' gen-sysinfo.go | \
1194 grep -v '_val =' | \
1195 sed -e 's/^\(const \)_\(BIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1196 for c in BIOCFLUSH BIOCGBLEN BIOCGDLT BIOCGETIF BIOCGHDRCMPLT BIOCGRTIMEOUT \
1197 BIOCGSTATS BIOCIMMEDIATE BIOCPROMISC BIOCSBLEN BIOCSDLT BIOCSETF \
1198 BIOCSETIF BIOCSHDRCMPLT BIOCSRTIMEOUT BIOCVERSION
1200 if ! grep "^const ${c}" ${OUT} >/dev/null 2>&1; then
1201 if grep "^const _${c}_val" ${OUT} >/dev/null 2>&1; then
1202 echo "const ${c} = _${c}_val" >> ${OUT}
1205 done
1207 # The in_pktinfo struct.
1208 grep '^type _in_pktinfo ' gen-sysinfo.go | \
1209 sed -e 's/_in_pktinfo/Inet4Pktinfo/' \
1210 -e 's/ipi_ifindex/Ifindex/' \
1211 -e 's/ipi_spec_dst/Spec_dst/' \
1212 -e 's/ipi_addr/Addr/' \
1213 -e 's/_in_addr/[4]byte/g' \
1214 >> ${OUT}
1216 # The in6_pktinfo struct.
1217 grep '^type _in6_pktinfo ' gen-sysinfo.go | \
1218 sed -e 's/_in6_pktinfo/Inet6Pktinfo/' \
1219 -e 's/ipi6_addr/Addr/' \
1220 -e 's/ipi6_ifindex/Ifindex/' \
1221 -e 's/_in6_addr/[16]byte/' \
1222 >> ${OUT}
1224 # The termios struct.
1225 grep '^type _termios ' gen-sysinfo.go | \
1226 sed -e 's/_termios/Termios/' \
1227 -e 's/c_iflag/Iflag/' \
1228 -e 's/c_oflag/Oflag/' \
1229 -e 's/c_cflag/Cflag/' \
1230 -e 's/c_lflag/Lflag/' \
1231 -e 's/c_line/Line/' \
1232 -e 's/c_cc/Cc/' \
1233 -e 's/c_ispeed/Ispeed/' \
1234 -e 's/c_ospeed/Ospeed/' \
1235 >> ${OUT}
1237 # The termios constants.
1238 for n in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \
1239 IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \
1240 OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 CS5 CS6 CS7 CS8 TABDLY \
1241 BSDLY VTDLY FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL \
1242 CLOCAL LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE ECHO ECHOE ECHOK \
1243 ECHONL ECHOCTL ECHOPRT ECHOKE DEFECHO FLUSHO NOFLSH TOSTOP PENDIN IEXTEN \
1244 VINTR VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 VSWTCH VSTART VSTOP \
1245 VSUSP VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS TCSANOW TCSADRAIN \
1246 TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON TCIOFF TCION B0 B50 \
1247 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 \
1248 B38400 B57600 B115200 B230400 B460800 B500000 B576000 B921600 B1000000 \
1249 B1152000 B1500000 B2000000 B2500000 B3000000 B3500000 B4000000; do
1251 grep "^const _$n " gen-sysinfo.go | \
1252 sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1253 done
1255 # The mount flags
1256 grep '^const _MNT_' gen-sysinfo.go |
1257 sed -e 's/^\(const \)_\(MNT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1258 grep '^const _MS_' gen-sysinfo.go |
1259 sed -e 's/^\(const \)_\(MS_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1261 # The fallocate flags.
1262 grep '^const _FALLOC_' gen-sysinfo.go |
1263 sed -e 's/^\(const \)_\(FALLOC_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1265 # The statfs struct.
1266 # Prefer largefile variant if available.
1267 # CentOS 5 does not have f_flags, so pull from f_spare.
1268 statfs=`grep '^type _statfs64 ' gen-sysinfo.go || true`
1269 if test "$statfs" = ""; then
1270 statfs=`grep '^type _statfs ' gen-sysinfo.go || true`
1272 if ! echo "$statfs" | grep f_flags >/dev/null 2>&1; then
1273 statfs=`echo "$statfs" | sed -e 's/f_spare \[4+1\]\([^ ;]*\)/f_flags \1; f_spare [3+1]\1/'`
1275 echo "$statfs" | sed -e 's/type _statfs64/type Statfs_t/' \
1276 -e 's/type _statfs/type Statfs_t/' \
1277 -e 's/f_type/Type/' \
1278 -e 's/f_bsize/Bsize/' \
1279 -e 's/f_blocks/Blocks/' \
1280 -e 's/f_bfree/Bfree/' \
1281 -e 's/f_bavail/Bavail/' \
1282 -e 's/f_files/Files/' \
1283 -e 's/f_ffree/Ffree/' \
1284 -e 's/f_fsid/Fsid/' \
1285 -e 's/f_namelen/Namelen/' \
1286 -e 's/f_frsize/Frsize/' \
1287 -e 's/f_flags/Flags/' \
1288 -e 's/f_spare/Spare/' \
1289 >> ${OUT}
1291 # The timex struct.
1292 timex=`grep '^type _timex ' gen-sysinfo.go || true`
1293 if test "$timex" = ""; then
1294 timex=`grep '^// type _timex ' gen-sysinfo.go || true`
1295 if test "$timex" != ""; then
1296 timex=`echo $timex | sed -e 's|// ||' -e 's/INVALID-bit-field/int32/g'`
1299 if test "$timex" != ""; then
1300 echo "$timex" | \
1301 sed -e 's/_timex/Timex/' \
1302 -e 's/modes/Modes/' \
1303 -e 's/offset/Offset/' \
1304 -e 's/freq/Freq/' \
1305 -e 's/maxerror/Maxerror/' \
1306 -e 's/esterror/Esterror/' \
1307 -e 's/status/Status/' \
1308 -e 's/constant/Constant/' \
1309 -e 's/precision/Precision/' \
1310 -e 's/tolerance/Tolerance/' \
1311 -e 's/ time / Time /' \
1312 -e 's/tick/Tick/' \
1313 -e 's/ppsfreq/Ppsfreq/' \
1314 -e 's/jitter/Jitter/' \
1315 -e 's/shift/Shift/' \
1316 -e 's/stabil/Stabil/' \
1317 -e 's/jitcnt/Jitcnt/' \
1318 -e 's/calcnt/Calcnt/' \
1319 -e 's/errcnt/Errcnt/' \
1320 -e 's/stbcnt/Stbcnt/' \
1321 -e 's/tai/Tai/' \
1322 -e 's/_timeval/Timeval/' \
1323 >> ${OUT}
1326 # The rlimit struct.
1327 # On systems that use syscall/libcall_posix_largefile.go, use rlimit64
1328 # if it exists.
1329 rlimit="_rlimit"
1330 if test "${GOOS}" = "aix" || test "${GOOS}" = "linux" || (test "${GOOS}" = "solaris" && (test "${GOARCH}" = "386" || test "${GOARCH}" = "sparc")); then
1331 if grep '^type _rlimit64 ' gen-sysinfo.go > /dev/null 2>&1; then
1332 rlimit="_rlimit64"
1335 grep "^type ${rlimit} " gen-sysinfo.go | \
1336 sed -e "s/${rlimit}/Rlimit/" \
1337 -e 's/rlim_cur/Cur/' \
1338 -e 's/rlim_max/Max/' \
1339 >> ${OUT}
1341 # The RLIMIT constants.
1342 grep '^const _RLIMIT_' gen-sysinfo.go |
1343 sed -e 's/^\(const \)_\(RLIMIT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1344 grep '^const _RLIM_' gen-sysinfo.go |
1345 grep -v '^const _RLIM_INFINITY ' |
1346 sed -e 's/^\(const \)_\(RLIM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1347 rliminf=""
1348 if test "${rlimit}" = "_rlimit64" && grep '^const _RLIM64_INFINITY ' gen-sysinfo.go > /dev/null 2>&1; then
1349 rliminf=`grep '^const _RLIM64_INFINITY ' gen-sysinfo.go | sed -e 's/.* //'`
1350 else
1351 rliminf=`grep '^const _RLIM_INFINITY ' gen-sysinfo.go | sed -e 's/.* //'`
1353 # For compatibility with the gc syscall package, treat 0xffffffffffffffff as -1.
1354 if test "$rliminf" = "0xffffffffffffffff"; then
1355 echo "const RLIM_INFINITY = -1" >> ${OUT}
1356 elif test -n "$rliminf"; then
1357 echo "const RLIM_INFINITY = $rliminf" >> ${OUT}
1360 # The sysinfo struct.
1361 grep '^type _sysinfo ' gen-sysinfo.go | \
1362 sed -e 's/_sysinfo/Sysinfo_t/' \
1363 -e 's/uptime/Uptime/' \
1364 -e 's/loads/Loads/' \
1365 -e 's/totalram/Totalram/' \
1366 -e 's/freeram/Freeram/' \
1367 -e 's/sharedram/Sharedram/' \
1368 -e 's/bufferram/Bufferram/' \
1369 -e 's/totalswap/Totalswap/' \
1370 -e 's/freeswap/Freeswap/' \
1371 -e 's/procs/Procs/' \
1372 -e 's/totalhigh/Totalhigh/' \
1373 -e 's/freehigh/Freehigh/' \
1374 -e 's/mem_unit/Unit/' \
1375 >> ${OUT}
1377 # The utimbuf struct.
1378 grep '^type _utimbuf ' gen-sysinfo.go | \
1379 sed -e 's/_utimbuf/Utimbuf/' \
1380 -e 's/actime/Actime/' \
1381 -e 's/modtime/Modtime/' \
1382 >> ${OUT}
1384 # The LOCK flags for flock.
1385 grep '^const _LOCK_' gen-sysinfo.go |
1386 sed -e 's/^\(const \)_\(LOCK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1388 # The PRIO constants.
1389 grep '^const _PRIO_' gen-sysinfo.go | \
1390 sed -e 's/^\(const \)_\(PRIO_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1392 # The GNU/Linux LINUX_REBOOT flags.
1393 grep '^const _LINUX_REBOOT_' gen-sysinfo.go |
1394 sed -e 's/^\(const \)_\(LINUX_REBOOT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1396 # The GNU/Linux sock_filter struct.
1397 grep '^type _sock_filter ' gen-sysinfo.go | \
1398 sed -e 's/_sock_filter/SockFilter/' \
1399 -e 's/code/Code/' \
1400 -e 's/jt/Jt/' \
1401 -e 's/jf/Jf/' \
1402 -e 's/k /K /' \
1403 >> ${OUT}
1405 # The GNU/Linux sock_fprog struct.
1406 grep '^type _sock_fprog ' gen-sysinfo.go | \
1407 sed -e 's/_sock_fprog/SockFprog/' \
1408 -e 's/len/Len/' \
1409 -e 's/filter/Filter/' \
1410 -e 's/_sock_filter/SockFilter/' \
1411 >> ${OUT}
1413 # The GNU/Linux filter flags.
1414 grep '^const _BPF_' gen-sysinfo.go | \
1415 sed -e 's/^\(const \)_\(BPF_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1417 # The GNU/Linux nlattr struct.
1418 grep '^type _nlattr ' gen-sysinfo.go | \
1419 sed -e 's/_nlattr/NlAttr/' \
1420 -e 's/nla_len/Len/' \
1421 -e 's/nla_type/Type/' \
1422 >> ${OUT}
1424 # The GNU/Linux nlmsgerr struct.
1425 grep '^type _nlmsgerr ' gen-sysinfo.go | \
1426 sed -e 's/_nlmsgerr/NlMsgerr/' \
1427 -e 's/error/Error/' \
1428 -e 's/msg/Msg/' \
1429 -e 's/_nlmsghdr/NlMsghdr/' \
1430 >> ${OUT}
1432 # The GNU/Linux rtnexthop struct.
1433 grep '^type _rtnexthop ' gen-sysinfo.go | \
1434 sed -e 's/_rtnexthop/RtNexthop/' \
1435 -e 's/rtnh_len/Len/' \
1436 -e 's/rtnh_flags/Flags/' \
1437 -e 's/rtnh_hops/Hops/' \
1438 -e 's/rtnh_ifindex/Ifindex/' \
1439 >> ${OUT}
1441 # The GNU/Linux netlink flags.
1442 grep '^const _NETLINK_' gen-sysinfo.go | \
1443 sed -e 's/^\(const \)_\(NETLINK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1444 grep '^const _NLA_' gen-sysinfo.go | grep -v '_val =' | \
1445 sed -e 's/^\(const \)_\(NLA_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1447 if ! grep '^const NLA_HDRLEN' ${OUT} >/dev/null 2>&1; then
1448 if grep '^const _NLA_HDRLEN_val' ${OUT} >/dev/null 2>&1; then
1449 echo 'const NLA_HDRLEN = _NLA_HDRLEN_val' >> ${OUT}
1453 # The GNU/Linux packet socket flags.
1454 grep '^const _PACKET_' gen-sysinfo.go | \
1455 sed -e 's/^\(const \)_\(PACKET_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1457 # The GNU/Linux inotify_event struct.
1458 grep '^type _inotify_event ' gen-sysinfo.go | \
1459 sed -e 's/_inotify_event/InotifyEvent/' \
1460 -e 's/wd/Wd/' \
1461 -e 's/mask/Mask/' \
1462 -e 's/cookie/Cookie/' \
1463 -e 's/len/Len/' \
1464 -e 's/name/Name/' \
1465 -e 's/\[\]/[0]/' \
1466 -e 's/\[0\]byte/[0]int8/' \
1467 >> ${OUT}
1469 # The GNU/Linux CLONE flags.
1470 grep '^const _CLONE_' gen-sysinfo.go | \
1471 sed -e 's/^\(const \)_\(CLONE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1472 # We need some CLONE constants that are not defined in older versions
1473 # of glibc.
1474 if ! grep '^const CLONE_NEWUSER ' ${OUT} > /dev/null 2>&1; then
1475 echo "const CLONE_NEWUSER = 0x10000000" >> ${OUT}
1477 if ! grep '^const CLONE_NEWNET ' ${OUT} > /dev/null 2>&1; then
1478 echo "const CLONE_NEWNET = 0x40000000" >> ${OUT}
1481 # Struct sizes.
1482 set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \
1483 ifaddrmsg IfAddrmsg ifa_msghdr IfaMsghdr ifinfomsg IfInfomsg \
1484 if_msghdr IfMsghdr in_pktinfo Inet4Pktinfo in6_pktinfo Inet6Pktinfo \
1485 inotify_event InotifyEvent linger Linger msghdr Msghdr nlattr NlAttr \
1486 nlmsgerr NlMsgerr nlmsghdr NlMsghdr rtattr RtAttr rt_msghdr RtMsghdr \
1487 rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \
1488 sock_filter SockFilter sock_fprog SockFprog ucred Ucred \
1489 icmp6_filter ICMPv6Filter ip6_mtuinfo IPv6MTUInfo
1490 while test $# != 0; do
1491 nc=$1
1492 ngo=$2
1493 shift
1494 shift
1495 if grep "^const _sizeof_$nc =" gen-sysinfo.go >/dev/null 2>&1; then
1496 echo "const Sizeof$ngo = _sizeof_$nc" >> ${OUT}
1498 done
1500 # In order to compile the net package, we need some sizes to exist
1501 # even if the types do not.
1502 if ! grep 'const SizeofIPMreq ' ${OUT} >/dev/null 2>&1; then
1503 echo 'const SizeofIPMreq = 8' >> ${OUT}
1505 if ! grep 'const SizeofIPv6Mreq ' ${OUT} >/dev/null 2>&1; then
1506 echo 'const SizeofIPv6Mreq = 20' >> ${OUT}
1508 if ! grep 'const SizeofIPMreqn ' ${OUT} >/dev/null 2>&1; then
1509 echo 'const SizeofIPMreqn = 12' >> ${OUT}
1511 if ! grep 'const SizeofICMPv6Filter ' ${OUT} >/dev/null 2>&1; then
1512 echo 'const SizeofICMPv6Filter = 32' >> ${OUT}
1515 # Type 'uint128' is needed in a couple of type definitions on arm64,such
1516 # as _user_fpsimd_struct, _elf_fpregset_t, etc.
1517 if ! grep '^type uint128' ${OUT} > /dev/null 2>&1; then
1518 echo "type uint128 [16]byte" >> ${OUT}
1521 exit $?