[42/46] Add vec_info::replace_stmt
[official-gcc.git] / libgo / mksysinfo.sh
blob48bc71dbe986b77635072a3c467be7e20985dcaa
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 'in6_addr' | \
40 grep -v 'sockaddr_in6' | \
41 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
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' \
44 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
45 >> ${OUT}
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.
50 grep '^type _arpcom ' gen-sysinfo.go | \
51 sed -e 's/_in6_addr/[16]byte/' >> ${OUT}
53 # Same on Solaris for _mld_hdr_t.
54 grep '^type _mld_hdr_t ' gen-sysinfo.go | \
55 sed -e 's/_in6_addr/[16]byte/' >> ${OUT}
57 # The errno constants. These get type Errno.
58 egrep '#define E[A-Z0-9_]+ ' errno.i | \
59 sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(_\1)/' >> ${OUT}
61 # The O_xxx flags.
62 egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
63 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
64 if ! grep '^const O_ASYNC' ${OUT} >/dev/null 2>&1; then
65 echo "const O_ASYNC = 0" >> ${OUT}
67 if ! grep '^const O_CLOEXEC' ${OUT} >/dev/null 2>&1; then
68 echo "const O_CLOEXEC = 0" >> ${OUT}
71 # The os package requires F_DUPFD_CLOEXEC to be defined.
72 if ! grep '^const F_DUPFD_CLOEXEC' ${OUT} >/dev/null 2>&1; then
73 echo "const F_DUPFD_CLOEXEC = 0" >> ${OUT}
76 # AIX 7.1 is a 64 bits value for _FCLOEXEC (referenced by O_CLOEXEC)
77 # which leads to a constant overflow when using O_CLOEXEC in some
78 # go code. Issue wan not present in 6.1 (no O_CLOEXEC) and is no
79 # more present in 7.2 (_FCLOEXEC is a 32 bit value).
80 if test "${GOOS}" = "aix" && `oslevel | grep -q "^7.1"`; then
81 sed -e 's/const __FCLOEXEC = .*/const __FCLOEXEC = 0/' ${OUT} > ${OUT}-2
82 mv ${OUT}-2 ${OUT}
85 # These flags can be lost on i386 GNU/Linux when using
86 # -D_FILE_OFFSET_BITS=64, because we see "#define F_SETLK F_SETLK64"
87 # before we see the definition of F_SETLK64.
88 for flag in F_GETLK F_SETLK F_SETLKW; do
89 if ! grep "^const ${flag} " ${OUT} >/dev/null 2>&1 \
90 && grep "^const ${flag}64 " ${OUT} >/dev/null 2>&1; then
91 echo "const ${flag} = ${flag}64" >> ${OUT}
93 done
95 # The Flock_t struct for fcntl.
96 grep '^type _flock ' gen-sysinfo.go | \
97 sed -e 's/type _flock/type Flock_t/' \
98 -e 's/l_type/Type/' \
99 -e 's/l_whence/Whence/' \
100 -e 's/l_start/Start/' \
101 -e 's/l_len/Len/' \
102 -e 's/l_pid/Pid/' \
103 >> ${OUT}
105 # The signal numbers.
106 grep '^const _SIG[^_]' gen-sysinfo.go | \
107 grep -v '^const _SIGEV_' | \
108 sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = Signal(_\2)/' >> ${OUT}
109 if ! grep '^const SIGPOLL ' ${OUT} >/dev/null 2>&1; then
110 if grep '^const SIGIO ' ${OUT} > /dev/null 2>&1; then
111 echo "const SIGPOLL = SIGIO" >> ${OUT}
114 if ! grep '^const SIGCLD ' ${OUT} >/dev/null 2>&1; then
115 if grep '^const SIGCHLD ' ${OUT} >/dev/null 2>&1; then
116 echo "const SIGCLD = SIGCHLD" >> ${OUT}
120 # The syscall numbers. We force the names to upper case.
121 grep '^const _SYS_' gen-sysinfo.go | \
122 sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \
123 while read sys; do
124 sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
125 echo "const $sup = _$sys" >> ${OUT}
126 done
128 # The GNU/Linux support wants to use SYS_GETDENTS64 if available.
129 if ! grep '^const SYS_GETDENTS ' ${OUT} >/dev/null 2>&1; then
130 echo "const SYS_GETDENTS = 0" >> ${OUT}
132 if ! grep '^const SYS_GETDENTS64 ' ${OUT} >/dev/null 2>&1; then
133 echo "const SYS_GETDENTS64 = 0" >> ${OUT}
136 # Stat constants.
137 grep '^const _S_' gen-sysinfo.go | \
138 sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
140 # Mmap constants.
141 grep '^const _PROT_' gen-sysinfo.go | \
142 sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
143 grep '^const _MAP_' gen-sysinfo.go | \
144 sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
145 grep '^const _MADV_' gen-sysinfo.go | \
146 sed -e 's/^\(const \)_\(MADV_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
147 grep '^const _MCL_' gen-sysinfo.go | \
148 sed -e 's/^\(const \)_\(MCL_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
150 # Process status constants.
151 grep '^const _W' gen-sysinfo.go |
152 sed -e 's/^\(const \)_\(W[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
153 # WSTOPPED was introduced in glibc 2.3.4.
154 if ! grep '^const _WSTOPPED = ' gen-sysinfo.go >/dev/null 2>&1; then
155 if grep '^const _WUNTRACED = ' gen-sysinfo.go > /dev/null 2>&1; then
156 echo 'const WSTOPPED = _WUNTRACED' >> ${OUT}
157 else
158 echo 'const WSTOPPED = 2' >> ${OUT}
161 if grep '^const ___WALL = ' gen-sysinfo.go >/dev/null 2>&1 \
162 && ! grep '^const _WALL = ' gen-sysinfo.go >/dev/null 2>&1; then
163 echo 'const WALL = ___WALL' >> ${OUT}
166 # Networking constants.
167 egrep '^const _(AF|ARPHRD|ETH|IN|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
168 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
169 grep '^const _SOMAXCONN' gen-sysinfo.go |
170 sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
171 >> ${OUT}
172 grep '^const _SHUT_' gen-sysinfo.go |
173 sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
175 # The net package requires some const definitions.
176 for m in IP_PKTINFO IPV6_V6ONLY IPPROTO_IPV6 IPV6_JOIN_GROUP IPV6_LEAVE_GROUP IPV6_TCLASS SO_REUSEPORT; do
177 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
178 echo "const $m = 0" >> ${OUT}
180 done
181 for m in SOCK_CLOEXEC SOCK_NONBLOCK; do
182 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
183 echo "const $m = -1" >> ${OUT}
185 done
187 # The syscall package requires AF_LOCAL.
188 if ! grep '^const AF_LOCAL ' ${OUT} >/dev/null 2>&1; then
189 if grep '^const AF_UNIX ' ${OUT} >/dev/null 2>&1; then
190 echo "const AF_LOCAL = AF_UNIX" >> ${OUT}
194 # sysconf constants.
195 grep '^const __SC' gen-sysinfo.go |
196 sed -e 's/^\(const \)__\(SC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
198 # pathconf constants.
199 grep '^const __PC' gen-sysinfo.go |
200 sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
202 # The PATH_MAX constant.
203 if grep '^const _PATH_MAX ' gen-sysinfo.go >/dev/null 2>&1; then
204 echo 'const PathMax = _PATH_MAX' >> ${OUT}
207 # epoll constants.
208 grep '^const _EPOLL' gen-sysinfo.go |
209 grep -v EPOLLET |
210 sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
211 # Make sure EPOLLET is positive.
212 if grep '^const _EPOLLET = [0-9]' gen-sysinfo.go >/dev/null 2>&1; then
213 grep '^const _EPOLLET ' gen-sysinfo.go |
214 sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
215 else
216 echo "const EPOLLET = 0x80000000" >> ${OUT}
218 # Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
219 if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
220 echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
222 if ! grep '^const EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
223 echo "const EPOLL_CLOEXEC = 02000000" >> ${OUT}
226 # Prctl constants.
227 grep '^const _PR_' gen-sysinfo.go |
228 sed -e 's/^\(const \)_\(PR_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
230 # Ptrace constants.
231 grep '^const _PTRACE' gen-sysinfo.go |
232 sed -e 's/^\(const \)_\(PTRACE[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
233 # We need some ptrace options that are not defined in older versions
234 # of glibc.
235 if ! grep '^const PTRACE_SETOPTIONS' ${OUT} > /dev/null 2>&1; then
236 echo "const PTRACE_SETOPTIONS = 0x4200" >> ${OUT}
238 if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then
239 echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
241 if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then
242 echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
244 if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then
245 echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
247 if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then
248 echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
250 if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then
251 echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
253 if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then
254 echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
256 if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then
257 echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
259 if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then
260 echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
262 if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
263 echo "const PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
265 if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
266 echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
268 if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then
269 echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
271 if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then
272 echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
274 if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then
275 echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
277 if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then
278 echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
280 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
281 echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
283 if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
284 echo "const _PTRACE_TRACEME = 0" >> ${OUT}
287 # A helper function that prints a structure from gen-sysinfo.go with the first
288 # letter of the field names in upper case. $1 is the name of structure. If $2
289 # is not empty, the structure or type is renamed to $2.
290 upcase_fields () {
291 name="$1"
292 def=`grep "^type $name " gen-sysinfo.go`
293 fields=`echo $def | sed -e 's/^[^{]*{\(.*\)}$/\1/'`
294 prefix=`echo $def | sed -e 's/{.*//'`
295 if test "$2" != ""; then
296 prefix=`echo $prefix | sed -e "s/$1/$2/"`
298 if test "$fields" != ""; then
299 nfields=
300 while test -n "$fields"; do
301 field=`echo $fields | sed -e 's/^\([^;]*\);.*$/\1/'`
302 fields=`echo $fields | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
303 # capitalize the next character.
304 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
305 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
306 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
307 field="$f$r"
308 nfields="$nfields $field;"
309 done
310 echo "${prefix} {$nfields }"
314 # The registers returned by PTRACE_GETREGS. This is probably
315 # GNU/Linux specific; it should do no harm if there is no
316 # _user_regs_struct.
317 regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
318 if test "$regs" = ""; then
319 # mips*
320 regs=`grep '^type _pt_regs struct' gen-sysinfo.go || true`
322 if test "$regs" != ""; then
323 regs=`echo $regs | sed -e 's/type _pt_regs struct//'`
324 regs=`echo $regs |
325 sed -e 's/type __*user_regs_struct struct //' -e 's/[{}]//g'`
326 regs=`echo $regs | sed -e s'/^ *//'`
327 nregs=
328 while test -n "$regs"; do
329 field=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
330 regs=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
331 # Capitalize the first character of the field.
332 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
333 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
334 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
335 field="$f$r"
336 field=`echo "$field" | sed \
337 -e 's/__user_psw_struct/PtracePsw/' \
338 -e 's/__user_fpregs_struct/PtraceFpregs/' \
339 -e 's/__user_per_struct/PtracePer/'`
340 nregs="$nregs $field;"
341 done
342 echo "type PtraceRegs struct {$nregs }" >> ${OUT}
345 # Some basic types.
346 echo 'type Size_t _size_t' >> ${OUT}
347 echo "type Ssize_t _ssize_t" >> ${OUT}
348 if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then
349 echo "type Offset_t _off64_t" >> ${OUT}
350 else
351 echo "type Offset_t _off_t" >> ${OUT}
353 echo "type Mode_t _mode_t" >> ${OUT}
354 echo "type Pid_t _pid_t" >> ${OUT}
355 echo "type Uid_t _uid_t" >> ${OUT}
356 echo "type Gid_t _gid_t" >> ${OUT}
357 echo "type Socklen_t _socklen_t" >> ${OUT}
359 # The C int type.
360 sizeof_int=`grep '^const ___SIZEOF_INT__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
361 if test "$sizeof_int" = "4"; then
362 echo "type _C_int int32" >> ${OUT}
363 echo "type _C_uint uint32" >> ${OUT}
364 elif test "$sizeof_int" = "8"; then
365 echo "type _C_int int64" >> ${OUT}
366 echo "type _C_uint uint64" >> ${OUT}
367 else
368 echo 1>&2 "mksysinfo.sh: could not determine size of int (got $sizeof_int)"
369 exit 1
372 # The C long type, needed because that is the type that ptrace returns.
373 sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
374 if test "$sizeof_long" = "4"; then
375 echo "type _C_long int32" >> ${OUT}
376 echo "type _C_ulong uint32" >> ${OUT}
377 elif test "$sizeof_long" = "8"; then
378 echo "type _C_long int64" >> ${OUT}
379 echo "type _C_ulong uint64" >> ${OUT}
380 else
381 echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
382 exit 1
385 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
386 # double is commented by -fdump-go-spec.
387 if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
388 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
390 if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
391 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
394 # The time_t type.
395 if grep '^type _time_t ' gen-sysinfo.go > /dev/null 2>&1; then
396 echo 'type Time_t _time_t' >> ${OUT}
399 # The time structures need special handling: we need to name the
400 # types, so that we can cast integers to the right types when
401 # assigning to the structures.
402 timeval=`grep '^type _timeval ' gen-sysinfo.go`
403 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
404 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
405 echo "type Timeval_sec_t $timeval_sec" >> ${OUT}
406 echo "type Timeval_usec_t $timeval_usec" >> ${OUT}
407 echo $timeval | \
408 sed -e 's/type _timeval /type Timeval /' \
409 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
410 -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
411 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
412 if test "$timespec" = ""; then
413 # IRIX 6.5 has __timespec instead.
414 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
416 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
417 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
418 echo "type Timespec_sec_t $timespec_sec" >> ${OUT}
419 echo "type Timespec_nsec_t $timespec_nsec" >> ${OUT}
420 echo $timespec | \
421 sed -e 's/^type ___timespec /type Timespec /' \
422 -e 's/^type _timespec /type Timespec /' \
423 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
424 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
426 timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
427 if test "$timestruc" != ""; then
428 timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
429 timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
430 echo "type Timestruc_sec_t $timestruc_sec" >> ${OUT}
431 echo "type Timestruc_nsec_t $timestruc_nsec" >> ${OUT}
432 echo $timestruc | \
433 sed -e 's/^type _timestruc_t /type Timestruc /' \
434 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
435 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
438 # The tms struct.
439 grep '^type _tms ' gen-sysinfo.go | \
440 sed -e 's/type _tms/type Tms/' \
441 -e 's/tms_utime/Utime/' \
442 -e 's/tms_stime/Stime/' \
443 -e 's/tms_cutime/Cutime/' \
444 -e 's/tms_cstime/Cstime/' \
445 >> ${OUT}
447 # AIX uses st_timespec struct for stat.
448 grep '^type _st_timespec ' gen-sysinfo.go | \
449 sed -e 's/type _st_timespec /type StTimespec /' \
450 -e 's/tv_sec/Sec/' \
451 -e 's/tv_nsec/Nsec/' >> ${OUT}
453 # The stat type.
454 # Prefer largefile variant if available.
455 stat=`grep '^type _stat64 ' gen-sysinfo.go || true`
456 if test "$stat" != ""; then
457 grep '^type _stat64 ' gen-sysinfo.go
458 else
459 grep '^type _stat ' gen-sysinfo.go
460 fi | sed -e 's/type _stat64/type Stat_t/' \
461 -e 's/type _stat/type Stat_t/' \
462 -e 's/st_dev/Dev/' \
463 -e 's/st_ino/Ino/g' \
464 -e 's/st_nlink/Nlink/' \
465 -e 's/st_mode/Mode/' \
466 -e 's/st_uid/Uid/' \
467 -e 's/st_gid/Gid/' \
468 -e 's/st_rdev/Rdev/' \
469 -e 's/st_size/Size/' \
470 -e 's/st_blksize/Blksize/' \
471 -e 's/st_blocks/Blocks/' \
472 -e 's/st_atim/Atim/' \
473 -e 's/st_mtim/Mtim/' \
474 -e 's/st_ctim/Ctim/' \
475 -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
476 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
477 -e 's/\([^a-zA-Z0-9_]\)_st_timespec_t\([^a-zA-Z0-9_]\)/\1StTimespec\2/g' \
478 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
479 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
480 -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
481 >> ${OUT}
483 # The directory searching types.
484 # Prefer largefile variant if available.
485 dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true`
486 if test "$dirent" != ""; then
487 grep '^type _dirent64 ' gen-sysinfo.go
488 else
489 grep '^type _dirent ' gen-sysinfo.go
490 fi | sed -e 's/type _dirent64/type Dirent/' \
491 -e 's/type _dirent/type Dirent/' \
492 -e 's/d_name \[0+1\]/d_name [0+256]/' \
493 -e 's/d_name/Name/' \
494 -e 's/]int8/]byte/' \
495 -e 's/d_ino/Ino/' \
496 -e 's/d_namlen/Namlen/' \
497 -e 's/d_off/Off/' \
498 -e 's/d_reclen/Reclen/' \
499 -e 's/d_type/Type/' \
500 >> ${OUT}
501 echo "type DIR _DIR" >> ${OUT}
503 # Values for d_type field in dirent.
504 grep '^const _DT_' gen-sysinfo.go |
505 sed -e 's/^\(const \)_\(DT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
507 # The rusage struct.
508 rusage=`grep '^type _rusage struct' gen-sysinfo.go`
509 if test "$rusage" != ""; then
510 # Remove anonymous unions from GNU/Linux <bits/resource.h>.
511 rusage=`echo $rusage | sed -e 's/Godump_[0-9][0-9]* struct {\([^}]*\)};/\1/g'`
512 rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
513 rusage=`echo $rusage | sed -e 's/^ *//'`
514 nrusage=
515 while test -n "$rusage"; do
516 field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
517 rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
518 # Drop the leading ru_, capitalize the next character.
519 field=`echo $field | sed -e 's/^ru_//'`
520 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
521 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
522 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
523 # Fix _timeval _timespec, and _timestruc_t.
524 r=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
525 r=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
526 r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
527 field="$f$r"
528 nrusage="$nrusage $field;"
529 done
530 echo "type Rusage struct {$nrusage }" >> ${OUT}
531 else
532 echo "type Rusage struct {}" >> ${OUT}
535 # The RUSAGE constants.
536 grep '^const _RUSAGE_' gen-sysinfo.go | \
537 sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
539 # The utsname struct.
540 grep '^type _utsname ' gen-sysinfo.go | \
541 sed -e 's/_utsname/Utsname/' \
542 -e 's/sysname/Sysname/' \
543 -e 's/nodename/Nodename/' \
544 -e 's/release/Release/' \
545 -e 's/version/Version/' \
546 -e 's/machine/Machine/' \
547 -e 's/domainname/Domainname/' \
548 >> ${OUT}
550 # The iovec struct.
551 iovec=`grep '^type _iovec ' gen-sysinfo.go`
552 iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
553 echo "type Iovec_len_t $iovec_len" >> ${OUT}
554 echo $iovec | \
555 sed -e 's/_iovec/Iovec/' \
556 -e 's/iov_base/Base/' \
557 -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
558 >> ${OUT}
560 # The msghdr struct.
561 msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
562 msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
563 echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
564 echo $msghdr | \
565 sed -e 's/_msghdr/Msghdr/' \
566 -e 's/msg_name/Name/' \
567 -e 's/msg_namelen/Namelen/' \
568 -e 's/msg_iov/Iov/' \
569 -e 's/msg_iovlen/Iovlen/' \
570 -e 's/_iovec/Iovec/' \
571 -e 's/msg_control/Control/' \
572 -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
573 -e 's/msg_flags/Flags/' \
574 >> ${OUT}
576 # The MSG_ flags for Msghdr.
577 grep '^const _MSG_' gen-sysinfo.go | \
578 sed -e 's/^\(const \)_\(MSG_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
580 # The cmsghdr struct.
581 cmsghdr=`grep '^type _cmsghdr ' gen-sysinfo.go`
582 if test -n "$cmsghdr"; then
583 cmsghdr_len=`echo $cmsghdr | sed -n -e 's/^.*cmsg_len \([^ ]*\);.*$/\1/p'`
584 echo "type Cmsghdr_len_t $cmsghdr_len" >> ${OUT}
585 echo "$cmsghdr" | \
586 sed -e 's/_cmsghdr/Cmsghdr/' \
587 -e 's/cmsg_len *[a-zA-Z0-9_]*/Len Cmsghdr_len_t/' \
588 -e 's/cmsg_level/Level/' \
589 -e 's/cmsg_type/Type/' \
590 -e 's/\[\]/[0]/' \
591 >> ${OUT}
594 # The SCM_ flags for Cmsghdr.
595 grep '^const _SCM_' gen-sysinfo.go | \
596 sed -e 's/^\(const \)_\(SCM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
598 # The ucred struct.
599 upcase_fields "_ucred" "Ucred" >> ${OUT} || true
601 # The ip_mreq struct.
602 grep '^type _ip_mreq ' gen-sysinfo.go | \
603 sed -e 's/_ip_mreq/IPMreq/' \
604 -e 's/imr_multiaddr/Multiaddr/' \
605 -e 's/imr_interface/Interface/' \
606 -e 's/_in_addr/[4]byte/g' \
607 >> ${OUT}
609 # We need IPMreq to compile the net package.
610 if ! grep 'type IPMreq ' ${OUT} >/dev/null 2>&1; then
611 echo 'type IPMreq struct { Multiaddr [4]byte; Interface [4]byte; }' >> ${OUT}
614 # The ipv6_mreq struct.
615 grep '^type _ipv6_mreq ' gen-sysinfo.go | \
616 sed -e 's/_ipv6_mreq/IPv6Mreq/' \
617 -e 's/ipv6mr_multiaddr/Multiaddr/' \
618 -e 's/ipv6mr_interface/Interface/' \
619 -e 's/_in6_addr/[16]byte/' \
620 >> ${OUT}
622 # We need IPv6Mreq to compile the net package.
623 if ! grep 'type IPv6Mreq ' ${OUT} >/dev/null 2>&1; then
624 echo 'type IPv6Mreq struct { Multiaddr [16]byte; Interface uint32; }' >> ${OUT}
627 # The ip_mreqn struct.
628 grep '^type _ip_mreqn ' gen-sysinfo.go | \
629 sed -e 's/_ip_mreqn/IPMreqn/' \
630 -e 's/imr_multiaddr/Multiaddr/' \
631 -e 's/imr_address/Address/' \
632 -e 's/imr_ifindex/Ifindex/' \
633 -e 's/_in_addr/[4]byte/g' \
634 >> ${OUT}
636 # We need IPMreq to compile the net package.
637 if ! grep 'type IPMreqn ' ${OUT} >/dev/null 2>&1; then
638 echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT}
641 # The icmp6_filter struct.
642 grep '^type _icmp6_filter ' gen-sysinfo.go | \
643 sed -e 's/_icmp6_filter/ICMPv6Filter/' \
644 -e 's/data/Data/' \
645 -e 's/filt/Filt/' \
646 >> ${OUT}
648 # We need ICMPv6Filter to compile the syscall package.
649 if ! grep 'type ICMPv6Filter ' ${OUT} > /dev/null 2>&1; then
650 echo 'type ICMPv6Filter struct { Data [8]uint32 }' >> ${OUT}
653 # The ip6_mtuinfo struct.
654 grep '^type _ip6_mtuinfo ' gen-sysinfo.go | \
655 sed -e 's/_ip6_mtuinfo/IPv6MTUInfo/' \
656 -e 's/ip6m_addr/Addr/' \
657 -e 's/_sockaddr_in6/RawSockaddrInet6/' \
658 -e 's/ip6m_mtu/Mtu/' \
659 >> ${OUT}
661 # Try to guess the type to use for fd_set.
662 fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
663 fds_bits_type="_C_long"
664 if test "$fd_set" != ""; then
665 fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
667 echo "type fds_bits_type $fds_bits_type" >> ${OUT}
669 # The addrinfo struct.
670 grep '^type _addrinfo ' gen-sysinfo.go | \
671 sed -e 's/_addrinfo/Addrinfo/g' \
672 -e 's/ ai_/ Ai_/g' \
673 >> ${OUT}
675 # The addrinfo and nameinfo flags and errors.
676 grep '^const _AI_' gen-sysinfo.go | \
677 sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
678 grep '^const _EAI_' gen-sysinfo.go | \
679 sed -e 's/^\(const \)_\(EAI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
680 grep '^const _NI_' gen-sysinfo.go | \
681 sed -e 's/^\(const \)_\(NI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
683 # If nothing else defined EAI_OVERFLOW, make sure it has a value.
684 if ! grep "const EAI_OVERFLOW " ${OUT} >/dev/null 2>&1; then
685 echo "const EAI_OVERFLOW = 0" >> ${OUT}
688 # The passwd struct.
689 # Force uid and gid from int32 to uint32 for consistency; they are
690 # int32 on Solaris 10 but uint32 everywhere else including Solaris 11.
691 grep '^type _passwd ' gen-sysinfo.go | \
692 sed -e 's/_passwd/Passwd/' \
693 -e 's/ pw_/ Pw_/g' \
694 -e 's/ Pw_uid int32/ Pw_uid uint32/' \
695 -e 's/ Pw_gid int32/ Pw_gid uint32/' \
696 >> ${OUT}
698 # The group struct.
699 grep '^type _group ' gen-sysinfo.go | \
700 sed -e 's/_group/Group/' \
701 -e 's/ gr_/ Gr_/g' \
702 >> ${OUT}
704 # The ioctl flags for the controlling TTY.
705 grep '^const _TIOC' gen-sysinfo.go | \
706 grep -v '_val =' | \
707 sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
708 grep '^const _TUNSET' gen-sysinfo.go | \
709 grep -v '_val =' | \
710 sed -e 's/^\(const \)_\(TUNSET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
711 # We need TIOCGWINSZ.
712 if ! grep '^const TIOCGWINSZ' ${OUT} >/dev/null 2>&1; then
713 if grep '^const _TIOCGWINSZ_val' ${OUT} >/dev/null 2>&1; then
714 echo 'const TIOCGWINSZ = _TIOCGWINSZ_val' >> ${OUT}
717 if ! grep '^const TIOCSWINSZ' ${OUT} >/dev/null 2>&1; then
718 if grep '^const _TIOCSWINSZ_val' ${OUT} >/dev/null 2>&1; then
719 echo 'const TIOCSWINSZ = _TIOCSWINSZ_val' >> ${OUT}
722 if ! grep '^const TIOCNOTTY' ${OUT} >/dev/null 2>&1; then
723 if grep '^const _TIOCNOTTY_val' ${OUT} >/dev/null 2>&1; then
724 echo 'const TIOCNOTTY = _TIOCNOTTY_val' >> ${OUT}
727 if ! grep '^const TIOCSCTTY' ${OUT} >/dev/null 2>&1; then
728 if grep '^const _TIOCSCTTY_val' ${OUT} >/dev/null 2>&1; then
729 echo 'const TIOCSCTTY = _TIOCSCTTY_val' >> ${OUT}
732 if ! grep '^const TIOCGPGRP' ${OUT} >/dev/null 2>&1; then
733 if grep '^const _TIOCGPGRP_val' ${OUT} >/dev/null 2>&1; then
734 echo 'const TIOCGPGRP = _TIOCGPGRP_val' >> ${OUT}
737 if ! grep '^const TIOCSPGRP' ${OUT} >/dev/null 2>&1; then
738 if grep '^const _TIOCSPGRP_val' ${OUT} >/dev/null 2>&1; then
739 echo 'const TIOCSPGRP = _TIOCSPGRP_val' >> ${OUT}
742 if ! grep '^const TIOCGPTN' ${OUT} >/dev/null 2>&1; then
743 if grep '^const _TIOCGPTN_val' ${OUT} >/dev/null 2>&1; then
744 echo 'const TIOCGPTN = _TIOCGPTN_val' >> ${OUT}
747 if ! grep '^const TIOCSPTLCK' ${OUT} >/dev/null 2>&1; then
748 if grep '^const _TIOCSPTLCK_val' ${OUT} >/dev/null 2>&1; then
749 echo 'const TIOCSPTLCK = _TIOCSPTLCK_val' >> ${OUT}
752 if ! grep '^const TIOCGDEV' ${OUT} >/dev/null 2>&1; then
753 if grep '^const _TIOCGDEV_val' ${OUT} >/dev/null 2>&1; then
754 echo 'const TIOCGDEV = _TIOCGDEV_val' >> ${OUT}
757 if ! grep '^const TIOCSIG' ${OUT} >/dev/null 2>&1; then
758 if grep '^const _TIOCSIG_val' ${OUT} >/dev/null 2>&1; then
759 echo 'const TIOCSIG = _TIOCSIG_val' >> ${OUT}
763 if ! grep '^const TUNSETNOCSUM' ${OUT} >/dev/null 2>&1; then
764 if grep '^const _TUNSETNOCSUM_val' ${OUT} >/dev/null 2>&1; then
765 echo 'const TUNSETNOCSUM = _TUNSETNOCSUM_val' >> ${OUT}
769 if ! grep '^const TUNSETDEBUG' ${OUT} >/dev/null 2>&1; then
770 if grep '^const _TUNSETDEBUG_val' ${OUT} >/dev/null 2>&1; then
771 echo 'const TUNSETDEBUG = _TUNSETDEBUG_val' >> ${OUT}
775 if ! grep '^const TUNSETIFF' ${OUT} >/dev/null 2>&1; then
776 if grep '^const _TUNSETIFF_val' ${OUT} >/dev/null 2>&1; then
777 echo 'const TUNSETIFF = _TUNSETIFF_val' >> ${OUT}
781 if ! grep '^const TUNSETPERSIST' ${OUT} >/dev/null 2>&1; then
782 if grep '^const _TUNSETPERSIST_val' ${OUT} >/dev/null 2>&1; then
783 echo 'const TUNSETPERSIST = _TUNSETPERSIST_val' >> ${OUT}
787 if ! grep '^const TUNSETOWNER' ${OUT} >/dev/null 2>&1; then
788 if grep '^const _TUNSETOWNER_val' ${OUT} >/dev/null 2>&1; then
789 echo 'const TUNSETOWNER = _TUNSETOWNER_val' >> ${OUT}
793 if ! grep '^const TUNSETLINK' ${OUT} >/dev/null 2>&1; then
794 if grep '^const _TUNSETLINK_val' ${OUT} >/dev/null 2>&1; then
795 echo 'const TUNSETLINK = _TUNSETLINK_val' >> ${OUT}
799 if ! grep '^const TUNSETGROUP' ${OUT} >/dev/null 2>&1; then
800 if grep '^const _TUNSETGROUP_val' ${OUT} >/dev/null 2>&1; then
801 echo 'const TUNSETGROUP = _TUNSETGROUP_val' >> ${OUT}
805 if ! grep '^const TUNGETFEATURES' ${OUT} >/dev/null 2>&1; then
806 if grep '^const _TUNGETFEATURES_val' ${OUT} >/dev/null 2>&1; then
807 echo 'const TUNGETFEATURES = _TUNGETFEATURES_val' >> ${OUT}
811 if ! grep '^const TUNSETOFFLOAD' ${OUT} >/dev/null 2>&1; then
812 if grep '^const _TUNSETOFFLOAD_val' ${OUT} >/dev/null 2>&1; then
813 echo 'const TUNSETOFFLOAD = _TUNSETOFFLOAD_val' >> ${OUT}
817 if ! grep '^const TUNSETTXFILTER' ${OUT} >/dev/null 2>&1; then
818 if grep '^const _TUNSETTXFILTER_val' ${OUT} >/dev/null 2>&1; then
819 echo 'const TUNSETTXFILTER = _TUNSETTXFILTER_val' >> ${OUT}
823 if ! grep '^const TUNGETIFF' ${OUT} >/dev/null 2>&1; then
824 if grep '^const _TUNGETIFF_val' ${OUT} >/dev/null 2>&1; then
825 echo 'const TUNGETIFF = _TUNGETIFF_val' >> ${OUT}
829 if ! grep '^const TUNGETSNDBUF' ${OUT} >/dev/null 2>&1; then
830 if grep '^const _TUNGETSNDBUF_val' ${OUT} >/dev/null 2>&1; then
831 echo 'const TUNGETSNDBUF = _TUNGETSNDBUF_val' >> ${OUT}
835 if ! grep '^const TUNSETSNDBUF' ${OUT} >/dev/null 2>&1; then
836 if grep '^const _TUNSETSNDBUF_val' ${OUT} >/dev/null 2>&1; then
837 echo 'const TUNSETSNDBUF = _TUNSETSNDBUF_val' >> ${OUT}
841 if ! grep '^const TUNATTACHFILTER' ${OUT} >/dev/null 2>&1; then
842 if grep '^const _TUNATTACHFILTER_val' ${OUT} >/dev/null 2>&1; then
843 echo 'const TUNATTACHFILTER = _TUNATTACHFILTER_val' >> ${OUT}
847 if ! grep '^const TUNDETACHFILTER' ${OUT} >/dev/null 2>&1; then
848 if grep '^const _TUNDETACHFILTER_val' ${OUT} >/dev/null 2>&1; then
849 echo 'const TUNDETACHFILTER = _TUNDETACHFILTER_val' >> ${OUT}
853 if ! grep '^const TUNGETVNETHDRSZ' ${OUT} >/dev/null 2>&1; then
854 if grep '^const _TUNGETVNETHDRSZ_val' ${OUT} >/dev/null 2>&1; then
855 echo 'const TUNGETVNETHDRSZ = _TUNGETVNETHDRSZ_val' >> ${OUT}
859 if ! grep '^const TUNSETVNETHDRSZ' ${OUT} >/dev/null 2>&1; then
860 if grep '^const _TUNSETVNETHDRSZ_val' ${OUT} >/dev/null 2>&1; then
861 echo 'const TUNSETVNETHDRSZ = _TUNSETVNETHDRSZ_val' >> ${OUT}
865 if ! grep '^const TUNSETQUEUE' ${OUT} >/dev/null 2>&1; then
866 if grep '^const _TUNSETQUEUE_val' ${OUT} >/dev/null 2>&1; then
867 echo 'const TUNSETQUEUE = _TUNSETQUEUE_val' >> ${OUT}
872 if ! grep '^const TUNSETIFINDEX' ${OUT} >/dev/null 2>&1; then
873 if grep '^const _TUNSETIFINDEX_val' ${OUT} >/dev/null 2>&1; then
874 echo 'const TUNSETIFINDEX = _TUNSETIFINDEX_val' >> ${OUT}
878 if ! grep '^const TUNGETFILTER' ${OUT} >/dev/null 2>&1; then
879 if grep '^const _TUNGETFILTER_val' ${OUT} >/dev/null 2>&1; then
880 echo 'const TUNGETFILTER = _TUNGETFILTER_val' >> ${OUT}
884 # The ioctl flags for terminal control
885 grep '^const _TC[GS]ET' gen-sysinfo.go | grep -v _val | \
886 sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
887 if ! grep '^const TCGETS' ${OUT} >/dev/null 2>&1; then
888 if grep '^const _TCGETS_val' ${OUT} >/dev/null 2>&1; then
889 echo 'const TCGETS = _TCGETS_val' >> ${OUT}
892 if ! grep '^const TCSETS' ${OUT} >/dev/null 2>&1; then
893 if grep '^const _TCSETS_val' ${OUT} >/dev/null 2>&1; then
894 echo 'const TCSETS = _TCSETS_val' >> ${OUT}
898 # ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but
899 # needs handling in syscalls.exec.go.
900 if ! grep '^const _TIOCSCTTY ' gen-sysinfo.go >/dev/null 2>&1; then
901 if grep '^const _TIOCNXCL ' gen-sysinfo.go >/dev/null 2>&1; then
902 echo "const TIOCSCTTY = TIOCNXCL" >> ${OUT}
906 # If nothing else defined TIOCSCTTY, make sure it has a value.
907 if ! grep "const TIOCSCTTY " ${OUT} >/dev/null 2>&1; then
908 echo "const TIOCSCTTY = 0" >> ${OUT}
911 # The nlmsghdr struct.
912 grep '^type _nlmsghdr ' gen-sysinfo.go | \
913 sed -e 's/_nlmsghdr/NlMsghdr/' \
914 -e 's/nlmsg_len/Len/' \
915 -e 's/nlmsg_type/Type/' \
916 -e 's/nlmsg_flags/Flags/' \
917 -e 's/nlmsg_seq/Seq/' \
918 -e 's/nlmsg_pid/Pid/' \
919 >> ${OUT}
921 # The nlmsg flags and operators.
922 grep '^const _NLM' gen-sysinfo.go | \
923 sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
925 # NLMSG_HDRLEN is defined as an expression using sizeof.
926 if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev/null 2>&1; then
927 if grep '^const _sizeof_nlmsghdr ' ${OUT} > /dev/null 2>&1; then
928 echo 'const NLMSG_HDRLEN = (_sizeof_nlmsghdr + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1)' >> ${OUT}
932 # The rtmsg struct.
933 grep '^type _rtmsg ' gen-sysinfo.go | \
934 sed -e 's/_rtmsg/RtMsg/' \
935 -e 's/rtm_family/Family/' \
936 -e 's/rtm_dst_len/Dst_len/' \
937 -e 's/rtm_src_len/Src_len/' \
938 -e 's/rtm_tos/Tos/' \
939 -e 's/rtm_table/Table/' \
940 -e 's/rtm_protocol/Protocol/' \
941 -e 's/rtm_scope/Scope/' \
942 -e 's/rtm_type/Type/' \
943 -e 's/rtm_flags/Flags/' \
944 >> ${OUT}
946 # The rtgenmsg struct.
947 grep '^type _rtgenmsg ' gen-sysinfo.go | \
948 sed -e 's/_rtgenmsg/RtGenmsg/' \
949 -e 's/rtgen_family/Family/' \
950 >> ${OUT}
952 # The routing message flags.
953 grep '^const _RT_' gen-sysinfo.go | \
954 sed -e 's/^\(const \)_\(RT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
955 grep '^const _RTA' gen-sysinfo.go | \
956 sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
957 grep '^const _RTF' gen-sysinfo.go | \
958 sed -e 's/^\(const \)_\(RTF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
959 grep '^const _RTCF' gen-sysinfo.go | \
960 sed -e 's/^\(const \)_\(RTCF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
961 grep '^const _RTM' gen-sysinfo.go | \
962 sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
963 grep '^const _RTN' gen-sysinfo.go | \
964 sed -e 's/^\(const \)_\(RTN[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
965 grep '^const _RTPROT' gen-sysinfo.go | \
966 sed -e 's/^\(const \)_\(RTPROT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
968 # The ifinfomsg struct.
969 grep '^type _ifinfomsg ' gen-sysinfo.go | \
970 sed -e 's/_ifinfomsg/IfInfomsg/' \
971 -e 's/ifi_family/Family/' \
972 -e 's/ifi_type/Type/' \
973 -e 's/ifi_index/Index/' \
974 -e 's/ifi_flags/Flags/' \
975 -e 's/ifi_change/Change/' \
976 >> ${OUT}
978 # The interface information types and flags.
979 grep '^const _IFA' gen-sysinfo.go | \
980 sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
981 grep '^const _IFLA' gen-sysinfo.go | \
982 sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
983 grep '^const _IFF' gen-sysinfo.go | \
984 sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
985 grep '^const _IFNAMSIZ' gen-sysinfo.go | \
986 sed -e 's/^\(const \)_\(IFNAMSIZ[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
987 grep '^const _SIOC' gen-sysinfo.go |
988 sed -e 's/^\(const \)_\(SIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
990 # The ifaddrmsg struct.
991 grep '^type _ifaddrmsg ' gen-sysinfo.go | \
992 sed -e 's/_ifaddrmsg/IfAddrmsg/' \
993 -e 's/ifa_family/Family/' \
994 -e 's/ifa_prefixlen/Prefixlen/' \
995 -e 's/ifa_flags/Flags/' \
996 -e 's/ifa_scope/Scope/' \
997 -e 's/ifa_index/Index/' \
998 >> ${OUT}
1000 # The rtattr struct.
1001 grep '^type _rtattr ' gen-sysinfo.go | \
1002 sed -e 's/_rtattr/RtAttr/' \
1003 -e 's/rta_len/Len/' \
1004 -e 's/rta_type/Type/' \
1005 >> ${OUT}
1007 # The in_pktinfo struct.
1008 grep '^type _in_pktinfo ' gen-sysinfo.go | \
1009 sed -e 's/_in_pktinfo/Inet4Pktinfo/' \
1010 -e 's/ipi_ifindex/Ifindex/' \
1011 -e 's/ipi_spec_dst/Spec_dst/' \
1012 -e 's/ipi_addr/Addr/' \
1013 -e 's/_in_addr/[4]byte/g' \
1014 >> ${OUT}
1016 # The in6_pktinfo struct.
1017 grep '^type _in6_pktinfo ' gen-sysinfo.go | \
1018 sed -e 's/_in6_pktinfo/Inet6Pktinfo/' \
1019 -e 's/ipi6_addr/Addr/' \
1020 -e 's/ipi6_ifindex/Ifindex/' \
1021 -e 's/_in6_addr/[16]byte/' \
1022 >> ${OUT}
1024 # The termios struct.
1025 grep '^type _termios ' gen-sysinfo.go | \
1026 sed -e 's/_termios/Termios/' \
1027 -e 's/c_iflag/Iflag/' \
1028 -e 's/c_oflag/Oflag/' \
1029 -e 's/c_cflag/Cflag/' \
1030 -e 's/c_lflag/Lflag/' \
1031 -e 's/c_line/Line/' \
1032 -e 's/c_cc/Cc/' \
1033 -e 's/c_ispeed/Ispeed/' \
1034 -e 's/c_ospeed/Ospeed/' \
1035 >> ${OUT}
1037 # The termios constants.
1038 for n in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \
1039 IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \
1040 OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 CS5 CS6 CS7 CS8 TABDLY \
1041 BSDLY VTDLY FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL \
1042 CLOCAL LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE ECHO ECHOE ECHOK \
1043 ECHONL ECHOCTL ECHOPRT ECHOKE DEFECHO FLUSHO NOFLSH TOSTOP PENDIN IEXTEN \
1044 VINTR VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 VSWTCH VSTART VSTOP \
1045 VSUSP VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS TCSANOW TCSADRAIN \
1046 TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON TCIOFF TCION B0 B50 \
1047 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 \
1048 B38400 B57600 B115200 B230400 B460800 B500000 B576000 B921600 B1000000 \
1049 B1152000 B1500000 B2000000 B2500000 B3000000 B3500000 B4000000; do
1051 grep "^const _$n " gen-sysinfo.go | \
1052 sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1053 done
1055 # The mount flags
1056 grep '^const _MNT_' gen-sysinfo.go |
1057 sed -e 's/^\(const \)_\(MNT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1058 grep '^const _MS_' gen-sysinfo.go |
1059 sed -e 's/^\(const \)_\(MS_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1061 # The fallocate flags.
1062 grep '^const _FALLOC_' gen-sysinfo.go |
1063 sed -e 's/^\(const \)_\(FALLOC_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1065 # The statfs struct.
1066 # Prefer largefile variant if available.
1067 statfs=`grep '^type _statfs64 ' gen-sysinfo.go || true`
1068 if test "$statfs" != ""; then
1069 grep '^type _statfs64 ' gen-sysinfo.go
1070 else
1071 grep '^type _statfs ' gen-sysinfo.go
1072 fi | sed -e 's/type _statfs64/type Statfs_t/' \
1073 -e 's/type _statfs/type Statfs_t/' \
1074 -e 's/f_type/Type/' \
1075 -e 's/f_bsize/Bsize/' \
1076 -e 's/f_blocks/Blocks/' \
1077 -e 's/f_bfree/Bfree/' \
1078 -e 's/f_bavail/Bavail/' \
1079 -e 's/f_files/Files/' \
1080 -e 's/f_ffree/Ffree/' \
1081 -e 's/f_fsid/Fsid/' \
1082 -e 's/f_namelen/Namelen/' \
1083 -e 's/f_frsize/Frsize/' \
1084 -e 's/f_flags/Flags/' \
1085 -e 's/f_spare/Spare/' \
1086 >> ${OUT}
1088 # The timex struct.
1089 timex=`grep '^type _timex ' gen-sysinfo.go || true`
1090 if test "$timex" = ""; then
1091 timex=`grep '^// type _timex ' gen-sysinfo.go || true`
1092 if test "$timex" != ""; then
1093 timex=`echo $timex | sed -e 's|// ||' -e 's/INVALID-bit-field/int32/g'`
1096 if test "$timex" != ""; then
1097 echo "$timex" | \
1098 sed -e 's/_timex/Timex/' \
1099 -e 's/modes/Modes/' \
1100 -e 's/offset/Offset/' \
1101 -e 's/freq/Freq/' \
1102 -e 's/maxerror/Maxerror/' \
1103 -e 's/esterror/Esterror/' \
1104 -e 's/status/Status/' \
1105 -e 's/constant/Constant/' \
1106 -e 's/precision/Precision/' \
1107 -e 's/tolerance/Tolerance/' \
1108 -e 's/ time / Time /' \
1109 -e 's/tick/Tick/' \
1110 -e 's/ppsfreq/Ppsfreq/' \
1111 -e 's/jitter/Jitter/' \
1112 -e 's/shift/Shift/' \
1113 -e 's/stabil/Stabil/' \
1114 -e 's/jitcnt/Jitcnt/' \
1115 -e 's/calcnt/Calcnt/' \
1116 -e 's/errcnt/Errcnt/' \
1117 -e 's/stbcnt/Stbcnt/' \
1118 -e 's/tai/Tai/' \
1119 -e 's/_timeval/Timeval/' \
1120 >> ${OUT}
1123 # The rlimit struct.
1124 # On systems that use syscall/libcall_posix_largefile.go, use rlimit64
1125 # if it exists.
1126 rlimit="_rlimit"
1127 if test "${GOOS}" = "aix" || test "${GOOS}" = "linux" || (test "${GOOS}" = "solaris" && (test "${GOARCH}" = "386" || test "${GOARCH}" = "sparc")); then
1128 if grep '^type _rlimit64 ' gen-sysinfo.go > /dev/null 2>&1; then
1129 rlimit="_rlimit64"
1132 grep "^type ${rlimit} " gen-sysinfo.go | \
1133 sed -e "s/${rlimit}/Rlimit/" \
1134 -e 's/rlim_cur/Cur/' \
1135 -e 's/rlim_max/Max/' \
1136 >> ${OUT}
1138 # The RLIMIT constants.
1139 grep '^const _RLIMIT_' gen-sysinfo.go |
1140 sed -e 's/^\(const \)_\(RLIMIT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1141 grep '^const _RLIM_' gen-sysinfo.go |
1142 grep -v '^const _RLIM_INFINITY ' |
1143 sed -e 's/^\(const \)_\(RLIM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1144 if test "${rlimit}" = "_rlimit64" && grep '^const _RLIM64_INFINITY ' gen-sysinfo.go > /dev/null 2>&1; then
1145 echo 'const RLIM_INFINITY = _RLIM64_INFINITY' >> ${OUT}
1146 elif grep '^const _RLIM_INFINITY ' gen-sysinfo.go > /dev/null 2>&1; then
1147 echo 'const RLIM_INFINITY = _RLIM_INFINITY' >> ${OUT}
1150 # The sysinfo struct.
1151 grep '^type _sysinfo ' gen-sysinfo.go | \
1152 sed -e 's/_sysinfo/Sysinfo_t/' \
1153 -e 's/uptime/Uptime/' \
1154 -e 's/loads/Loads/' \
1155 -e 's/totalram/Totalram/' \
1156 -e 's/freeram/Freeram/' \
1157 -e 's/sharedram/Sharedram/' \
1158 -e 's/bufferram/Bufferram/' \
1159 -e 's/totalswap/Totalswap/' \
1160 -e 's/freeswap/Freeswap/' \
1161 -e 's/procs/Procs/' \
1162 -e 's/totalhigh/Totalhigh/' \
1163 -e 's/freehigh/Freehigh/' \
1164 -e 's/mem_unit/Unit/' \
1165 >> ${OUT}
1167 # The utimbuf struct.
1168 grep '^type _utimbuf ' gen-sysinfo.go | \
1169 sed -e 's/_utimbuf/Utimbuf/' \
1170 -e 's/actime/Actime/' \
1171 -e 's/modtime/Modtime/' \
1172 >> ${OUT}
1174 # The LOCK flags for flock.
1175 grep '^const _LOCK_' gen-sysinfo.go |
1176 sed -e 's/^\(const \)_\(LOCK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1178 # The PRIO constants.
1179 grep '^const _PRIO_' gen-sysinfo.go | \
1180 sed -e 's/^\(const \)_\(PRIO_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1182 # The GNU/Linux LINUX_REBOOT flags.
1183 grep '^const _LINUX_REBOOT_' gen-sysinfo.go |
1184 sed -e 's/^\(const \)_\(LINUX_REBOOT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1186 # The GNU/Linux sock_filter struct.
1187 grep '^type _sock_filter ' gen-sysinfo.go | \
1188 sed -e 's/_sock_filter/SockFilter/' \
1189 -e 's/code/Code/' \
1190 -e 's/jt/Jt/' \
1191 -e 's/jf/Jf/' \
1192 -e 's/k /K /' \
1193 >> ${OUT}
1195 # The GNU/Linux sock_fprog struct.
1196 grep '^type _sock_fprog ' gen-sysinfo.go | \
1197 sed -e 's/_sock_fprog/SockFprog/' \
1198 -e 's/len/Len/' \
1199 -e 's/filter/Filter/' \
1200 -e 's/_sock_filter/SockFilter/' \
1201 >> ${OUT}
1203 # The GNU/Linux filter flags.
1204 grep '^const _BPF_' gen-sysinfo.go | \
1205 sed -e 's/^\(const \)_\(BPF_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1207 # The GNU/Linux nlattr struct.
1208 grep '^type _nlattr ' gen-sysinfo.go | \
1209 sed -e 's/_nlattr/NlAttr/' \
1210 -e 's/nla_len/Len/' \
1211 -e 's/nla_type/Type/' \
1212 >> ${OUT}
1214 # The GNU/Linux nlmsgerr struct.
1215 grep '^type _nlmsgerr ' gen-sysinfo.go | \
1216 sed -e 's/_nlmsgerr/NlMsgerr/' \
1217 -e 's/error/Error/' \
1218 -e 's/msg/Msg/' \
1219 -e 's/_nlmsghdr/NlMsghdr/' \
1220 >> ${OUT}
1222 # The GNU/Linux rtnexthop struct.
1223 grep '^type _rtnexthop ' gen-sysinfo.go | \
1224 sed -e 's/_rtnexthop/RtNexthop/' \
1225 -e 's/rtnh_len/Len/' \
1226 -e 's/rtnh_flags/Flags/' \
1227 -e 's/rtnh_hops/Hops/' \
1228 -e 's/rtnh_ifindex/Ifindex/' \
1229 >> ${OUT}
1231 # The GNU/Linux netlink flags.
1232 grep '^const _NETLINK_' gen-sysinfo.go | \
1233 sed -e 's/^\(const \)_\(NETLINK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1234 grep '^const _NLA_' gen-sysinfo.go | grep -v '_val =' | \
1235 sed -e 's/^\(const \)_\(NLA_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1237 if ! grep '^const NLA_HDRLEN' ${OUT} >/dev/null 2>&1; then
1238 if grep '^const _NLA_HDRLEN_val' ${OUT} >/dev/null 2>&1; then
1239 echo 'const NLA_HDRLEN = _NLA_HDRLEN_val' >> ${OUT}
1243 # The GNU/Linux packet socket flags.
1244 grep '^const _PACKET_' gen-sysinfo.go | \
1245 sed -e 's/^\(const \)_\(PACKET_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1247 # The GNU/Linux inotify_event struct.
1248 grep '^type _inotify_event ' gen-sysinfo.go | \
1249 sed -e 's/_inotify_event/InotifyEvent/' \
1250 -e 's/wd/Wd/' \
1251 -e 's/mask/Mask/' \
1252 -e 's/cookie/Cookie/' \
1253 -e 's/len/Len/' \
1254 -e 's/name/Name/' \
1255 -e 's/\[\]/[0]/' \
1256 -e 's/\[0\]byte/[0]int8/' \
1257 >> ${OUT}
1259 # The GNU/Linux CLONE flags.
1260 grep '^const _CLONE_' gen-sysinfo.go | \
1261 sed -e 's/^\(const \)_\(CLONE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1262 # We need some CLONE constants that are not defined in older versions
1263 # of glibc.
1264 if ! grep '^const CLONE_NEWUSER ' ${OUT} > /dev/null 2>&1; then
1265 echo "const CLONE_NEWUSER = 0x10000000" >> ${OUT}
1267 if ! grep '^const CLONE_NEWNET ' ${OUT} > /dev/null 2>&1; then
1268 echo "const CLONE_NEWNET = 0x40000000" >> ${OUT}
1271 # Struct sizes.
1272 set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \
1273 ifaddrmsg IfAddrmsg ifinfomsg IfInfomsg in_pktinfo Inet4Pktinfo \
1274 in6_pktinfo Inet6Pktinfo inotify_event InotifyEvent linger Linger \
1275 msghdr Msghdr nlattr NlAttr nlmsgerr NlMsgerr nlmsghdr NlMsghdr \
1276 rtattr RtAttr rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \
1277 sock_filter SockFilter sock_fprog SockFprog ucred Ucred \
1278 icmp6_filter ICMPv6Filter ip6_mtuinfo IPv6MTUInfo
1279 while test $# != 0; do
1280 nc=$1
1281 ngo=$2
1282 shift
1283 shift
1284 if grep "^const _sizeof_$nc =" gen-sysinfo.go >/dev/null 2>&1; then
1285 echo "const Sizeof$ngo = _sizeof_$nc" >> ${OUT}
1287 done
1289 # In order to compile the net package, we need some sizes to exist
1290 # even if the types do not.
1291 if ! grep 'const SizeofIPMreq ' ${OUT} >/dev/null 2>&1; then
1292 echo 'const SizeofIPMreq = 8' >> ${OUT}
1294 if ! grep 'const SizeofIPv6Mreq ' ${OUT} >/dev/null 2>&1; then
1295 echo 'const SizeofIPv6Mreq = 20' >> ${OUT}
1297 if ! grep 'const SizeofIPMreqn ' ${OUT} >/dev/null 2>&1; then
1298 echo 'const SizeofIPMreqn = 12' >> ${OUT}
1300 if ! grep 'const SizeofICMPv6Filter ' ${OUT} >/dev/null 2>&1; then
1301 echo 'const SizeofICMPv6Filter = 32' >> ${OUT}
1304 # The Solaris 11 Update 1 _zone_net_addr_t struct.
1305 grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
1306 sed -e 's/_in6_addr/[16]byte/' \
1307 >> ${OUT}
1309 # The Solaris 11.4 _flow_arp_desc_t struct.
1310 grep '^type _flow_arp_desc_t ' gen-sysinfo.go | \
1311 sed -e 's/_in6_addr_t/[16]byte/g' \
1312 >> ${OUT}
1314 # The Solaris 11.4 _flow_l3_desc_t struct.
1315 grep '^type _flow_l3_desc_t ' gen-sysinfo.go | \
1316 sed -e 's/_in6_addr_t/[16]byte/g' \
1317 >> ${OUT}
1319 # The Solaris 11.3 _mac_ipaddr_t struct.
1320 grep '^type _mac_ipaddr_t ' gen-sysinfo.go | \
1321 sed -e 's/_in6_addr_t/[16]byte/g' \
1322 >> ${OUT}
1324 # The Solaris 11.3 _mactun_info_t struct.
1325 grep '^type _mactun_info_t ' gen-sysinfo.go | \
1326 sed -e 's/_in6_addr_t/[16]byte/g' \
1327 >> ${OUT}
1329 exit $?