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