]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgo/mksysinfo.sh
runtime: fix assembly syntax
[thirdparty/gcc.git] / libgo / mksysinfo.sh
CommitLineData
e440a328 1#!/bin/sh
2
3# Copyright 2009 The Go Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style
5# license that can be found in the LICENSE file.
6
bfac90c5 7# Create sysinfo.go from gen-sysinfo.go and errno.i.
e440a328 8
9# This shell script creates the sysinfo.go file which holds types and
bfac90c5 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.
e440a328 13
bfac90c5 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.
e440a328 17
e440a328 18OUT=tmp-sysinfo.go
19
20set -e
21
e440a328 22echo 'package syscall' > ${OUT}
49b4e44b 23echo 'import "unsafe"' >> ${OUT}
70a51116 24echo 'type _ unsafe.Pointer' >> ${OUT}
e440a328 25
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.
30grep -v '^// ' gen-sysinfo.go | \
31 grep -v '^func' | \
5657a3c3 32 grep -v '^var' | \
e440a328 33 grep -v '^type _timeval ' | \
e0519e05 34 grep -v '^type _timespec_t ' | \
35 grep -v '^type _timespec ' | \
976f97ad 36 grep -v '^type _timestruc_t ' | \
e440a328 37 grep -v '^type _epoll_' | \
47e8a478 38 grep -v '^type _*locale[_ ]' | \
e440a328 39 grep -v 'in6_addr' | \
40 grep -v 'sockaddr_in6' | \
41 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
e0519e05 42 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
43 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
976f97ad 44 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
e440a328 45 >> ${OUT}
46
03118c21 47# On AIX, the _arpcom struct, is filtered by the above grep sequence, as it as
48# a field of type _in6_addr, but other types depend on _arpcom, so we need to
49# put it back.
50grep '^type _arpcom ' gen-sysinfo.go | \
51 sed -e 's/_in6_addr/[16]byte/' >> ${OUT}
52
b8405b7e 53# Same on Solaris for _mld_hdr_t.
54grep '^type _mld_hdr_t ' gen-sysinfo.go | \
55 sed -e 's/_in6_addr/[16]byte/' >> ${OUT}
56
46bc1fe2 57# The errno constants. These get type Errno.
c6ad139d 58egrep '#define E[A-Z0-9_]+ [0-9E]' errno.i | \
46bc1fe2 59 sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(_\1)/' >> ${OUT}
e440a328 60
c6ad139d 61# Workaround for GNU/Hurd _EMIG_* errors having negative values
62egrep '#define E[A-Z0-9_]+ -[0-9]' errno.i | \
63 sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(-_\1)/' >> ${OUT}
64
e440a328 65# The O_xxx flags.
69db433d 66egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
e440a328 67 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
976f97ad 68if ! grep '^const O_ASYNC' ${OUT} >/dev/null 2>&1; then
69 echo "const O_ASYNC = 0" >> ${OUT}
70fi
e440a328 71if ! grep '^const O_CLOEXEC' ${OUT} >/dev/null 2>&1; then
72 echo "const O_CLOEXEC = 0" >> ${OUT}
73fi
74
af06d5b4 75# The os package requires F_DUPFD_CLOEXEC to be defined.
76if ! grep '^const F_DUPFD_CLOEXEC' ${OUT} >/dev/null 2>&1; then
77 echo "const F_DUPFD_CLOEXEC = 0" >> ${OUT}
78fi
79
cb80685b 80# The internal/poll package requires F_GETPIPE_SZ to be defined.
81if ! grep '^const F_GETPIPE_SZ' ${OUT} >/dev/null 2>&1; then
82 echo "const F_GETPIPE_SZ = 0" >> ${OUT}
83fi
84
03118c21 85# AIX 7.1 is a 64 bits value for _FCLOEXEC (referenced by O_CLOEXEC)
86# which leads to a constant overflow when using O_CLOEXEC in some
87# go code. Issue wan not present in 6.1 (no O_CLOEXEC) and is no
88# more present in 7.2 (_FCLOEXEC is a 32 bit value).
89if test "${GOOS}" = "aix" && `oslevel | grep -q "^7.1"`; then
90 sed -e 's/const __FCLOEXEC = .*/const __FCLOEXEC = 0/' ${OUT} > ${OUT}-2
91 mv ${OUT}-2 ${OUT}
92fi
93
7982f4b5 94# These flags can be lost on i386 GNU/Linux when using
95# -D_FILE_OFFSET_BITS=64, because we see "#define F_SETLK F_SETLK64"
96# before we see the definition of F_SETLK64.
97for flag in F_GETLK F_SETLK F_SETLKW; do
98 if ! grep "^const ${flag} " ${OUT} >/dev/null 2>&1 \
99 && grep "^const ${flag}64 " ${OUT} >/dev/null 2>&1; then
100 echo "const ${flag} = ${flag}64" >> ${OUT}
101 fi
102done
103
a756a05a 104# The Flock_t struct for fcntl.
105grep '^type _flock ' gen-sysinfo.go | \
106 sed -e 's/type _flock/type Flock_t/' \
107 -e 's/l_type/Type/' \
108 -e 's/l_whence/Whence/' \
109 -e 's/l_start/Start/' \
110 -e 's/l_len/Len/' \
111 -e 's/l_pid/Pid/' \
112 >> ${OUT}
113
e440a328 114# The signal numbers.
115grep '^const _SIG[^_]' gen-sysinfo.go | \
116 grep -v '^const _SIGEV_' | \
2d2d80b8 117 sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = Signal(_\2)/' >> ${OUT}
447002cc 118if ! grep '^const SIGPOLL ' ${OUT} >/dev/null 2>&1; then
119 if grep '^const SIGIO ' ${OUT} > /dev/null 2>&1; then
120 echo "const SIGPOLL = SIGIO" >> ${OUT}
121 fi
122fi
123if ! grep '^const SIGCLD ' ${OUT} >/dev/null 2>&1; then
124 if grep '^const SIGCHLD ' ${OUT} >/dev/null 2>&1; then
125 echo "const SIGCLD = SIGCHLD" >> ${OUT}
126 fi
127fi
e440a328 128
129# The syscall numbers. We force the names to upper case.
130grep '^const _SYS_' gen-sysinfo.go | \
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
136
c6ad139d 137# Special treatment of SYS_IOCTL for GNU/Hurd.
138if ! grep '^const SYS_IOCTL' ${OUT} > /dev/null 2>&1; then
139 echo "const SYS_IOCTL = 0" >> ${OUT}
140fi
141
52b67c41 142# The GNU/Linux support wants to use SYS_GETDENTS64 if available.
143if ! grep '^const SYS_GETDENTS ' ${OUT} >/dev/null 2>&1; then
144 echo "const SYS_GETDENTS = 0" >> ${OUT}
145fi
146if ! grep '^const SYS_GETDENTS64 ' ${OUT} >/dev/null 2>&1; then
147 echo "const SYS_GETDENTS64 = 0" >> ${OUT}
148fi
149
e60ae8c7 150# The syscall package wants the geteuid system call number. It isn't
151# defined on Alpha, which only provides the getresuid system call.
152if ! grep '^const SYS_GETEUID ' ${OUT} >/dev/null 2>&1; then
153 echo "const SYS_GETEUID = 0" >> ${OUT}
154fi
155
e440a328 156# Stat constants.
157grep '^const _S_' gen-sysinfo.go | \
158 sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
35a02ae0 159
160# Mmap constants.
161grep '^const _PROT_' gen-sysinfo.go | \
162 sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
163grep '^const _MAP_' gen-sysinfo.go | \
164 sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
c54eb9a5 165grep '^const _MADV_' gen-sysinfo.go | \
166 sed -e 's/^\(const \)_\(MADV_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
87e44028 167grep '^const _MCL_' gen-sysinfo.go | \
168 sed -e 's/^\(const \)_\(MCL_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
e440a328 169
170# Process status constants.
171grep '^const _W' gen-sysinfo.go |
172 sed -e 's/^\(const \)_\(W[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
173# WSTOPPED was introduced in glibc 2.3.4.
174if ! 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}
179 fi
180fi
181if 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}
184fi
c2a11183 185# On GNU/Linux the os package requires WEXITED and WNOWAIT.
186if test "${GOOS}" = "linux"; then
187 if ! grep '^const WEXITED = ' ${OUT} >/dev/null 2>&1; then
188 echo 'const WEXITED = 4' >> ${OUT}
189 fi
190 if ! grep '^const WNOWAIT = ' ${OUT} >/dev/null 2>&1; then
191 echo 'const WNOWAIT = 0x01000000' >> ${OUT}
192 fi
193fi
e440a328 194
195# Networking constants.
f450da21 196egrep '^const _(AF|ARPHRD|ETH|IN|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
e440a328 197 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
198grep '^const _SOMAXCONN' gen-sysinfo.go |
199 sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
200 >> ${OUT}
201grep '^const _SHUT_' gen-sysinfo.go |
202 sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
203
c235a48c 204# The net package requires some const definitions.
604e7f91 205for m in IP_PKTINFO IPV6_V6ONLY IPPROTO_IPV6 IPV6_JOIN_GROUP IPV6_LEAVE_GROUP IPV6_TCLASS SO_REUSEPORT; do
c235a48c 206 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
207 echo "const $m = 0" >> ${OUT}
208 fi
209done
12ebd629 210for m in SOCK_CLOEXEC SOCK_NONBLOCK; do
211 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
212 echo "const $m = -1" >> ${OUT}
213 fi
214done
e39e9de5 215
697aef8c 216# The syscall package requires AF_LOCAL.
217if ! grep '^const AF_LOCAL ' ${OUT} >/dev/null 2>&1; then
218 if grep '^const AF_UNIX ' ${OUT} >/dev/null 2>&1; then
219 echo "const AF_LOCAL = AF_UNIX" >> ${OUT}
220 fi
221fi
222
3c58765b 223# The syscall package requires _AT_FDCWD, but doesn't export it.
224if ! grep '^const _AT_FDCWD = ' ${OUT} >/dev/null 2>&1; then
225 echo "const _AT_FDCWD = -100" >> ${OUT}
226fi
227
be239ed2 228# sysconf constants.
229grep '^const __SC' gen-sysinfo.go |
230 sed -e 's/^\(const \)__\(SC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
231
e440a328 232# pathconf constants.
233grep '^const __PC' gen-sysinfo.go |
234 sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
235
62c34bfb 236# The PATH_MAX constant.
7eaf7f7f 237if grep '^const _PATH_MAX ' gen-sysinfo.go >/dev/null 2>&1; then
62c34bfb 238 echo 'const PathMax = _PATH_MAX' >> ${OUT}
7eaf7f7f 239fi
62c34bfb 240
46bc1fe2 241# epoll constants.
242grep '^const _EPOLL' gen-sysinfo.go |
090dff10 243 grep -v EPOLLET |
46bc1fe2 244 sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
090dff10 245# Make sure EPOLLET is positive.
cba66200 246if grep '^const _EPOLLET = [0-9]' gen-sysinfo.go >/dev/null 2>&1; then
090dff10 247 grep '^const _EPOLLET ' gen-sysinfo.go |
248 sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
249else
250 echo "const EPOLLET = 0x80000000" >> ${OUT}
251fi
57e75709 252# Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
e440a328 253if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
254 echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
255fi
57e75709 256if ! grep '^const EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
257 echo "const EPOLL_CLOEXEC = 02000000" >> ${OUT}
258fi
e440a328 259
422eaae5 260# Prctl constants.
261grep '^const _PR_' gen-sysinfo.go |
262 sed -e 's/^\(const \)_\(PR_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
263
d477de41 264# Ptrace constants.
265grep '^const _PTRACE' gen-sysinfo.go |
266 sed -e 's/^\(const \)_\(PTRACE[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
267# We need some ptrace options that are not defined in older versions
268# of glibc.
269if ! grep '^const PTRACE_SETOPTIONS' ${OUT} > /dev/null 2>&1; then
270 echo "const PTRACE_SETOPTIONS = 0x4200" >> ${OUT}
e440a328 271fi
272if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then
273 echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
274fi
275if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then
276 echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
277fi
278if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then
279 echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
280fi
281if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then
282 echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
283fi
284if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then
285 echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
286fi
287if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then
288 echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
289fi
290if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then
291 echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
292fi
293if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then
294 echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
295fi
296if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
433697c4 297 echo "const PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
e440a328 298fi
299if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
300 echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
301fi
302if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then
303 echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
304fi
305if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then
306 echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
307fi
308if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then
309 echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
310fi
311if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then
312 echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
313fi
314if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
315 echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
316fi
976f97ad 317if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
034cf891 318 echo "const _PTRACE_TRACEME = 0" >> ${OUT}
976f97ad 319fi
e440a328 320
141eb62b 321# A helper function that prints a structure from gen-sysinfo.go with the first
322# letter of the field names in upper case. $1 is the name of structure. If $2
323# is not empty, the structure or type is renamed to $2.
324upcase_fields () {
325 name="$1"
cba66200 326 def=`grep "^type $name " gen-sysinfo.go`
141eb62b 327 fields=`echo $def | sed -e 's/^[^{]*{\(.*\)}$/\1/'`
328 prefix=`echo $def | sed -e 's/{.*//'`
329 if test "$2" != ""; then
330 prefix=`echo $prefix | sed -e "s/$1/$2/"`
331 fi
332 if test "$fields" != ""; then
333 nfields=
334 while test -n "$fields"; do
335 field=`echo $fields | sed -e 's/^\([^;]*\);.*$/\1/'`
336 fields=`echo $fields | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
337 # capitalize the next character.
338 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
339 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
340 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
341 field="$f$r"
342 nfields="$nfields $field;"
343 done
344 echo "${prefix} {$nfields }"
345 fi
346}
347
e440a328 348# The registers returned by PTRACE_GETREGS. This is probably
976f97ad 349# GNU/Linux specific; it should do no harm if there is no
350# _user_regs_struct.
7549a79a 351regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
c241a61c 352if test "$regs" = ""; then
17e02461 353 # mips*
354 regs=`grep '^type _pt_regs struct' gen-sysinfo.go || true`
141eb62b 355fi
e440a328 356if test "$regs" != ""; then
6b49e67f 357 regs=`echo $regs | sed -e 's/type _pt_regs struct//'`
141eb62b 358 regs=`echo $regs |
359 sed -e 's/type __*user_regs_struct struct //' -e 's/[{}]//g'`
e440a328 360 regs=`echo $regs | sed -e s'/^ *//'`
361 nregs=
362 while test -n "$regs"; do
363 field=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
364 regs=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
365 # Capitalize the first character of the field.
366 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
367 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
368 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
369 field="$f$r"
141eb62b 370 field=`echo "$field" | sed \
371 -e 's/__user_psw_struct/PtracePsw/' \
372 -e 's/__user_fpregs_struct/PtraceFpregs/' \
373 -e 's/__user_per_struct/PtracePer/'`
e440a328 374 nregs="$nregs $field;"
375 done
376 echo "type PtraceRegs struct {$nregs }" >> ${OUT}
377fi
378
379# Some basic types.
380echo 'type Size_t _size_t' >> ${OUT}
381echo "type Ssize_t _ssize_t" >> ${OUT}
382if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then
383 echo "type Offset_t _off64_t" >> ${OUT}
384else
385 echo "type Offset_t _off_t" >> ${OUT}
386fi
387echo "type Mode_t _mode_t" >> ${OUT}
388echo "type Pid_t _pid_t" >> ${OUT}
389echo "type Uid_t _uid_t" >> ${OUT}
390echo "type Gid_t _gid_t" >> ${OUT}
391echo "type Socklen_t _socklen_t" >> ${OUT}
392
754ed3a8 393# The C int type.
394sizeof_int=`grep '^const ___SIZEOF_INT__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
395if test "$sizeof_int" = "4"; then
396 echo "type _C_int int32" >> ${OUT}
280f3681 397 echo "type _C_uint uint32" >> ${OUT}
754ed3a8 398elif test "$sizeof_int" = "8"; then
399 echo "type _C_int int64" >> ${OUT}
280f3681 400 echo "type _C_uint uint64" >> ${OUT}
754ed3a8 401else
402 echo 1>&2 "mksysinfo.sh: could not determine size of int (got $sizeof_int)"
403 exit 1
404fi
405
406# The C long type, needed because that is the type that ptrace returns.
e440a328 407sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
408if test "$sizeof_long" = "4"; then
409 echo "type _C_long int32" >> ${OUT}
0509fa0e 410 echo "type _C_ulong uint32" >> ${OUT}
e440a328 411elif test "$sizeof_long" = "8"; then
412 echo "type _C_long int64" >> ${OUT}
0509fa0e 413 echo "type _C_ulong uint64" >> ${OUT}
e440a328 414else
415 echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
416 exit 1
417fi
418
f15dfc33 419# Solaris 2 needs _u?pad128_t, but its default definition in terms of long
420# double is commented by -fdump-go-spec.
421if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
422 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
423fi
424if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
425 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
426fi
427
9e4aaf6e 428# The time_t type.
429if grep '^type _time_t ' gen-sysinfo.go > /dev/null 2>&1; then
430 echo 'type Time_t _time_t' >> ${OUT}
431fi
432
e440a328 433# The time structures need special handling: we need to name the
434# types, so that we can cast integers to the right types when
435# assigning to the structures.
436timeval=`grep '^type _timeval ' gen-sysinfo.go`
437timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
438timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
439echo "type Timeval_sec_t $timeval_sec" >> ${OUT}
440echo "type Timeval_usec_t $timeval_usec" >> ${OUT}
441echo $timeval | \
442 sed -e 's/type _timeval /type Timeval /' \
443 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
444 -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
524b52f8 445timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
446if test "$timespec" = ""; then
447 # IRIX 6.5 has __timespec instead.
448 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
449fi
e440a328 450timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
451timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
452echo "type Timespec_sec_t $timespec_sec" >> ${OUT}
453echo "type Timespec_nsec_t $timespec_nsec" >> ${OUT}
454echo $timespec | \
e0519e05 455 sed -e 's/^type ___timespec /type Timespec /' \
456 -e 's/^type _timespec /type Timespec /' \
e440a328 457 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
458 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
459
976f97ad 460timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
461if test "$timestruc" != ""; then
462 timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
463 timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
464 echo "type Timestruc_sec_t $timestruc_sec" >> ${OUT}
465 echo "type Timestruc_nsec_t $timestruc_nsec" >> ${OUT}
466 echo $timestruc | \
467 sed -e 's/^type _timestruc_t /type Timestruc /' \
468 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
469 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
470fi
471
41884b67 472# The tms struct.
473grep '^type _tms ' gen-sysinfo.go | \
474 sed -e 's/type _tms/type Tms/' \
475 -e 's/tms_utime/Utime/' \
476 -e 's/tms_stime/Stime/' \
477 -e 's/tms_cutime/Cutime/' \
478 -e 's/tms_cstime/Cstime/' \
479 >> ${OUT}
480
31ca46e3 481# AIX uses st_timespec struct for stat.
482grep '^type _st_timespec ' gen-sysinfo.go | \
483 sed -e 's/type _st_timespec /type StTimespec /' \
484 -e 's/tv_sec/Sec/' \
485 -e 's/tv_nsec/Nsec/' >> ${OUT}
486
c6ad139d 487# Special treatment of struct stat st_dev for GNU/Hurd
488# /usr/include/i386-gnu/bits/stat.h: #define st_dev st_fsid
93b422b4 489st_dev='-e s/st_dev/Dev/'
c6ad139d 490if grep 'define st_dev st_fsid' gen-sysinfo.go > /dev/null 2>&1; then
93b422b4 491 st_dev='-e s/st_fsid/Dev/'
c6ad139d 492fi
493
e440a328 494# The stat type.
1633da9c 495# Prefer largefile variant if available.
496stat=`grep '^type _stat64 ' gen-sysinfo.go || true`
497if test "$stat" != ""; then
498 grep '^type _stat64 ' gen-sysinfo.go
499else
500 grep '^type _stat ' gen-sysinfo.go
69db433d 501fi | sed -e 's/type _stat64/type Stat_t/' \
502 -e 's/type _stat/type Stat_t/' \
93b422b4 503 ${st_dev} \
1633da9c 504 -e 's/st_ino/Ino/g' \
505 -e 's/st_nlink/Nlink/' \
506 -e 's/st_mode/Mode/' \
507 -e 's/st_uid/Uid/' \
508 -e 's/st_gid/Gid/' \
509 -e 's/st_rdev/Rdev/' \
510 -e 's/st_size/Size/' \
511 -e 's/st_blksize/Blksize/' \
512 -e 's/st_blocks/Blocks/' \
62c34bfb 513 -e 's/st_atim/Atim/' \
514 -e 's/st_mtim/Mtim/' \
515 -e 's/st_ctim/Ctim/' \
1633da9c 516 -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
e0519e05 517 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
31ca46e3 518 -e 's/\([^a-zA-Z0-9_]\)_st_timespec_t\([^a-zA-Z0-9_]\)/\1StTimespec\2/g' \
e0519e05 519 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
1633da9c 520 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
4c90aa9a 521 -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
1633da9c 522 >> ${OUT}
e440a328 523
524# The directory searching types.
1633da9c 525# Prefer largefile variant if available.
526dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true`
527if test "$dirent" != ""; then
528 grep '^type _dirent64 ' gen-sysinfo.go
529else
530 grep '^type _dirent ' gen-sysinfo.go
69db433d 531fi | sed -e 's/type _dirent64/type Dirent/' \
532 -e 's/type _dirent/type Dirent/' \
1633da9c 533 -e 's/d_name \[0+1\]/d_name [0+256]/' \
534 -e 's/d_name/Name/' \
535 -e 's/]int8/]byte/' \
536 -e 's/d_ino/Ino/' \
e8b32921 537 -e 's/d_namlen/Namlen/' \
1633da9c 538 -e 's/d_off/Off/' \
539 -e 's/d_reclen/Reclen/' \
540 -e 's/d_type/Type/' \
541 >> ${OUT}
e440a328 542echo "type DIR _DIR" >> ${OUT}
543
f450da21 544# Values for d_type field in dirent.
545grep '^const _DT_' gen-sysinfo.go |
546 sed -e 's/^\(const \)_\(DT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
547
e440a328 548# The rusage struct.
549rusage=`grep '^type _rusage struct' gen-sysinfo.go`
550if test "$rusage" != ""; then
a5067d00 551 # Remove anonymous unions from GNU/Linux <bits/resource.h>.
141eb62b 552 rusage=`echo $rusage | sed -e 's/Godump_[0-9][0-9]* struct {\([^}]*\)};/\1/g'`
6e8b08cf 553 rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
554 rusage=`echo $rusage | sed -e 's/^ *//'`
e440a328 555 nrusage=
556 while test -n "$rusage"; do
557 field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
558 rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
559 # Drop the leading ru_, capitalize the next character.
560 field=`echo $field | sed -e 's/^ru_//'`
561 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
562 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
563 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
976f97ad 564 # Fix _timeval _timespec, and _timestruc_t.
e440a328 565 r=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
566 r=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
976f97ad 567 r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
e440a328 568 field="$f$r"
569 nrusage="$nrusage $field;"
570 done
571 echo "type Rusage struct {$nrusage }" >> ${OUT}
37d6b690 572else
573 echo "type Rusage struct {}" >> ${OUT}
e440a328 574fi
575
84911de8 576# The RUSAGE constants.
577grep '^const _RUSAGE_' gen-sysinfo.go | \
578 sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
579
e440a328 580# The utsname struct.
581grep '^type _utsname ' gen-sysinfo.go | \
582 sed -e 's/_utsname/Utsname/' \
583 -e 's/sysname/Sysname/' \
584 -e 's/nodename/Nodename/' \
585 -e 's/release/Release/' \
586 -e 's/version/Version/' \
587 -e 's/machine/Machine/' \
588 -e 's/domainname/Domainname/' \
589 >> ${OUT}
590
48080209 591# The iovec struct.
592iovec=`grep '^type _iovec ' gen-sysinfo.go`
593iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
594echo "type Iovec_len_t $iovec_len" >> ${OUT}
595echo $iovec | \
596 sed -e 's/_iovec/Iovec/' \
597 -e 's/iov_base/Base/' \
598 -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
599 >> ${OUT}
600
601# The msghdr struct.
602msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
603msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
604echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
605echo $msghdr | \
606 sed -e 's/_msghdr/Msghdr/' \
607 -e 's/msg_name/Name/' \
608 -e 's/msg_namelen/Namelen/' \
609 -e 's/msg_iov/Iov/' \
610 -e 's/msg_iovlen/Iovlen/' \
611 -e 's/_iovec/Iovec/' \
612 -e 's/msg_control/Control/' \
613 -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
614 -e 's/msg_flags/Flags/' \
615 >> ${OUT}
616
82ca2551 617# The MSG_ flags for Msghdr.
618grep '^const _MSG_' gen-sysinfo.go | \
619 sed -e 's/^\(const \)_\(MSG_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
620
621# The cmsghdr struct.
622cmsghdr=`grep '^type _cmsghdr ' gen-sysinfo.go`
623if test -n "$cmsghdr"; then
624 cmsghdr_len=`echo $cmsghdr | sed -n -e 's/^.*cmsg_len \([^ ]*\);.*$/\1/p'`
625 echo "type Cmsghdr_len_t $cmsghdr_len" >> ${OUT}
626 echo "$cmsghdr" | \
627 sed -e 's/_cmsghdr/Cmsghdr/' \
628 -e 's/cmsg_len *[a-zA-Z0-9_]*/Len Cmsghdr_len_t/' \
629 -e 's/cmsg_level/Level/' \
630 -e 's/cmsg_type/Type/' \
b5676c94 631 -e 's/\[\]/[0]/' \
82ca2551 632 >> ${OUT}
82ca2551 633fi
634
635# The SCM_ flags for Cmsghdr.
636grep '^const _SCM_' gen-sysinfo.go | \
637 sed -e 's/^\(const \)_\(SCM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
638
639# The ucred struct.
8a1b0e9b 640upcase_fields "_ucred" "Ucred" >> ${OUT} || true
82ca2551 641
fa5d125b 642# The ip_mreq struct.
31c6ec42 643grep '^type _ip_mreq ' gen-sysinfo.go | \
49b4e44b 644 sed -e 's/_ip_mreq/IPMreq/' \
31c6ec42 645 -e 's/imr_multiaddr/Multiaddr/' \
646 -e 's/imr_interface/Interface/' \
647 -e 's/_in_addr/[4]byte/g' \
648 >> ${OUT}
649
c235a48c 650# We need IPMreq to compile the net package.
651if ! grep 'type IPMreq ' ${OUT} >/dev/null 2>&1; then
652 echo 'type IPMreq struct { Multiaddr [4]byte; Interface [4]byte; }' >> ${OUT}
d477de41 653fi
654
fa5d125b 655# The ipv6_mreq struct.
656grep '^type _ipv6_mreq ' gen-sysinfo.go | \
657 sed -e 's/_ipv6_mreq/IPv6Mreq/' \
658 -e 's/ipv6mr_multiaddr/Multiaddr/' \
659 -e 's/ipv6mr_interface/Interface/' \
660 -e 's/_in6_addr/[16]byte/' \
661 >> ${OUT}
662
c235a48c 663# We need IPv6Mreq to compile the net package.
664if ! grep 'type IPv6Mreq ' ${OUT} >/dev/null 2>&1; then
665 echo 'type IPv6Mreq struct { Multiaddr [16]byte; Interface uint32; }' >> ${OUT}
666fi
667
422eaae5 668# The ip_mreqn struct.
669grep '^type _ip_mreqn ' gen-sysinfo.go | \
670 sed -e 's/_ip_mreqn/IPMreqn/' \
671 -e 's/imr_multiaddr/Multiaddr/' \
672 -e 's/imr_address/Address/' \
673 -e 's/imr_ifindex/Ifindex/' \
674 -e 's/_in_addr/[4]byte/g' \
675 >> ${OUT}
676
677# We need IPMreq to compile the net package.
678if ! grep 'type IPMreqn ' ${OUT} >/dev/null 2>&1; then
679 echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT}
680fi
681
0ce10ea1 682# The icmp6_filter struct.
683grep '^type _icmp6_filter ' gen-sysinfo.go | \
684 sed -e 's/_icmp6_filter/ICMPv6Filter/' \
685 -e 's/data/Data/' \
686 -e 's/filt/Filt/' \
687 >> ${OUT}
688
689# We need ICMPv6Filter to compile the syscall package.
690if ! grep 'type ICMPv6Filter ' ${OUT} > /dev/null 2>&1; then
691 echo 'type ICMPv6Filter struct { Data [8]uint32 }' >> ${OUT}
692fi
693
0c6c84a9 694# The ip6_mtuinfo struct.
695grep '^type _ip6_mtuinfo ' gen-sysinfo.go | \
696 sed -e 's/_ip6_mtuinfo/IPv6MTUInfo/' \
697 -e 's/ip6m_addr/Addr/' \
698 -e 's/_sockaddr_in6/RawSockaddrInet6/' \
699 -e 's/ip6m_mtu/Mtu/' \
700 >> ${OUT}
701
3c58765b 702# We need IPv6MTUInfo to compile the syscall package.
703if ! grep 'type IPv6MTUInfo ' ${OUT} >/dev/null 2>&1; then
704 echo 'type IPv6MTUInfo struct { Addr RawSockaddrInet6; Mtu uint32; }' >> ${OUT}
705fi
706if ! grep 'const _sizeof_ip6_mtuinfo = ' ${OUT} >/dev/null 2>&1; then
707 echo 'const SizeofIPv6MTUInfo = 32' >> ${OUT}
708fi
709
310f6f45 710# Try to guess the type to use for fd_set.
711fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
712fds_bits_type="_C_long"
713if test "$fd_set" != ""; then
714 fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
715fi
716echo "type fds_bits_type $fds_bits_type" >> ${OUT}
717
84911de8 718# The addrinfo struct.
719grep '^type _addrinfo ' gen-sysinfo.go | \
720 sed -e 's/_addrinfo/Addrinfo/g' \
721 -e 's/ ai_/ Ai_/g' \
722 >> ${OUT}
723
4a3da3a8 724# The addrinfo and nameinfo flags and errors.
84911de8 725grep '^const _AI_' gen-sysinfo.go | \
726 sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
46bc1fe2 727grep '^const _EAI_' gen-sysinfo.go | \
728 sed -e 's/^\(const \)_\(EAI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
4a3da3a8 729grep '^const _NI_' gen-sysinfo.go | \
730 sed -e 's/^\(const \)_\(NI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
84911de8 731
03118c21 732# If nothing else defined EAI_OVERFLOW, make sure it has a value.
733if ! grep "const EAI_OVERFLOW " ${OUT} >/dev/null 2>&1; then
734 echo "const EAI_OVERFLOW = 0" >> ${OUT}
735fi
736
84911de8 737# The passwd struct.
738grep '^type _passwd ' gen-sysinfo.go | \
739 sed -e 's/_passwd/Passwd/' \
740 -e 's/ pw_/ Pw_/g' \
741 >> ${OUT}
742
be239ed2 743# The group struct.
744grep '^type _group ' gen-sysinfo.go | \
745 sed -e 's/_group/Group/' \
746 -e 's/ gr_/ Gr_/g' \
747 >> ${OUT}
748
49b4e44b 749# The ioctl flags for the controlling TTY.
750grep '^const _TIOC' gen-sysinfo.go | \
7cb04ba7 751 grep -v '_val =' | \
49b4e44b 752 sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
57ca644c 753grep '^const _TUNSET' gen-sysinfo.go | \
754 grep -v '_val =' | \
755 sed -e 's/^\(const \)_\(TUNSET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
7cb04ba7 756# We need TIOCGWINSZ.
757if ! grep '^const TIOCGWINSZ' ${OUT} >/dev/null 2>&1; then
758 if grep '^const _TIOCGWINSZ_val' ${OUT} >/dev/null 2>&1; then
0fd261dc 759 echo 'const TIOCGWINSZ = _TIOCGWINSZ_val' >> ${OUT}
7cb04ba7 760 fi
761fi
5efbe698 762if ! grep '^const TIOCSWINSZ' ${OUT} >/dev/null 2>&1; then
763 if grep '^const _TIOCSWINSZ_val' ${OUT} >/dev/null 2>&1; then
764 echo 'const TIOCSWINSZ = _TIOCSWINSZ_val' >> ${OUT}
765 fi
766fi
05a5342b 767if ! grep '^const TIOCNOTTY' ${OUT} >/dev/null 2>&1; then
768 if grep '^const _TIOCNOTTY_val' ${OUT} >/dev/null 2>&1; then
769 echo 'const TIOCNOTTY = _TIOCNOTTY_val' >> ${OUT}
770 fi
771fi
772if ! grep '^const TIOCSCTTY' ${OUT} >/dev/null 2>&1; then
773 if grep '^const _TIOCSCTTY_val' ${OUT} >/dev/null 2>&1; then
774 echo 'const TIOCSCTTY = _TIOCSCTTY_val' >> ${OUT}
775 fi
776fi
be2b07a5 777if ! grep '^const TIOCGPGRP' ${OUT} >/dev/null 2>&1; then
778 if grep '^const _TIOCGPGRP_val' ${OUT} >/dev/null 2>&1; then
779 echo 'const TIOCGPGRP = _TIOCGPGRP_val' >> ${OUT}
780 fi
781fi
2bd77207 782if ! grep '^const TIOCSPGRP' ${OUT} >/dev/null 2>&1; then
783 if grep '^const _TIOCSPGRP_val' ${OUT} >/dev/null 2>&1; then
784 echo 'const TIOCSPGRP = _TIOCSPGRP_val' >> ${OUT}
785 fi
786fi
db2c791b 787if ! grep '^const TIOCGPTN' ${OUT} >/dev/null 2>&1; then
788 if grep '^const _TIOCGPTN_val' ${OUT} >/dev/null 2>&1; then
789 echo 'const TIOCGPTN = _TIOCGPTN_val' >> ${OUT}
790 fi
791fi
792if ! grep '^const TIOCSPTLCK' ${OUT} >/dev/null 2>&1; then
793 if grep '^const _TIOCSPTLCK_val' ${OUT} >/dev/null 2>&1; then
794 echo 'const TIOCSPTLCK = _TIOCSPTLCK_val' >> ${OUT}
795 fi
796fi
797if ! grep '^const TIOCGDEV' ${OUT} >/dev/null 2>&1; then
798 if grep '^const _TIOCGDEV_val' ${OUT} >/dev/null 2>&1; then
799 echo 'const TIOCGDEV = _TIOCGDEV_val' >> ${OUT}
800 fi
801fi
802if ! grep '^const TIOCSIG' ${OUT} >/dev/null 2>&1; then
803 if grep '^const _TIOCSIG_val' ${OUT} >/dev/null 2>&1; then
804 echo 'const TIOCSIG = _TIOCSIG_val' >> ${OUT}
805 fi
806fi
49b4e44b 807
57ca644c 808if ! grep '^const TUNSETNOCSUM' ${OUT} >/dev/null 2>&1; then
809 if grep '^const _TUNSETNOCSUM_val' ${OUT} >/dev/null 2>&1; then
810 echo 'const TUNSETNOCSUM = _TUNSETNOCSUM_val' >> ${OUT}
811 fi
812fi
813
814if ! grep '^const TUNSETDEBUG' ${OUT} >/dev/null 2>&1; then
815 if grep '^const _TUNSETDEBUG_val' ${OUT} >/dev/null 2>&1; then
816 echo 'const TUNSETDEBUG = _TUNSETDEBUG_val' >> ${OUT}
817 fi
818fi
819
820if ! grep '^const TUNSETIFF' ${OUT} >/dev/null 2>&1; then
821 if grep '^const _TUNSETIFF_val' ${OUT} >/dev/null 2>&1; then
822 echo 'const TUNSETIFF = _TUNSETIFF_val' >> ${OUT}
823 fi
824fi
825
826if ! grep '^const TUNSETPERSIST' ${OUT} >/dev/null 2>&1; then
827 if grep '^const _TUNSETPERSIST_val' ${OUT} >/dev/null 2>&1; then
828 echo 'const TUNSETPERSIST = _TUNSETPERSIST_val' >> ${OUT}
829 fi
830fi
831
832if ! grep '^const TUNSETOWNER' ${OUT} >/dev/null 2>&1; then
833 if grep '^const _TUNSETOWNER_val' ${OUT} >/dev/null 2>&1; then
834 echo 'const TUNSETOWNER = _TUNSETOWNER_val' >> ${OUT}
835 fi
836fi
837
838if ! grep '^const TUNSETLINK' ${OUT} >/dev/null 2>&1; then
839 if grep '^const _TUNSETLINK_val' ${OUT} >/dev/null 2>&1; then
840 echo 'const TUNSETLINK = _TUNSETLINK_val' >> ${OUT}
841 fi
842fi
843
844if ! grep '^const TUNSETGROUP' ${OUT} >/dev/null 2>&1; then
845 if grep '^const _TUNSETGROUP_val' ${OUT} >/dev/null 2>&1; then
846 echo 'const TUNSETGROUP = _TUNSETGROUP_val' >> ${OUT}
847 fi
848fi
849
850if ! grep '^const TUNGETFEATURES' ${OUT} >/dev/null 2>&1; then
851 if grep '^const _TUNGETFEATURES_val' ${OUT} >/dev/null 2>&1; then
852 echo 'const TUNGETFEATURES = _TUNGETFEATURES_val' >> ${OUT}
853 fi
854fi
855
856if ! grep '^const TUNSETOFFLOAD' ${OUT} >/dev/null 2>&1; then
857 if grep '^const _TUNSETOFFLOAD_val' ${OUT} >/dev/null 2>&1; then
858 echo 'const TUNSETOFFLOAD = _TUNSETOFFLOAD_val' >> ${OUT}
859 fi
860fi
861
862if ! grep '^const TUNSETTXFILTER' ${OUT} >/dev/null 2>&1; then
863 if grep '^const _TUNSETTXFILTER_val' ${OUT} >/dev/null 2>&1; then
864 echo 'const TUNSETTXFILTER = _TUNSETTXFILTER_val' >> ${OUT}
865 fi
866fi
867
868if ! grep '^const TUNGETIFF' ${OUT} >/dev/null 2>&1; then
869 if grep '^const _TUNGETIFF_val' ${OUT} >/dev/null 2>&1; then
870 echo 'const TUNGETIFF = _TUNGETIFF_val' >> ${OUT}
871 fi
872fi
873
874if ! grep '^const TUNGETSNDBUF' ${OUT} >/dev/null 2>&1; then
875 if grep '^const _TUNGETSNDBUF_val' ${OUT} >/dev/null 2>&1; then
876 echo 'const TUNGETSNDBUF = _TUNGETSNDBUF_val' >> ${OUT}
877 fi
878fi
879
880if ! grep '^const TUNSETSNDBUF' ${OUT} >/dev/null 2>&1; then
881 if grep '^const _TUNSETSNDBUF_val' ${OUT} >/dev/null 2>&1; then
882 echo 'const TUNSETSNDBUF = _TUNSETSNDBUF_val' >> ${OUT}
883 fi
884fi
885
886if ! grep '^const TUNATTACHFILTER' ${OUT} >/dev/null 2>&1; then
887 if grep '^const _TUNATTACHFILTER_val' ${OUT} >/dev/null 2>&1; then
888 echo 'const TUNATTACHFILTER = _TUNATTACHFILTER_val' >> ${OUT}
889 fi
890fi
891
892if ! grep '^const TUNDETACHFILTER' ${OUT} >/dev/null 2>&1; then
893 if grep '^const _TUNDETACHFILTER_val' ${OUT} >/dev/null 2>&1; then
894 echo 'const TUNDETACHFILTER = _TUNDETACHFILTER_val' >> ${OUT}
895 fi
896fi
897
84a30a52 898if ! grep '^const TUNGETVNETHDRSZ' ${OUT} >/dev/null 2>&1; then
57ca644c 899 if grep '^const _TUNGETVNETHDRSZ_val' ${OUT} >/dev/null 2>&1; then
900 echo 'const TUNGETVNETHDRSZ = _TUNGETVNETHDRSZ_val' >> ${OUT}
901 fi
902fi
903
84a30a52 904if ! grep '^const TUNSETVNETHDRSZ' ${OUT} >/dev/null 2>&1; then
57ca644c 905 if grep '^const _TUNSETVNETHDRSZ_val' ${OUT} >/dev/null 2>&1; then
906 echo 'const TUNSETVNETHDRSZ = _TUNSETVNETHDRSZ_val' >> ${OUT}
907 fi
908fi
909
84a30a52 910if ! grep '^const TUNSETQUEUE' ${OUT} >/dev/null 2>&1; then
57ca644c 911 if grep '^const _TUNSETQUEUE_val' ${OUT} >/dev/null 2>&1; then
912 echo 'const TUNSETQUEUE = _TUNSETQUEUE_val' >> ${OUT}
913 fi
914fi
915
916
917if ! grep '^const TUNSETIFINDEX' ${OUT} >/dev/null 2>&1; then
918 if grep '^const _TUNSETIFINDEX_val' ${OUT} >/dev/null 2>&1; then
919 echo 'const TUNSETIFINDEX = _TUNSETIFINDEX_val' >> ${OUT}
920 fi
921fi
922
923if ! grep '^const TUNGETFILTER' ${OUT} >/dev/null 2>&1; then
924 if grep '^const _TUNGETFILTER_val' ${OUT} >/dev/null 2>&1; then
925 echo 'const TUNGETFILTER = _TUNGETFILTER_val' >> ${OUT}
926 fi
927fi
928
fa5d125b 929# The ioctl flags for terminal control
5efbe698 930grep '^const _TC[GS]ET' gen-sysinfo.go | grep -v _val | \
fa5d125b 931 sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
5efbe698 932if ! grep '^const TCGETS' ${OUT} >/dev/null 2>&1; then
933 if grep '^const _TCGETS_val' ${OUT} >/dev/null 2>&1; then
934 echo 'const TCGETS = _TCGETS_val' >> ${OUT}
935 fi
936fi
937if ! grep '^const TCSETS' ${OUT} >/dev/null 2>&1; then
938 if grep '^const _TCSETS_val' ${OUT} >/dev/null 2>&1; then
939 echo 'const TCSETS = _TCSETS_val' >> ${OUT}
940 fi
941fi
fa5d125b 942
77237956 943# ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but
944# needs handling in syscalls.exec.go.
945if ! grep '^const _TIOCSCTTY ' gen-sysinfo.go >/dev/null 2>&1; then
946 if grep '^const _TIOCNXCL ' gen-sysinfo.go >/dev/null 2>&1; then
947 echo "const TIOCSCTTY = TIOCNXCL" >> ${OUT}
948 fi
949fi
950
03118c21 951# If nothing else defined TIOCSCTTY, make sure it has a value.
952if ! grep "const TIOCSCTTY " ${OUT} >/dev/null 2>&1; then
953 echo "const TIOCSCTTY = 0" >> ${OUT}
954fi
955
49b4e44b 956# The nlmsghdr struct.
957grep '^type _nlmsghdr ' gen-sysinfo.go | \
958 sed -e 's/_nlmsghdr/NlMsghdr/' \
959 -e 's/nlmsg_len/Len/' \
960 -e 's/nlmsg_type/Type/' \
961 -e 's/nlmsg_flags/Flags/' \
962 -e 's/nlmsg_seq/Seq/' \
963 -e 's/nlmsg_pid/Pid/' \
964 >> ${OUT}
965
966# The nlmsg flags and operators.
967grep '^const _NLM' gen-sysinfo.go | \
968 sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
969
970# NLMSG_HDRLEN is defined as an expression using sizeof.
971if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev/null 2>&1; then
5150d596 972 if grep '^const _sizeof_nlmsghdr ' ${OUT} > /dev/null 2>&1; then
973 echo 'const NLMSG_HDRLEN = (_sizeof_nlmsghdr + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1)' >> ${OUT}
49b4e44b 974 fi
975fi
976
d477de41 977# The rtmsg struct.
978grep '^type _rtmsg ' gen-sysinfo.go | \
979 sed -e 's/_rtmsg/RtMsg/' \
980 -e 's/rtm_family/Family/' \
981 -e 's/rtm_dst_len/Dst_len/' \
982 -e 's/rtm_src_len/Src_len/' \
983 -e 's/rtm_tos/Tos/' \
984 -e 's/rtm_table/Table/' \
87e44028 985 -e 's/rtm_protocol/Protocol/' \
d477de41 986 -e 's/rtm_scope/Scope/' \
987 -e 's/rtm_type/Type/' \
988 -e 's/rtm_flags/Flags/' \
989 >> ${OUT}
990
49b4e44b 991# The rtgenmsg struct.
992grep '^type _rtgenmsg ' gen-sysinfo.go | \
993 sed -e 's/_rtgenmsg/RtGenmsg/' \
994 -e 's/rtgen_family/Family/' \
995 >> ${OUT}
996
997# The routing message flags.
87e44028 998grep '^const _RT_' gen-sysinfo.go | \
999 sed -e 's/^\(const \)_\(RT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
49b4e44b 1000grep '^const _RTA' gen-sysinfo.go | \
1001 sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
bd867e38 1002grep '^const _RTF' gen-sysinfo.go | \
1003 sed -e 's/^\(const \)_\(RTF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1004grep '^const _RTCF' gen-sysinfo.go | \
1005 sed -e 's/^\(const \)_\(RTCF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
49b4e44b 1006grep '^const _RTM' gen-sysinfo.go | \
1007 sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
87e44028 1008grep '^const _RTN' gen-sysinfo.go | \
1009 sed -e 's/^\(const \)_\(RTN[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1010grep '^const _RTPROT' gen-sysinfo.go | \
1011 sed -e 's/^\(const \)_\(RTPROT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
49b4e44b 1012
49b4e44b 1013# The ifinfomsg struct.
1014grep '^type _ifinfomsg ' gen-sysinfo.go | \
1015 sed -e 's/_ifinfomsg/IfInfomsg/' \
1016 -e 's/ifi_family/Family/' \
1017 -e 's/ifi_type/Type/' \
1018 -e 's/ifi_index/Index/' \
1019 -e 's/ifi_flags/Flags/' \
1020 -e 's/ifi_change/Change/' \
1021 >> ${OUT}
1022
d8aa6c56 1023# The if_msghdr struct.
1024grep '^type _if_msghdr ' gen-sysinfo.go | \
1025 sed -e 's/_if_msghdr/IfMsgHdr/' \
1026 -e 's/ifm_msglen/Msglen/' \
1027 -e 's/ifm_version/Version/' \
1028 -e 's/ifm_type/Type/' \
1029 -e 's/ifm_addrs/Addrs/' \
1030 -e 's/ifm_flags/Flags/' \
1031 -e 's/ifm_index/Index/' \
1032 -e 's/ifm_addrlen/Addrlen/' \
1033 >> ${OUT}
1034
49b4e44b 1035# The interface information types and flags.
1036grep '^const _IFA' gen-sysinfo.go | \
1037 sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1038grep '^const _IFLA' gen-sysinfo.go | \
1039 sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1040grep '^const _IFF' gen-sysinfo.go | \
1041 sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
9e4aaf6e 1042grep '^const _IFNAMSIZ' gen-sysinfo.go | \
1043 sed -e 's/^\(const \)_\(IFNAMSIZ[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1044grep '^const _SIOC' gen-sysinfo.go |
1045 sed -e 's/^\(const \)_\(SIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
49b4e44b 1046
49b4e44b 1047# The ifaddrmsg struct.
1048grep '^type _ifaddrmsg ' gen-sysinfo.go | \
1049 sed -e 's/_ifaddrmsg/IfAddrmsg/' \
1050 -e 's/ifa_family/Family/' \
1051 -e 's/ifa_prefixlen/Prefixlen/' \
1052 -e 's/ifa_flags/Flags/' \
1053 -e 's/ifa_scope/Scope/' \
1054 -e 's/ifa_index/Index/' \
1055 >> ${OUT}
1056
49b4e44b 1057# The rtattr struct.
1058grep '^type _rtattr ' gen-sysinfo.go | \
1059 sed -e 's/_rtattr/RtAttr/' \
1060 -e 's/rta_len/Len/' \
1061 -e 's/rta_type/Type/' \
1062 >> ${OUT}
1063
a6922263 1064# The in_pktinfo struct.
1065grep '^type _in_pktinfo ' gen-sysinfo.go | \
1066 sed -e 's/_in_pktinfo/Inet4Pktinfo/' \
1067 -e 's/ipi_ifindex/Ifindex/' \
1068 -e 's/ipi_spec_dst/Spec_dst/' \
1069 -e 's/ipi_addr/Addr/' \
62c34bfb 1070 -e 's/_in_addr/[4]byte/g' \
a6922263 1071 >> ${OUT}
1072
1073# The in6_pktinfo struct.
1074grep '^type _in6_pktinfo ' gen-sysinfo.go | \
1075 sed -e 's/_in6_pktinfo/Inet6Pktinfo/' \
1076 -e 's/ipi6_addr/Addr/' \
1077 -e 's/ipi6_ifindex/Ifindex/' \
1078 -e 's/_in6_addr/[16]byte/' \
1079 >> ${OUT}
1080
fa5d125b 1081# The termios struct.
1082grep '^type _termios ' gen-sysinfo.go | \
1083 sed -e 's/_termios/Termios/' \
1084 -e 's/c_iflag/Iflag/' \
1085 -e 's/c_oflag/Oflag/' \
1086 -e 's/c_cflag/Cflag/' \
1087 -e 's/c_lflag/Lflag/' \
1088 -e 's/c_line/Line/' \
1089 -e 's/c_cc/Cc/' \
1090 -e 's/c_ispeed/Ispeed/' \
1091 -e 's/c_ospeed/Ospeed/' \
1092 >> ${OUT}
1093
46bc1fe2 1094# The termios constants.
fa5d125b 1095for n in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \
1096 IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \
f450da21 1097 OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 CS5 CS6 CS7 CS8 TABDLY \
1098 BSDLY VTDLY FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL \
1099 CLOCAL LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE ECHO ECHOE ECHOK \
1100 ECHONL ECHOCTL ECHOPRT ECHOKE DEFECHO FLUSHO NOFLSH TOSTOP PENDIN IEXTEN \
1101 VINTR VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 VSWTCH VSTART VSTOP \
1102 VSUSP VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS TCSANOW TCSADRAIN \
46bc1fe2 1103 TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON TCIOFF TCION B0 B50 \
1104 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 \
f450da21 1105 B38400 B57600 B115200 B230400 B460800 B500000 B576000 B921600 B1000000 \
62c34bfb 1106 B1152000 B1500000 B2000000 B2500000 B3000000 B3500000 B4000000; do
fa5d125b 1107
1108 grep "^const _$n " gen-sysinfo.go | \
1109 sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1110done
1111
0ec80c0c 1112# The mount flags
87e44028 1113grep '^const _MNT_' gen-sysinfo.go |
1114 sed -e 's/^\(const \)_\(MNT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
0ec80c0c 1115grep '^const _MS_' gen-sysinfo.go |
1116 sed -e 's/^\(const \)_\(MS_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1117
1118# The fallocate flags.
1119grep '^const _FALLOC_' gen-sysinfo.go |
1120 sed -e 's/^\(const \)_\(FALLOC_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1121
1122# The statfs struct.
1123# Prefer largefile variant if available.
07b08917 1124# CentOS 5 does not have f_flags, so pull from f_spare.
0ec80c0c 1125statfs=`grep '^type _statfs64 ' gen-sysinfo.go || true`
ad0ce1a5 1126if test "$statfs" == ""; then
1127 statfs=`grep '^type _statfs ' gen-sysinfo.go || true`
1128fi
07b08917 1129if ! echo "$statfs" | grep f_flags; then
1130 statfs=`echo "$statfs" | sed -e 's/f_spare \[4+1\]\([^ ;]*\)/f_flags \1; f_spare [3+1]\1/'`
1131fi
ad0ce1a5 1132echo "$statfs" | sed -e 's/type _statfs64/type Statfs_t/' \
0ec80c0c 1133 -e 's/type _statfs/type Statfs_t/' \
1134 -e 's/f_type/Type/' \
1135 -e 's/f_bsize/Bsize/' \
1136 -e 's/f_blocks/Blocks/' \
1137 -e 's/f_bfree/Bfree/' \
1138 -e 's/f_bavail/Bavail/' \
1139 -e 's/f_files/Files/' \
1140 -e 's/f_ffree/Ffree/' \
1141 -e 's/f_fsid/Fsid/' \
1142 -e 's/f_namelen/Namelen/' \
1143 -e 's/f_frsize/Frsize/' \
1144 -e 's/f_flags/Flags/' \
1145 -e 's/f_spare/Spare/' \
1146 >> ${OUT}
1147
9e4aaf6e 1148# The timex struct.
e947a5a4 1149timex=`grep '^type _timex ' gen-sysinfo.go || true`
1150if test "$timex" = ""; then
1151 timex=`grep '^// type _timex ' gen-sysinfo.go || true`
1152 if test "$timex" != ""; then
1153 timex=`echo $timex | sed -e 's|// ||' -e 's/INVALID-bit-field/int32/g'`
1154 fi
1155fi
1156if test "$timex" != ""; then
1157 echo "$timex" | \
9e4aaf6e 1158 sed -e 's/_timex/Timex/' \
1159 -e 's/modes/Modes/' \
1160 -e 's/offset/Offset/' \
1161 -e 's/freq/Freq/' \
1162 -e 's/maxerror/Maxerror/' \
1163 -e 's/esterror/Esterror/' \
1164 -e 's/status/Status/' \
1165 -e 's/constant/Constant/' \
1166 -e 's/precision/Precision/' \
1167 -e 's/tolerance/Tolerance/' \
1168 -e 's/ time / Time /' \
1169 -e 's/tick/Tick/' \
1170 -e 's/ppsfreq/Ppsfreq/' \
1171 -e 's/jitter/Jitter/' \
1172 -e 's/shift/Shift/' \
1173 -e 's/stabil/Stabil/' \
1174 -e 's/jitcnt/Jitcnt/' \
1175 -e 's/calcnt/Calcnt/' \
1176 -e 's/errcnt/Errcnt/' \
1177 -e 's/stbcnt/Stbcnt/' \
1178 -e 's/tai/Tai/' \
1179 -e 's/_timeval/Timeval/' \
1180 >> ${OUT}
e947a5a4 1181fi
9e4aaf6e 1182
1183# The rlimit struct.
0a76ba3c 1184# On systems that use syscall/libcall_posix_largefile.go, use rlimit64
1185# if it exists.
1186rlimit="_rlimit"
1187if test "${GOOS}" = "aix" || test "${GOOS}" = "linux" || (test "${GOOS}" = "solaris" && (test "${GOARCH}" = "386" || test "${GOARCH}" = "sparc")); then
1188 if grep '^type _rlimit64 ' gen-sysinfo.go > /dev/null 2>&1; then
1189 rlimit="_rlimit64"
1190 fi
1191fi
1192grep "^type ${rlimit} " gen-sysinfo.go | \
1193 sed -e "s/${rlimit}/Rlimit/" \
9e4aaf6e 1194 -e 's/rlim_cur/Cur/' \
1195 -e 's/rlim_max/Max/' \
1196 >> ${OUT}
1197
1198# The RLIMIT constants.
1199grep '^const _RLIMIT_' gen-sysinfo.go |
1200 sed -e 's/^\(const \)_\(RLIMIT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
62c34bfb 1201grep '^const _RLIM_' gen-sysinfo.go |
0a76ba3c 1202 grep -v '^const _RLIM_INFINITY ' |
62c34bfb 1203 sed -e 's/^\(const \)_\(RLIM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
6bfb70cd 1204rliminf=""
0a76ba3c 1205if test "${rlimit}" = "_rlimit64" && grep '^const _RLIM64_INFINITY ' gen-sysinfo.go > /dev/null 2>&1; then
6bfb70cd 1206 rliminf=`grep '^const _RLIM64_INFINITY ' gen-sysinfo.go | sed -e 's/.* //'`
1207else
1208 rliminf=`grep '^const _RLIM_INFINITY ' gen-sysinfo.go | sed -e 's/.* //'`
1209fi
1210# For compatibility with the gc syscall package, treat 0xffffffffffffffff as -1.
1211if test "$rliminf" = "0xffffffffffffffff"; then
1212 echo "const RLIM_INFINITY = -1" >> ${OUT}
1213elif test -n "$rliminf"; then
1214 echo "const RLIM_INFINITY = $rliminf" >> ${OUT}
0a76ba3c 1215fi
9e4aaf6e 1216
1217# The sysinfo struct.
1218grep '^type _sysinfo ' gen-sysinfo.go | \
1219 sed -e 's/_sysinfo/Sysinfo_t/' \
1220 -e 's/uptime/Uptime/' \
1221 -e 's/loads/Loads/' \
1222 -e 's/totalram/Totalram/' \
1223 -e 's/freeram/Freeram/' \
1224 -e 's/sharedram/Sharedram/' \
1225 -e 's/bufferram/Bufferram/' \
1226 -e 's/totalswap/Totalswap/' \
1227 -e 's/freeswap/Freeswap/' \
1228 -e 's/procs/Procs/' \
1229 -e 's/totalhigh/Totalhigh/' \
1230 -e 's/freehigh/Freehigh/' \
1231 -e 's/mem_unit/Unit/' \
1232 >> ${OUT}
1233
9e4aaf6e 1234# The utimbuf struct.
1235grep '^type _utimbuf ' gen-sysinfo.go | \
1236 sed -e 's/_utimbuf/Utimbuf/' \
1237 -e 's/actime/Actime/' \
1238 -e 's/modtime/Modtime/' \
1239 >> ${OUT}
1240
87e44028 1241# The LOCK flags for flock.
1242grep '^const _LOCK_' gen-sysinfo.go |
1243 sed -e 's/^\(const \)_\(LOCK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1244
51a6dfd0 1245# The PRIO constants.
1246grep '^const _PRIO_' gen-sysinfo.go | \
1247 sed -e 's/^\(const \)_\(PRIO_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1248
9e4aaf6e 1249# The GNU/Linux LINUX_REBOOT flags.
1250grep '^const _LINUX_REBOOT_' gen-sysinfo.go |
1251 sed -e 's/^\(const \)_\(LINUX_REBOOT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1252
1253# The GNU/Linux sock_filter struct.
1254grep '^type _sock_filter ' gen-sysinfo.go | \
1255 sed -e 's/_sock_filter/SockFilter/' \
1256 -e 's/code/Code/' \
1257 -e 's/jt/Jt/' \
1258 -e 's/jf/Jf/' \
1259 -e 's/k /K /' \
1260 >> ${OUT}
1261
1262# The GNU/Linux sock_fprog struct.
1263grep '^type _sock_fprog ' gen-sysinfo.go | \
1264 sed -e 's/_sock_fprog/SockFprog/' \
1265 -e 's/len/Len/' \
1266 -e 's/filter/Filter/' \
1267 -e 's/_sock_filter/SockFilter/' \
1268 >> ${OUT}
1269
bd867e38 1270# The GNU/Linux filter flags.
1271grep '^const _BPF_' gen-sysinfo.go | \
1272 sed -e 's/^\(const \)_\(BPF_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1273
a6922263 1274# The GNU/Linux nlattr struct.
1275grep '^type _nlattr ' gen-sysinfo.go | \
1276 sed -e 's/_nlattr/NlAttr/' \
1277 -e 's/nla_len/Len/' \
1278 -e 's/nla_type/Type/' \
1279 >> ${OUT}
1280
1281# The GNU/Linux nlmsgerr struct.
1282grep '^type _nlmsgerr ' gen-sysinfo.go | \
1283 sed -e 's/_nlmsgerr/NlMsgerr/' \
1284 -e 's/error/Error/' \
1285 -e 's/msg/Msg/' \
62c34bfb 1286 -e 's/_nlmsghdr/NlMsghdr/' \
a6922263 1287 >> ${OUT}
1288
1289# The GNU/Linux rtnexthop struct.
1290grep '^type _rtnexthop ' gen-sysinfo.go | \
1291 sed -e 's/_rtnexthop/RtNexthop/' \
1292 -e 's/rtnh_len/Len/' \
1293 -e 's/rtnh_flags/Flags/' \
1294 -e 's/rtnh_hops/Hops/' \
1295 -e 's/rtnh_ifindex/Ifindex/' \
1296 >> ${OUT}
1297
87e44028 1298# The GNU/Linux netlink flags.
1299grep '^const _NETLINK_' gen-sysinfo.go | \
1300 sed -e 's/^\(const \)_\(NETLINK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
ca18e0e7 1301grep '^const _NLA_' gen-sysinfo.go | grep -v '_val =' | \
62c34bfb 1302 sed -e 's/^\(const \)_\(NLA_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
87e44028 1303
ca18e0e7 1304if ! grep '^const NLA_HDRLEN' ${OUT} >/dev/null 2>&1; then
1305 if grep '^const _NLA_HDRLEN_val' ${OUT} >/dev/null 2>&1; then
1306 echo 'const NLA_HDRLEN = _NLA_HDRLEN_val' >> ${OUT}
1307 fi
1308fi
1309
87e44028 1310# The GNU/Linux packet socket flags.
1311grep '^const _PACKET_' gen-sysinfo.go | \
1312 sed -e 's/^\(const \)_\(PACKET_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1313
a6922263 1314# The GNU/Linux inotify_event struct.
1315grep '^type _inotify_event ' gen-sysinfo.go | \
1316 sed -e 's/_inotify_event/InotifyEvent/' \
1317 -e 's/wd/Wd/' \
1318 -e 's/mask/Mask/' \
1319 -e 's/cookie/Cookie/' \
1320 -e 's/len/Len/' \
1321 -e 's/name/Name/' \
1322 -e 's/\[\]/[0]/' \
62c34bfb 1323 -e 's/\[0\]byte/[0]int8/' \
a6922263 1324 >> ${OUT}
1325
a3ba513e 1326# The GNU/Linux CLONE flags.
1327grep '^const _CLONE_' gen-sysinfo.go | \
1328 sed -e 's/^\(const \)_\(CLONE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
4db5794b 1329# We need some CLONE constants that are not defined in older versions
1330# of glibc.
1331if ! grep '^const CLONE_NEWUSER ' ${OUT} > /dev/null 2>&1; then
1332 echo "const CLONE_NEWUSER = 0x10000000" >> ${OUT}
1333fi
f324d484 1334if ! grep '^const CLONE_NEWNET ' ${OUT} > /dev/null 2>&1; then
1335 echo "const CLONE_NEWNET = 0x40000000" >> ${OUT}
1336fi
a3ba513e 1337
5150d596 1338# Struct sizes.
1339set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \
1340 ifaddrmsg IfAddrmsg ifinfomsg IfInfomsg in_pktinfo Inet4Pktinfo \
62c34bfb 1341 in6_pktinfo Inet6Pktinfo inotify_event InotifyEvent linger Linger \
5150d596 1342 msghdr Msghdr nlattr NlAttr nlmsgerr NlMsgerr nlmsghdr NlMsghdr \
1343 rtattr RtAttr rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \
0ce10ea1 1344 sock_filter SockFilter sock_fprog SockFprog ucred Ucred \
0c6c84a9 1345 icmp6_filter ICMPv6Filter ip6_mtuinfo IPv6MTUInfo
5150d596 1346while test $# != 0; do
1347 nc=$1
1348 ngo=$2
1349 shift
1350 shift
1351 if grep "^const _sizeof_$nc =" gen-sysinfo.go >/dev/null 2>&1; then
1352 echo "const Sizeof$ngo = _sizeof_$nc" >> ${OUT}
1353 fi
1354done
1355
1356# In order to compile the net package, we need some sizes to exist
1357# even if the types do not.
1358if ! grep 'const SizeofIPMreq ' ${OUT} >/dev/null 2>&1; then
1359 echo 'const SizeofIPMreq = 8' >> ${OUT}
1360fi
1361if ! grep 'const SizeofIPv6Mreq ' ${OUT} >/dev/null 2>&1; then
1362 echo 'const SizeofIPv6Mreq = 20' >> ${OUT}
1363fi
1364if ! grep 'const SizeofIPMreqn ' ${OUT} >/dev/null 2>&1; then
1365 echo 'const SizeofIPMreqn = 12' >> ${OUT}
1366fi
0ce10ea1 1367if ! grep 'const SizeofICMPv6Filter ' ${OUT} >/dev/null 2>&1; then
1368 echo 'const SizeofICMPv6Filter = 32' >> ${OUT}
1369fi
5150d596 1370
42d664db 1371# The Solaris 11 Update 1 _zone_net_addr_t struct.
1372grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
1373 sed -e 's/_in6_addr/[16]byte/' \
1374 >> ${OUT}
1375
bf1eb034 1376# The Solaris 11.4 _flow_arp_desc_t struct.
5c55b1cf 1377grep '^type _flow_arp_desc_t ' gen-sysinfo.go | \
1378 sed -e 's/_in6_addr_t/[16]byte/g' \
1379 >> ${OUT}
1380
bf1eb034 1381# The Solaris 11.4 _flow_l3_desc_t struct.
5c55b1cf 1382grep '^type _flow_l3_desc_t ' gen-sysinfo.go | \
1383 sed -e 's/_in6_addr_t/[16]byte/g' \
1384 >> ${OUT}
1385
bf1eb034 1386# The Solaris 11.3 _mac_ipaddr_t struct.
5c55b1cf 1387grep '^type _mac_ipaddr_t ' gen-sysinfo.go | \
1388 sed -e 's/_in6_addr_t/[16]byte/g' \
1389 >> ${OUT}
1390
bf1eb034 1391# The Solaris 11.3 _mactun_info_t struct.
5c55b1cf 1392grep '^type _mactun_info_t ' gen-sysinfo.go | \
1393 sed -e 's/_in6_addr_t/[16]byte/g' \
1394 >> ${OUT}
1395
e440a328 1396exit $?