OSDN Git Service

PR target/47744
[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 #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
80
81 ${CC} -fdump-go-spec=gen-sysinfo.go -std=gnu99 -S -o sysinfo.s sysinfo.c
82
83 echo 'package syscall' > ${OUT}
84
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}
103
104 # The errno constants.
105 grep '^const _E' gen-sysinfo.go | \
106   sed -e 's/^\(const \)_\(E[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
107
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}
113 fi
114 if ! grep '^const O_CLOEXEC' ${OUT} >/dev/null 2>&1; then
115   echo "const O_CLOEXEC = 0" >> ${OUT}
116 fi
117
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}
122
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
130
131 # Stat constants.
132 grep '^const _S_' gen-sysinfo.go | \
133   sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
134
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}
140
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}
150   fi
151 fi
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}
155 fi
156
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}
165
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}
169 fi
170
171 # pathconf constants.
172 grep '^const __PC' gen-sysinfo.go |
173   sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
174
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}
179 fi
180
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}
191 fi
192 if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then
193   echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
194 fi
195 if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then
196   echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
197 fi
198 if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then
199   echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
200 fi
201 if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then
202   echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
203 fi
204 if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then
205   echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
206 fi
207 if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then
208   echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
209 fi
210 if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then
211   echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
212 fi
213 if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then
214   echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
215 fi
216 if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
217   echo "const _PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
218 fi
219 if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
220   echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
221 fi
222 if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then
223   echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
224 fi
225 if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then
226   echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
227 fi
228 if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then
229   echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
230 fi
231 if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then
232   echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
233 fi
234 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
235   echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
236 fi
237 if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
238   echo "const _PTRACE_TRACEME = 0" >> ${OUT}
239 fi
240
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}
260 fi
261
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}
269 fi
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}
275
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
285 fi
286
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}
291 fi
292 if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
293   echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
294 fi
295
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`
312 fi
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}
322
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}
333 fi
334
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          -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
362        >> ${OUT}
363
364 # The directory searching types.
365 # Prefer largefile variant if available.
366 dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true`
367 if test "$dirent" != ""; then
368   grep '^type _dirent64 ' gen-sysinfo.go
369 else
370   grep '^type _dirent ' gen-sysinfo.go
371 fi | sed -e 's/type _dirent64/type Dirent/' \
372          -e 's/type _dirent/type Dirent/' \
373          -e 's/d_name \[0+1\]/d_name [0+256]/' \
374          -e 's/d_name/Name/' \
375          -e 's/]int8/]byte/' \
376          -e 's/d_ino/Ino/' \
377          -e 's/d_off/Off/' \
378          -e 's/d_reclen/Reclen/' \
379          -e 's/d_type/Type/' \
380       >> ${OUT}
381 echo "type DIR _DIR" >> ${OUT}
382
383 # The rusage struct.
384 rusage=`grep '^type _rusage struct' gen-sysinfo.go`
385 if test "$rusage" != ""; then
386   rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
387   rusage=`echo $rusage | sed -e 's/^ *//'`
388   nrusage=
389   while test -n "$rusage"; do
390     field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
391     rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
392     # Drop the leading ru_, capitalize the next character.
393     field=`echo $field | sed -e 's/^ru_//'`
394     f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
395     r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
396     f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
397     # Fix _timeval _timespec, and _timestruc_t.
398     r=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
399     r=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
400     r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
401     field="$f$r"
402     nrusage="$nrusage $field;"
403   done
404   echo "type Rusage struct {$nrusage }" >> ${OUT}
405 else
406   echo "type Rusage struct {}" >> ${OUT}
407 fi
408
409 # The RUSAGE constants.
410 grep '^const _RUSAGE_' gen-sysinfo.go | \
411   sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
412
413 # The utsname struct.
414 grep '^type _utsname ' gen-sysinfo.go | \
415     sed -e 's/_utsname/Utsname/' \
416       -e 's/sysname/Sysname/' \
417       -e 's/nodename/Nodename/' \
418       -e 's/release/Release/' \
419       -e 's/version/Version/' \
420       -e 's/machine/Machine/' \
421       -e 's/domainname/Domainname/' \
422     >> ${OUT}
423
424 # The iovec struct.
425 iovec=`grep '^type _iovec ' gen-sysinfo.go`
426 iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
427 echo "type Iovec_len_t $iovec_len" >> ${OUT}
428 echo $iovec | \
429     sed -e 's/_iovec/Iovec/' \
430       -e 's/iov_base/Base/' \
431       -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
432     >> ${OUT}
433
434 # The msghdr struct.
435 msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
436 msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
437 echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
438 echo $msghdr | \
439     sed -e 's/_msghdr/Msghdr/' \
440       -e 's/msg_name/Name/' \
441       -e 's/msg_namelen/Namelen/' \
442       -e 's/msg_iov/Iov/' \
443       -e 's/msg_iovlen/Iovlen/' \
444       -e 's/_iovec/Iovec/' \
445       -e 's/msg_control/Control/' \
446       -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
447       -e 's/msg_flags/Flags/' \
448     >> ${OUT}
449
450 # The ip_mreq struct
451 grep '^type _ip_mreq ' gen-sysinfo.go | \
452     sed -e 's/_ip_mreq/IpMreq/' \
453       -e 's/imr_multiaddr/Multiaddr/' \
454       -e 's/imr_interface/Interface/' \
455       -e 's/_in_addr/[4]byte/g' \
456     >> ${OUT}
457
458 # Try to guess the type to use for fd_set.
459 fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
460 fds_bits_type="_C_long"
461 if test "$fd_set" != ""; then
462     fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
463 fi
464 echo "type fds_bits_type $fds_bits_type" >> ${OUT}
465
466 # The addrinfo struct.
467 grep '^type _addrinfo ' gen-sysinfo.go | \
468     sed -e 's/_addrinfo/Addrinfo/g' \
469       -e 's/ ai_/ Ai_/g' \
470     >> ${OUT}
471
472 # The addrinfo flags.
473 grep '^const _AI_' gen-sysinfo.go | \
474   sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
475
476 # The passwd struct.
477 grep '^type _passwd ' gen-sysinfo.go | \
478     sed -e 's/_passwd/Passwd/' \
479       -e 's/ pw_/ Pw_/g' \
480     >> ${OUT}
481
482 exit $?