Revert wrong checkin
[official-gcc.git] / libgo / mksysinfo.sh
blob19885fb000d6d6c950e875977efb2a297901ca6c
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.
9 # This shell script creates the sysinfo.go file which holds types and
10 # constants extracted from the system header files. This relies on a
11 # hook in gcc: the -fdump-go-spec option will generate debugging
12 # information in Go syntax.
14 # We currently #include all the files at once, which works, but leads
15 # to exposing some names which ideally should not be exposed, as they
16 # match grep patterns. E.g., WCHAR_MIN gets exposed because it starts
17 # with W, like the wait flags.
19 CC=${CC:-gcc}
20 OUT=tmp-sysinfo.go
22 set -e
24 rm -f sysinfo.c
25 cat > sysinfo.c <<EOF
26 #include "config.h"
28 #define _GNU_SOURCE
29 #define _LARGEFILE_SOURCE
30 #define _FILE_OFFSET_BITS 64
32 #include <sys/types.h>
33 #include <dirent.h>
34 #include <errno.h>
35 #include <fcntl.h>
36 #include <netinet/in.h>
37 /* <netinet/tcp.h> needs u_char/u_short, but <sys/bsd_types> is only
38 included by <netinet/in.h> if _SGIAPI (i.e. _SGI_SOURCE
39 && !_XOPEN_SOURCE. */
40 #ifdef __sgi__
41 #include <sys/bsd_types.h>
42 #endif
43 #include <netinet/tcp.h>
44 #include <signal.h>
45 #if defined(HAVE_SYSCALL_H)
46 #include <syscall.h>
47 #endif
48 #if defined(HAVE_SYS_SYSCALL_H)
49 #include <sys/syscall.h>
50 #endif
51 #if defined(HAVE_SYS_EPOLL_H)
52 #include <sys/epoll.h>
53 #endif
54 #if defined(HAVE_SYS_MMAN_H)
55 #include <sys/mman.h>
56 #endif
57 #if defined(HAVE_SYS_PTRACE_H)
58 #include <sys/ptrace.h>
59 #endif
60 #include <sys/resource.h>
61 #include <sys/uio.h>
62 #include <sys/socket.h>
63 #include <sys/stat.h>
64 #include <sys/time.h>
65 #include <sys/wait.h>
66 #include <sys/un.h>
67 #if defined(HAVE_SYS_USER_H)
68 #include <sys/user.h>
69 #endif
70 #if defined(HAVE_SYS_UTSNAME_H)
71 #include <sys/utsname.h>
72 #endif
73 #if defined(HAVE_SYS_SELECT_H)
74 #include <sys/select.h>
75 #endif
76 #include <unistd.h>
77 #include <netdb.h>
78 #include <pwd.h>
79 EOF
81 ${CC} -fdump-go-spec=gen-sysinfo.go -std=gnu99 -S -o sysinfo.s sysinfo.c
83 echo 'package syscall' > ${OUT}
85 # Get all the consts and types, skipping ones which could not be
86 # represented in Go and ones which we need to rewrite. We also skip
87 # function declarations, as we don't need them here. All the symbols
88 # will all have a leading underscore.
89 grep -v '^// ' gen-sysinfo.go | \
90 grep -v '^func' | \
91 grep -v '^type _timeval ' | \
92 grep -v '^type _timespec_t ' | \
93 grep -v '^type _timespec ' | \
94 grep -v '^type _timestruc_t ' | \
95 grep -v '^type _epoll_' | \
96 grep -v 'in6_addr' | \
97 grep -v 'sockaddr_in6' | \
98 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
99 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
100 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
101 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
102 >> ${OUT}
104 # The errno constants.
105 grep '^const _E' gen-sysinfo.go | \
106 sed -e 's/^\(const \)_\(E[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
108 # The O_xxx flags.
109 egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
110 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
111 if ! grep '^const O_ASYNC' ${OUT} >/dev/null 2>&1; then
112 echo "const O_ASYNC = 0" >> ${OUT}
114 if ! grep '^const O_CLOEXEC' ${OUT} >/dev/null 2>&1; then
115 echo "const O_CLOEXEC = 0" >> ${OUT}
118 # The signal numbers.
119 grep '^const _SIG[^_]' gen-sysinfo.go | \
120 grep -v '^const _SIGEV_' | \
121 sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
123 # The syscall numbers. We force the names to upper case.
124 grep '^const _SYS_' gen-sysinfo.go | \
125 sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \
126 while read sys; do
127 sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
128 echo "const $sup = _$sys" >> ${OUT}
129 done
131 # Stat constants.
132 grep '^const _S_' gen-sysinfo.go | \
133 sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
135 # Mmap constants.
136 grep '^const _PROT_' gen-sysinfo.go | \
137 sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
138 grep '^const _MAP_' gen-sysinfo.go | \
139 sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
141 # Process status constants.
142 grep '^const _W' gen-sysinfo.go |
143 sed -e 's/^\(const \)_\(W[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
144 # WSTOPPED was introduced in glibc 2.3.4.
145 if ! grep '^const _WSTOPPED = ' gen-sysinfo.go >/dev/null 2>&1; then
146 if grep '^const _WUNTRACED = ' gen-sysinfo.go > /dev/null 2>&1; then
147 echo 'const WSTOPPED = _WUNTRACED' >> ${OUT}
148 else
149 echo 'const WSTOPPED = 2' >> ${OUT}
152 if grep '^const ___WALL = ' gen-sysinfo.go >/dev/null 2>&1 \
153 && ! grep '^const _WALL = ' gen-sysinfo.go >/dev/null 2>&1; then
154 echo 'const WALL = ___WALL' >> ${OUT}
157 # Networking constants.
158 egrep '^const _(AF|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
159 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
160 grep '^const _SOMAXCONN' gen-sysinfo.go |
161 sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
162 >> ${OUT}
163 grep '^const _SHUT_' gen-sysinfo.go |
164 sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
166 # The net package requires a definition for IPV6ONLY.
167 if ! grep '^const IPV6_V6ONLY ' ${OUT} >/dev/null 2>&1; then
168 echo "const IPV6_V6ONLY = 0" >> ${OUT}
171 # pathconf constants.
172 grep '^const __PC' gen-sysinfo.go |
173 sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
175 # The epoll constants were picked up by the errno constants, but we
176 # need to be sure the EPOLLRDHUP is defined.
177 if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
178 echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
181 # Ptrace constants. We don't expose all the PTRACE flags, just the
182 # PTRACE_O_xxx and PTRACE_EVENT_xxx ones.
183 grep '^const _PTRACE_O' gen-sysinfo.go |
184 sed -e 's/^\(const \)_\(PTRACE_O[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
185 grep '^const _PTRACE_EVENT' gen-sysinfo.go |
186 sed -e 's/^\(const \)_\(PTRACE_EVENT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
187 # We need PTRACE_SETOPTIONS and PTRACE_GETEVENTMSG, but they are not
188 # defined in older versions of glibc.
189 if ! grep '^const _PTRACE_SETOPTIONS' ${OUT} > /dev/null 2>&1; then
190 echo "const _PTRACE_SETOPTIONS = 0x4200" >> ${OUT}
192 if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then
193 echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
195 if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then
196 echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
198 if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then
199 echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
201 if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then
202 echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
204 if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then
205 echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
207 if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then
208 echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
210 if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then
211 echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
213 if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then
214 echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
216 if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
217 echo "const _PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
219 if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
220 echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
222 if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then
223 echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
225 if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then
226 echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
228 if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then
229 echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
231 if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then
232 echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
234 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
235 echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
237 if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
238 echo "const _PTRACE_TRACEME = 0" >> ${OUT}
241 # The registers returned by PTRACE_GETREGS. This is probably
242 # GNU/Linux specific; it should do no harm if there is no
243 # _user_regs_struct.
244 regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
245 if test "$regs" != ""; then
246 regs=`echo $regs | sed -e 's/type _user_regs_struct struct //' -e 's/[{}]//g'`
247 regs=`echo $regs | sed -e s'/^ *//'`
248 nregs=
249 while test -n "$regs"; do
250 field=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
251 regs=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
252 # Capitalize the first character of the field.
253 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
254 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
255 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
256 field="$f$r"
257 nregs="$nregs $field;"
258 done
259 echo "type PtraceRegs struct {$nregs }" >> ${OUT}
262 # Some basic types.
263 echo 'type Size_t _size_t' >> ${OUT}
264 echo "type Ssize_t _ssize_t" >> ${OUT}
265 if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then
266 echo "type Offset_t _off64_t" >> ${OUT}
267 else
268 echo "type Offset_t _off_t" >> ${OUT}
270 echo "type Mode_t _mode_t" >> ${OUT}
271 echo "type Pid_t _pid_t" >> ${OUT}
272 echo "type Uid_t _uid_t" >> ${OUT}
273 echo "type Gid_t _gid_t" >> ${OUT}
274 echo "type Socklen_t _socklen_t" >> ${OUT}
276 # The long type, needed because that is the type that ptrace returns.
277 sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
278 if test "$sizeof_long" = "4"; then
279 echo "type _C_long int32" >> ${OUT}
280 elif test "$sizeof_long" = "8"; then
281 echo "type _C_long int64" >> ${OUT}
282 else
283 echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
284 exit 1
287 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
288 # double is commented by -fdump-go-spec.
289 if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
290 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
292 if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
293 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
296 # The time structures need special handling: we need to name the
297 # types, so that we can cast integers to the right types when
298 # assigning to the structures.
299 timeval=`grep '^type _timeval ' gen-sysinfo.go`
300 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
301 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
302 echo "type Timeval_sec_t $timeval_sec" >> ${OUT}
303 echo "type Timeval_usec_t $timeval_usec" >> ${OUT}
304 echo $timeval | \
305 sed -e 's/type _timeval /type Timeval /' \
306 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
307 -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
308 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
309 if test "$timespec" = ""; then
310 # IRIX 6.5 has __timespec instead.
311 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
313 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
314 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
315 echo "type Timespec_sec_t $timespec_sec" >> ${OUT}
316 echo "type Timespec_nsec_t $timespec_nsec" >> ${OUT}
317 echo $timespec | \
318 sed -e 's/^type ___timespec /type Timespec /' \
319 -e 's/^type _timespec /type Timespec /' \
320 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
321 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
323 timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
324 if test "$timestruc" != ""; then
325 timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
326 timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
327 echo "type Timestruc_sec_t $timestruc_sec" >> ${OUT}
328 echo "type Timestruc_nsec_t $timestruc_nsec" >> ${OUT}
329 echo $timestruc | \
330 sed -e 's/^type _timestruc_t /type Timestruc /' \
331 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
332 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
335 # The stat type.
336 # Prefer largefile variant if available.
337 stat=`grep '^type _stat64 ' gen-sysinfo.go || true`
338 if test "$stat" != ""; then
339 grep '^type _stat64 ' gen-sysinfo.go
340 else
341 grep '^type _stat ' gen-sysinfo.go
342 fi | sed -e 's/type _stat64/type Stat_t/' \
343 -e 's/type _stat/type Stat_t/' \
344 -e 's/st_dev/Dev/' \
345 -e 's/st_ino/Ino/g' \
346 -e 's/st_nlink/Nlink/' \
347 -e 's/st_mode/Mode/' \
348 -e 's/st_uid/Uid/' \
349 -e 's/st_gid/Gid/' \
350 -e 's/st_rdev/Rdev/' \
351 -e 's/st_size/Size/' \
352 -e 's/st_blksize/Blksize/' \
353 -e 's/st_blocks/Blocks/' \
354 -e 's/st_atim/Atime/' \
355 -e 's/st_mtim/Mtime/' \
356 -e 's/st_ctim/Ctime/' \
357 -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
358 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
359 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
360 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
361 >> ${OUT}
363 # The directory searching types.
364 # Prefer largefile variant if available.
365 dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true`
366 if test "$dirent" != ""; then
367 grep '^type _dirent64 ' gen-sysinfo.go
368 else
369 grep '^type _dirent ' gen-sysinfo.go
370 fi | sed -e 's/type _dirent64/type Dirent/' \
371 -e 's/type _dirent/type Dirent/' \
372 -e 's/d_name \[0+1\]/d_name [0+256]/' \
373 -e 's/d_name/Name/' \
374 -e 's/]int8/]byte/' \
375 -e 's/d_ino/Ino/' \
376 -e 's/d_off/Off/' \
377 -e 's/d_reclen/Reclen/' \
378 -e 's/d_type/Type/' \
379 >> ${OUT}
380 echo "type DIR _DIR" >> ${OUT}
382 # The rusage struct.
383 rusage=`grep '^type _rusage struct' gen-sysinfo.go`
384 if test "$rusage" != ""; then
385 rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
386 rusage=`echo $rusage | sed -e 's/^ *//'`
387 nrusage=
388 while test -n "$rusage"; do
389 field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
390 rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
391 # Drop the leading ru_, capitalize the next character.
392 field=`echo $field | sed -e 's/^ru_//'`
393 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
394 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
395 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
396 # Fix _timeval _timespec, and _timestruc_t.
397 r=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
398 r=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
399 r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
400 field="$f$r"
401 nrusage="$nrusage $field;"
402 done
403 echo "type Rusage struct {$nrusage }" >> ${OUT}
404 else
405 echo "type Rusage struct {}" >> ${OUT}
408 # The RUSAGE constants.
409 grep '^const _RUSAGE_' gen-sysinfo.go | \
410 sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
412 # The utsname struct.
413 grep '^type _utsname ' gen-sysinfo.go | \
414 sed -e 's/_utsname/Utsname/' \
415 -e 's/sysname/Sysname/' \
416 -e 's/nodename/Nodename/' \
417 -e 's/release/Release/' \
418 -e 's/version/Version/' \
419 -e 's/machine/Machine/' \
420 -e 's/domainname/Domainname/' \
421 >> ${OUT}
423 # The iovec struct.
424 iovec=`grep '^type _iovec ' gen-sysinfo.go`
425 iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
426 echo "type Iovec_len_t $iovec_len" >> ${OUT}
427 echo $iovec | \
428 sed -e 's/_iovec/Iovec/' \
429 -e 's/iov_base/Base/' \
430 -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
431 >> ${OUT}
433 # The msghdr struct.
434 msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
435 msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
436 echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
437 echo $msghdr | \
438 sed -e 's/_msghdr/Msghdr/' \
439 -e 's/msg_name/Name/' \
440 -e 's/msg_namelen/Namelen/' \
441 -e 's/msg_iov/Iov/' \
442 -e 's/msg_iovlen/Iovlen/' \
443 -e 's/_iovec/Iovec/' \
444 -e 's/msg_control/Control/' \
445 -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
446 -e 's/msg_flags/Flags/' \
447 >> ${OUT}
449 # The ip_mreq struct
450 grep '^type _ip_mreq ' gen-sysinfo.go | \
451 sed -e 's/_ip_mreq/IpMreq/' \
452 -e 's/imr_multiaddr/Multiaddr/' \
453 -e 's/imr_interface/Interface/' \
454 -e 's/_in_addr/[4]byte/g' \
455 >> ${OUT}
457 # Try to guess the type to use for fd_set.
458 fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
459 fds_bits_type="_C_long"
460 if test "$fd_set" != ""; then
461 fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
463 echo "type fds_bits_type $fds_bits_type" >> ${OUT}
465 # The addrinfo struct.
466 grep '^type _addrinfo ' gen-sysinfo.go | \
467 sed -e 's/_addrinfo/Addrinfo/g' \
468 -e 's/ ai_/ Ai_/g' \
469 >> ${OUT}
471 # The addrinfo flags.
472 grep '^const _AI_' gen-sysinfo.go | \
473 sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
475 # The passwd struct.
476 grep '^type _passwd ' gen-sysinfo.go | \
477 sed -e 's/_passwd/Passwd/' \
478 -e 's/ pw_/ Pw_/g' \
479 >> ${OUT}
481 exit $?