OSDN Git Service

libgo: Update to current Go library.
[pf3gnuchains/gcc-fork.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.
8
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.
13
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.
18
19 CC=${CC:-gcc}
20 OUT=tmp-sysinfo.go
21
22 set -e
23
24 rm -f sysinfo.c
25 cat > sysinfo.c <<EOF
26 #include "config.h"
27
28 #define _GNU_SOURCE
29 #define _LARGEFILE_SOURCE
30 #define _FILE_OFFSET_BITS 64
31
32 #ifdef __sgi__
33 /* IRIX 6 needs _XOPEN_SOURCE=500 for the XPG5 version of struct msghdr in
34    <sys/socket.h>.  */
35 #define _XOPEN_SOURCE 500
36 #endif
37
38 #include <sys/types.h>
39 #include <dirent.h>
40 #include <errno.h>
41 #include <fcntl.h>
42 #include <netinet/in.h>
43 /* <netinet/tcp.h> needs u_char/u_short, but <sys/bsd_types> is only
44    included by <netinet/in.h> if _SGIAPI (i.e. _SGI_SOURCE
45    && !_XOPEN_SOURCE.  */
46 #ifdef __sgi__
47 #include <sys/bsd_types.h>
48 #endif
49 #include <netinet/tcp.h>
50 #include <signal.h>
51 #if defined(HAVE_SYSCALL_H)
52 #include <syscall.h>
53 #endif
54 #if defined(HAVE_SYS_SYSCALL_H)
55 #include <sys/syscall.h>
56 #endif
57 #if defined(HAVE_SYS_EPOLL_H)
58 #include <sys/epoll.h>
59 #endif
60 #if defined(HAVE_SYS_MMAN_H)
61 #include <sys/mman.h>
62 #endif
63 #if defined(HAVE_SYS_PTRACE_H)
64 #include <sys/ptrace.h>
65 #endif
66 #include <sys/resource.h>
67 #include <sys/uio.h>
68 #include <sys/socket.h>
69 #include <sys/stat.h>
70 #include <sys/time.h>
71 #include <sys/wait.h>
72 #include <sys/un.h>
73 #if defined(HAVE_SYS_USER_H)
74 #include <sys/user.h>
75 #endif
76 #if defined(HAVE_SYS_UTSNAME_H)
77 #include <sys/utsname.h>
78 #endif
79 #if defined(HAVE_SYS_SELECT_H)
80 #include <sys/select.h>
81 #endif
82 #include <unistd.h>
83 EOF
84
85 ${CC} -fdump-go-spec=gen-sysinfo.go -std=gnu99 -S -o sysinfo.s sysinfo.c
86
87 echo 'package syscall' > ${OUT}
88
89 # Get all the consts and types, skipping ones which could not be
90 # represented in Go and ones which we need to rewrite.  We also skip
91 # function declarations, as we don't need them here.  All the symbols
92 # will all have a leading underscore.
93 grep -v '^// ' gen-sysinfo.go | \
94   grep -v '^func' | \
95   grep -v '^type _timeval ' | \
96   grep -v '^type _timespec\(_t\)\? ' | \
97   grep -v '^type _timestruc_t ' | \
98   grep -v '^type _epoll_' | \
99   grep -v 'in6_addr' | \
100   grep -v 'sockaddr_in6' | \
101   sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
102       -e 's/\([^a-zA-Z0-9_]\)_timespec\(_t\)\?\([^a-zA-Z0-9_]\)/\1Timespec\3/g' \
103       -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
104     >> ${OUT}
105
106 # The errno constants.
107 grep '^const _E' gen-sysinfo.go | \
108   sed -e 's/^\(const \)_\(E[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
109
110 # The O_xxx flags.
111 egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
112   sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
113 if ! grep '^const O_ASYNC' ${OUT} >/dev/null 2>&1; then
114   echo "const O_ASYNC = 0" >> ${OUT}
115 fi
116 if ! grep '^const O_CLOEXEC' ${OUT} >/dev/null 2>&1; then
117   echo "const O_CLOEXEC = 0" >> ${OUT}
118 fi
119
120 # The signal numbers.
121 grep '^const _SIG[^_]' gen-sysinfo.go | \
122   grep -v '^const _SIGEV_' | \
123   sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
124
125 # The syscall numbers.  We force the names to upper case.
126 grep '^const _SYS_' gen-sysinfo.go | \
127   sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \
128   while read sys; do
129     sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
130     echo "const $sup = _$sys" >> ${OUT}
131   done
132
133 # Stat constants.
134 grep '^const _S_' gen-sysinfo.go | \
135   sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
136
137 # Mmap constants.
138 grep '^const _PROT_' gen-sysinfo.go | \
139   sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
140 grep '^const _MAP_' gen-sysinfo.go | \
141   sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
142
143 # Process status constants.
144 grep '^const _W' gen-sysinfo.go |
145   sed -e 's/^\(const \)_\(W[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
146 # WSTOPPED was introduced in glibc 2.3.4.
147 if ! grep '^const _WSTOPPED = ' gen-sysinfo.go >/dev/null 2>&1; then
148   if grep '^const _WUNTRACED = ' gen-sysinfo.go > /dev/null 2>&1; then
149     echo 'const WSTOPPED = _WUNTRACED' >> ${OUT}
150   else
151     echo 'const WSTOPPED = 2' >> ${OUT}
152   fi
153 fi
154 if grep '^const ___WALL = ' gen-sysinfo.go >/dev/null 2>&1 \
155    && ! grep '^const _WALL = ' gen-sysinfo.go >/dev/null 2>&1; then
156   echo 'const WALL = ___WALL' >> ${OUT}
157 fi
158
159 # Networking constants.
160 egrep '^const _(AF|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
161   sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
162 grep '^const _SOMAXCONN' gen-sysinfo.go |
163   sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
164     >> ${OUT}
165 grep '^const _SHUT_' gen-sysinfo.go |
166   sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
167
168 # The net package requires a definition for IPV6ONLY.
169 if ! grep '^const IPV6_V6ONLY ' ${OUT} >/dev/null 2>&1; then
170   echo "const IPV6_V6ONLY = 0" >> ${OUT}
171 fi
172
173 # pathconf constants.
174 grep '^const __PC' gen-sysinfo.go |
175   sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
176
177 # The epoll constants were picked up by the errno constants, but we
178 # need to be sure the EPOLLRDHUP is defined.
179 if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
180   echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
181 fi
182
183 # Ptrace constants.  We don't expose all the PTRACE flags, just the
184 # PTRACE_O_xxx and PTRACE_EVENT_xxx ones.
185 grep '^const _PTRACE_O' gen-sysinfo.go |
186   sed -e 's/^\(const \)_\(PTRACE_O[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
187 grep '^const _PTRACE_EVENT' gen-sysinfo.go |
188   sed -e 's/^\(const \)_\(PTRACE_EVENT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
189 # We need PTRACE_SETOPTIONS and PTRACE_GETEVENTMSG, but they are not
190 # defined in older versions of glibc.
191 if ! grep '^const _PTRACE_SETOPTIONS' ${OUT} > /dev/null 2>&1; then
192   echo "const _PTRACE_SETOPTIONS = 0x4200" >> ${OUT}
193 fi
194 if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then
195   echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
196 fi
197 if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then
198   echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
199 fi
200 if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then
201   echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
202 fi
203 if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then
204   echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
205 fi
206 if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then
207   echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
208 fi
209 if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then
210   echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
211 fi
212 if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then
213   echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
214 fi
215 if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then
216   echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
217 fi
218 if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
219   echo "const _PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
220 fi
221 if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
222   echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
223 fi
224 if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then
225   echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
226 fi
227 if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then
228   echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
229 fi
230 if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then
231   echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
232 fi
233 if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then
234   echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
235 fi
236 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
237   echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
238 fi
239 if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
240   echo "const _PTRACE_TRACEME = 0" >> ${OUT}
241 fi
242
243 # The registers returned by PTRACE_GETREGS.  This is probably
244 # GNU/Linux specific; it should do no harm if there is no
245 # _user_regs_struct.
246 regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
247 if test "$regs" != ""; then
248   regs=`echo $regs | sed -e 's/type _user_regs_struct struct //' -e 's/[{}]//g'`
249   regs=`echo $regs | sed -e s'/^ *//'`
250   nregs=
251   while test -n "$regs"; do
252     field=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
253     regs=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
254     # Capitalize the first character of the field.
255     f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
256     r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
257     f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
258     field="$f$r"
259     nregs="$nregs $field;"
260   done
261   echo "type PtraceRegs struct {$nregs }" >> ${OUT}
262 fi
263
264 # Some basic types.
265 echo 'type Size_t _size_t' >> ${OUT}
266 echo "type Ssize_t _ssize_t" >> ${OUT}
267 if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then
268   echo "type Offset_t _off64_t" >> ${OUT}
269 else
270   echo "type Offset_t _off_t" >> ${OUT}
271 fi
272 echo "type Mode_t _mode_t" >> ${OUT}
273 echo "type Pid_t _pid_t" >> ${OUT}
274 echo "type Uid_t _uid_t" >> ${OUT}
275 echo "type Gid_t _gid_t" >> ${OUT}
276 echo "type Socklen_t _socklen_t" >> ${OUT}
277
278 # The long type, needed because that is the type that ptrace returns.
279 sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
280 if test "$sizeof_long" = "4"; then
281   echo "type _C_long int32" >> ${OUT}
282 elif test "$sizeof_long" = "8"; then
283   echo "type _C_long int64" >> ${OUT}
284 else
285   echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
286   exit 1
287 fi
288
289 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
290 # double is commented by -fdump-go-spec.
291 if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
292   echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
293 fi
294 if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
295   echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
296 fi
297
298 # The time structures need special handling: we need to name the
299 # types, so that we can cast integers to the right types when
300 # assigning to the structures.
301 timeval=`grep '^type _timeval ' gen-sysinfo.go`
302 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
303 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
304 echo "type Timeval_sec_t $timeval_sec" >> ${OUT}
305 echo "type Timeval_usec_t $timeval_usec" >> ${OUT}
306 echo $timeval | \
307   sed -e 's/type _timeval /type Timeval /' \
308       -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
309       -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
310 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
311 if test "$timespec" = ""; then
312   # IRIX 6.5 has __timespec instead.
313   timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
314 fi
315 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
316 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
317 echo "type Timespec_sec_t $timespec_sec" >> ${OUT}
318 echo "type Timespec_nsec_t $timespec_nsec" >> ${OUT}
319 echo $timespec | \
320   sed -e 's/^type \(__\)\?_timespec /type Timespec /' \
321       -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
322       -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
323
324 timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
325 if test "$timestruc" != ""; then
326   timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
327   timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
328   echo "type Timestruc_sec_t $timestruc_sec" >> ${OUT}
329   echo "type Timestruc_nsec_t $timestruc_nsec" >> ${OUT}
330   echo $timestruc | \
331     sed -e 's/^type _timestruc_t /type Timestruc /' \
332         -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
333         -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
334 fi
335
336 # The stat type.
337 # Prefer largefile variant if available.
338 stat=`grep '^type _stat64 ' gen-sysinfo.go || true`
339 if test "$stat" != ""; then
340   grep '^type _stat64 ' gen-sysinfo.go
341 else
342   grep '^type _stat ' gen-sysinfo.go
343 fi | sed -e 's/type _stat64/type Stat_t/' \
344          -e 's/type _stat/type Stat_t/' \
345          -e 's/st_dev/Dev/' \
346          -e 's/st_ino/Ino/g' \
347          -e 's/st_nlink/Nlink/' \
348          -e 's/st_mode/Mode/' \
349          -e 's/st_uid/Uid/' \
350          -e 's/st_gid/Gid/' \
351          -e 's/st_rdev/Rdev/' \
352          -e 's/st_size/Size/' \
353          -e 's/st_blksize/Blksize/' \
354          -e 's/st_blocks/Blocks/' \
355          -e 's/st_atim/Atime/' \
356          -e 's/st_mtim/Mtime/' \
357          -e 's/st_ctim/Ctime/' \
358          -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
359          -e 's/\([^a-zA-Z0-9_]\)_timespec\(_t\)\?\([^a-zA-Z0-9_]\)/\1Timespec\3/g' \
360          -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
361        >> ${OUT}
362
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}
381
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}
406 fi
407
408 # The utsname struct.
409 grep '^type _utsname ' gen-sysinfo.go | \
410     sed -e 's/_utsname/Utsname/' \
411       -e 's/sysname/Sysname/' \
412       -e 's/nodename/Nodename/' \
413       -e 's/release/Release/' \
414       -e 's/version/Version/' \
415       -e 's/machine/Machine/' \
416       -e 's/domainname/Domainname/' \
417     >> ${OUT}
418
419 # The iovec struct.
420 iovec=`grep '^type _iovec ' gen-sysinfo.go`
421 iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
422 echo "type Iovec_len_t $iovec_len" >> ${OUT}
423 echo $iovec | \
424     sed -e 's/_iovec/Iovec/' \
425       -e 's/iov_base/Base/' \
426       -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
427     >> ${OUT}
428
429 # The msghdr struct.
430 msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
431 msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
432 echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
433 echo $msghdr | \
434     sed -e 's/_msghdr/Msghdr/' \
435       -e 's/msg_name/Name/' \
436       -e 's/msg_namelen/Namelen/' \
437       -e 's/msg_iov/Iov/' \
438       -e 's/msg_iovlen/Iovlen/' \
439       -e 's/_iovec/Iovec/' \
440       -e 's/msg_control/Control/' \
441       -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
442       -e 's/msg_flags/Flags/' \
443     >> ${OUT}
444
445 # The ip_mreq struct
446 grep '^type _ip_mreq ' gen-sysinfo.go | \
447     sed -e 's/_ip_mreq/IpMreq/' \
448       -e 's/imr_multiaddr/Multiaddr/' \
449       -e 's/imr_interface/Interface/' \
450       -e 's/_in_addr/[4]byte/g' \
451     >> ${OUT}
452
453 # Try to guess the type to use for fd_set.
454 fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
455 fds_bits_type="_C_long"
456 if test "$fd_set" != ""; then
457     fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
458 fi
459 echo "type fds_bits_type $fds_bits_type" >> ${OUT}
460
461 exit $?