+# The iovec struct.
+iovec=`grep '^type _iovec ' gen-sysinfo.go`
+iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
+echo "type Iovec_len_t $iovec_len" >> ${OUT}
+echo $iovec | \
+ sed -e 's/_iovec/Iovec/' \
+ -e 's/iov_base/Base/' \
+ -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
+ >> ${OUT}
+
+# The msghdr struct.
+msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
+msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
+echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
+echo $msghdr | \
+ sed -e 's/_msghdr/Msghdr/' \
+ -e 's/msg_name/Name/' \
+ -e 's/msg_namelen/Namelen/' \
+ -e 's/msg_iov/Iov/' \
+ -e 's/msg_iovlen/Iovlen/' \
+ -e 's/_iovec/Iovec/' \
+ -e 's/msg_control/Control/' \
+ -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
+ -e 's/msg_flags/Flags/' \
+ >> ${OUT}
+
+# The MSG_ flags for Msghdr.
+grep '^const _MSG_' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(MSG_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The cmsghdr struct.
+cmsghdr=`grep '^type _cmsghdr ' gen-sysinfo.go`
+if test -n "$cmsghdr"; then
+ cmsghdr_len=`echo $cmsghdr | sed -n -e 's/^.*cmsg_len \([^ ]*\);.*$/\1/p'`
+ echo "type Cmsghdr_len_t $cmsghdr_len" >> ${OUT}
+ echo "$cmsghdr" | \
+ sed -e 's/_cmsghdr/Cmsghdr/' \
+ -e 's/cmsg_len *[a-zA-Z0-9_]*/Len Cmsghdr_len_t/' \
+ -e 's/cmsg_level/Level/' \
+ -e 's/cmsg_type/Type/' \
+ -e 's/\[\]/[0]/' \
+ >> ${OUT}
+
+ # The size of the cmsghdr struct.
+ echo 'var SizeofCmsghdr = int(unsafe.Sizeof(Cmsghdr{}))' >> ${OUT}
+fi
+
+# The SCM_ flags for Cmsghdr.
+grep '^const _SCM_' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(SCM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The ucred struct.
+grep '^type _ucred ' gen-sysinfo.go | \
+ sed -e 's/_ucred/Ucred/' \
+ -e 's/pid/Pid/' \
+ -e 's/uid/Uid/' \
+ -e 's/gid/Gid/' \
+ >> ${OUT}
+
+# The size of the ucred struct.
+if grep 'type Ucred ' ${OUT} >/dev/null 2>&1; then
+ echo 'var SizeofUcred = int(unsafe.Sizeof(Ucred{}))' >> ${OUT}
+fi
+
+# The ip_mreq struct.
+grep '^type _ip_mreq ' gen-sysinfo.go | \
+ sed -e 's/_ip_mreq/IPMreq/' \
+ -e 's/imr_multiaddr/Multiaddr/' \
+ -e 's/imr_interface/Interface/' \
+ -e 's/_in_addr/[4]byte/g' \
+ >> ${OUT}
+
+# We need IPMreq to compile the net package.
+if ! grep 'type IPMreq ' ${OUT} >/dev/null 2>&1; then
+ echo 'type IPMreq struct { Multiaddr [4]byte; Interface [4]byte; }' >> ${OUT}
+fi
+
+# The size of the ip_mreq struct.
+echo 'var SizeofIPMreq = int(unsafe.Sizeof(IPMreq{}))' >> ${OUT}
+
+# The ipv6_mreq struct.
+grep '^type _ipv6_mreq ' gen-sysinfo.go | \
+ sed -e 's/_ipv6_mreq/IPv6Mreq/' \
+ -e 's/ipv6mr_multiaddr/Multiaddr/' \
+ -e 's/ipv6mr_interface/Interface/' \
+ -e 's/_in6_addr/[16]byte/' \
+ >> ${OUT}
+
+# We need IPv6Mreq to compile the net package.
+if ! grep 'type IPv6Mreq ' ${OUT} >/dev/null 2>&1; then
+ echo 'type IPv6Mreq struct { Multiaddr [16]byte; Interface uint32; }' >> ${OUT}
+fi
+
+# The size of the ipv6_mreq struct.
+echo 'var SizeofIPv6Mreq = int(unsafe.Sizeof(IPv6Mreq{}))' >> ${OUT}
+
+# The ip_mreqn struct.
+grep '^type _ip_mreqn ' gen-sysinfo.go | \
+ sed -e 's/_ip_mreqn/IPMreqn/' \
+ -e 's/imr_multiaddr/Multiaddr/' \
+ -e 's/imr_address/Address/' \
+ -e 's/imr_ifindex/Ifindex/' \
+ -e 's/_in_addr/[4]byte/g' \
+ >> ${OUT}
+
+# We need IPMreq to compile the net package.
+if ! grep 'type IPMreqn ' ${OUT} >/dev/null 2>&1; then
+ echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT}
+fi
+
+# The size of the ip_mreqn struct.
+echo 'var SizeofIPMreqn = int(unsafe.Sizeof(IPMreqn{}))' >> ${OUT}
+
+# Try to guess the type to use for fd_set.
+fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
+fds_bits_type="_C_long"
+if test "$fd_set" != ""; then
+ fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
+fi
+echo "type fds_bits_type $fds_bits_type" >> ${OUT}
+
+# The addrinfo struct.
+grep '^type _addrinfo ' gen-sysinfo.go | \
+ sed -e 's/_addrinfo/Addrinfo/g' \
+ -e 's/ ai_/ Ai_/g' \
+ >> ${OUT}
+
+# The addrinfo flags and errors.
+grep '^const _AI_' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+grep '^const _EAI_' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(EAI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The passwd struct.
+grep '^type _passwd ' gen-sysinfo.go | \
+ sed -e 's/_passwd/Passwd/' \
+ -e 's/ pw_/ Pw_/g' \
+ >> ${OUT}
+
+# The ioctl flags for the controlling TTY.
+grep '^const _TIOC' gen-sysinfo.go | \
+ grep -v '_val =' | \
+ sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+# We need TIOCGWINSZ.
+if ! grep '^const TIOCGWINSZ' ${OUT} >/dev/null 2>&1; then
+ if grep '^const _TIOCGWINSZ_val' ${OUT} >/dev/null 2>&1; then
+ echo 'const TIOCGWINSZ = _TIOCGWINSZ_val' >> ${OUT}
+ fi
+fi
+
+# The ioctl flags for terminal control
+grep '^const _TC[GS]ET' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but
+# needs handling in syscalls.exec.go.
+if ! grep '^const _TIOCSCTTY ' gen-sysinfo.go >/dev/null 2>&1; then
+ if grep '^const _TIOCNXCL ' gen-sysinfo.go >/dev/null 2>&1; then
+ echo "const TIOCSCTTY = TIOCNXCL" >> ${OUT}
+ fi
+fi
+
+# The nlmsghdr struct.
+grep '^type _nlmsghdr ' gen-sysinfo.go | \
+ sed -e 's/_nlmsghdr/NlMsghdr/' \
+ -e 's/nlmsg_len/Len/' \
+ -e 's/nlmsg_type/Type/' \
+ -e 's/nlmsg_flags/Flags/' \
+ -e 's/nlmsg_seq/Seq/' \
+ -e 's/nlmsg_pid/Pid/' \
+ >> ${OUT}
+
+# The nlmsg flags and operators.
+grep '^const _NLM' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# NLMSG_HDRLEN is defined as an expression using sizeof.
+if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev/null 2>&1; then
+ if grep '^type NlMsghdr ' ${OUT} > /dev/null 2>&1; then
+ echo 'var NLMSG_HDRLEN = int((unsafe.Sizeof(NlMsghdr{}) + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1))' >> ${OUT}
+ fi
+fi
+
+# The rtmsg struct.
+grep '^type _rtmsg ' gen-sysinfo.go | \
+ sed -e 's/_rtmsg/RtMsg/' \
+ -e 's/rtm_family/Family/' \
+ -e 's/rtm_dst_len/Dst_len/' \
+ -e 's/rtm_src_len/Src_len/' \
+ -e 's/rtm_tos/Tos/' \
+ -e 's/rtm_table/Table/' \
+ -e 's/rtm_protocol/Procotol/' \
+ -e 's/rtm_scope/Scope/' \
+ -e 's/rtm_type/Type/' \
+ -e 's/rtm_flags/Flags/' \
+ >> ${OUT}
+
+# The size of the rtmsg struct.
+if grep 'type RtMsg ' ${OUT} > /dev/null 2>&1; then
+ echo 'var SizeofRtMsg = int(unsafe.Sizeof(RtMsg{}))' >> ${OUT}
+fi
+
+# The rtgenmsg struct.
+grep '^type _rtgenmsg ' gen-sysinfo.go | \
+ sed -e 's/_rtgenmsg/RtGenmsg/' \
+ -e 's/rtgen_family/Family/' \
+ >> ${OUT}
+
+# The routing message flags.
+grep '^const _RTA' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+grep '^const _RTM' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The size of the rtgenmsg struct.
+if grep 'type RtGenmsg ' ${OUT} > /dev/null 2>&1; then
+ echo 'var SizeofRtGenmsg = int(unsafe.Sizeof(RtGenmsg{}))' >> ${OUT}
+fi
+
+# The ifinfomsg struct.
+grep '^type _ifinfomsg ' gen-sysinfo.go | \
+ sed -e 's/_ifinfomsg/IfInfomsg/' \
+ -e 's/ifi_family/Family/' \
+ -e 's/ifi_type/Type/' \
+ -e 's/ifi_index/Index/' \
+ -e 's/ifi_flags/Flags/' \
+ -e 's/ifi_change/Change/' \
+ >> ${OUT}
+
+# The interface information types and flags.
+grep '^const _IFA' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+grep '^const _IFLA' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+grep '^const _IFF' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+grep '^const _IFNAMSIZ' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(IFNAMSIZ[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+grep '^const _SIOC' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(SIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The size of the ifinfomsg struct.
+if grep 'type IfInfomsg ' ${OUT} > /dev/null 2>&1; then
+ echo 'var SizeofIfInfomsg = int(unsafe.Sizeof(IfInfomsg{}))' >> ${OUT}
+fi
+
+# The ifaddrmsg struct.
+grep '^type _ifaddrmsg ' gen-sysinfo.go | \
+ sed -e 's/_ifaddrmsg/IfAddrmsg/' \
+ -e 's/ifa_family/Family/' \
+ -e 's/ifa_prefixlen/Prefixlen/' \
+ -e 's/ifa_flags/Flags/' \
+ -e 's/ifa_scope/Scope/' \
+ -e 's/ifa_index/Index/' \
+ >> ${OUT}
+
+# The size of the ifaddrmsg struct.
+if grep 'type IfAddrmsg ' ${OUT} > /dev/null 2>&1; then
+ echo 'var SizeofIfAddrmsg = int(unsafe.Sizeof(IfAddrmsg{}))' >> ${OUT}
+fi
+
+# The rtattr struct.
+grep '^type _rtattr ' gen-sysinfo.go | \
+ sed -e 's/_rtattr/RtAttr/' \
+ -e 's/rta_len/Len/' \
+ -e 's/rta_type/Type/' \
+ >> ${OUT}
+
+# The size of the rtattr struct.
+if grep 'type RtAttr ' ${OUT} > /dev/null 2>&1; then
+ echo 'var SizeofRtAttr = int(unsafe.Sizeof(RtAttr{}))' >> ${OUT}
+fi
+
+# The termios struct.
+grep '^type _termios ' gen-sysinfo.go | \
+ sed -e 's/_termios/Termios/' \
+ -e 's/c_iflag/Iflag/' \
+ -e 's/c_oflag/Oflag/' \
+ -e 's/c_cflag/Cflag/' \
+ -e 's/c_lflag/Lflag/' \
+ -e 's/c_line/Line/' \
+ -e 's/c_cc/Cc/' \
+ -e 's/c_ispeed/Ispeed/' \
+ -e 's/c_ospeed/Ospeed/' \
+ >> ${OUT}
+
+# The termios constants.
+for n in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \
+ IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \
+ OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 TABDLY BSDLY VTDLY \
+ FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL CLOCAL \
+ LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE ECHO ECHOE ECHOK ECHONL \
+ ECHOCTL ECHOPRT ECHOKE DEFECHO FLUSHO NOFLSH TOSTOP PENDIN IEXTEN VINTR \
+ VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 VSWTCH VSTART VSTOP VSUSP \
+ VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS TCSANOW TCSADRAIN \
+ TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON TCIOFF TCION B0 B50 \
+ B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 \
+ B38400 B57600 B115200 B230400; do
+
+ grep "^const _$n " gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+done
+
+# The mount flags
+grep '^const _MS_' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(MS_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The fallocate flags.
+grep '^const _FALLOC_' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(FALLOC_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The statfs struct.
+# Prefer largefile variant if available.
+statfs=`grep '^type _statfs64 ' gen-sysinfo.go || true`
+if test "$statfs" != ""; then
+ grep '^type _statfs64 ' gen-sysinfo.go
+else
+ grep '^type _statfs ' gen-sysinfo.go
+fi | sed -e 's/type _statfs64/type Statfs_t/' \
+ -e 's/type _statfs/type Statfs_t/' \
+ -e 's/f_type/Type/' \
+ -e 's/f_bsize/Bsize/' \
+ -e 's/f_blocks/Blocks/' \
+ -e 's/f_bfree/Bfree/' \
+ -e 's/f_bavail/Bavail/' \
+ -e 's/f_files/Files/' \
+ -e 's/f_ffree/Ffree/' \
+ -e 's/f_fsid/Fsid/' \
+ -e 's/f_namelen/Namelen/' \
+ -e 's/f_frsize/Frsize/' \
+ -e 's/f_flags/Flags/' \
+ -e 's/f_spare/Spare/' \
+ >> ${OUT}
+
+# The timex struct.
+timex=`grep '^type _timex ' gen-sysinfo.go || true`
+if test "$timex" = ""; then
+ timex=`grep '^// type _timex ' gen-sysinfo.go || true`
+ if test "$timex" != ""; then
+ timex=`echo $timex | sed -e 's|// ||' -e 's/INVALID-bit-field/int32/g'`
+ fi
+fi
+if test "$timex" != ""; then
+ echo "$timex" | \
+ sed -e 's/_timex/Timex/' \
+ -e 's/modes/Modes/' \
+ -e 's/offset/Offset/' \
+ -e 's/freq/Freq/' \
+ -e 's/maxerror/Maxerror/' \
+ -e 's/esterror/Esterror/' \
+ -e 's/status/Status/' \
+ -e 's/constant/Constant/' \
+ -e 's/precision/Precision/' \
+ -e 's/tolerance/Tolerance/' \
+ -e 's/ time / Time /' \
+ -e 's/tick/Tick/' \
+ -e 's/ppsfreq/Ppsfreq/' \
+ -e 's/jitter/Jitter/' \
+ -e 's/shift/Shift/' \
+ -e 's/stabil/Stabil/' \
+ -e 's/jitcnt/Jitcnt/' \
+ -e 's/calcnt/Calcnt/' \
+ -e 's/errcnt/Errcnt/' \
+ -e 's/stbcnt/Stbcnt/' \
+ -e 's/tai/Tai/' \
+ -e 's/_timeval/Timeval/' \
+ >> ${OUT}
+fi
+
+# The rlimit struct.
+grep '^type _rlimit ' gen-sysinfo.go | \
+ sed -e 's/_rlimit/Rlimit/' \
+ -e 's/rlim_cur/Cur/' \
+ -e 's/rlim_max/Max/' \
+ >> ${OUT}
+
+# The RLIMIT constants.
+grep '^const _RLIMIT_' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(RLIMIT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The sysinfo struct.
+grep '^type _sysinfo ' gen-sysinfo.go | \
+ sed -e 's/_sysinfo/Sysinfo_t/' \
+ -e 's/uptime/Uptime/' \
+ -e 's/loads/Loads/' \
+ -e 's/totalram/Totalram/' \
+ -e 's/freeram/Freeram/' \
+ -e 's/sharedram/Sharedram/' \
+ -e 's/bufferram/Bufferram/' \
+ -e 's/totalswap/Totalswap/' \
+ -e 's/freeswap/Freeswap/' \
+ -e 's/procs/Procs/' \
+ -e 's/totalhigh/Totalhigh/' \
+ -e 's/freehigh/Freehigh/' \
+ -e 's/mem_unit/Unit/' \
+ >> ${OUT}
+
+# The ustat struct.
+grep '^type _ustat ' gen-sysinfo.go | \
+ sed -e 's/_ustat/Ustat_t/' \
+ -e 's/f_tfree/Tfree/' \
+ -e 's/f_tinode/Tinoe/' \
+ -e 's/f_fname/Fname/' \
+ -e 's/f_fpack/Fpack/' \
+ >> ${OUT}
+# Force it to be defined, as on some older GNU/Linux systems the
+# header file fails when using with <linux/filter.h>.
+if ! grep 'type _ustat ' gen-sysinfo.go >/dev/null 2>&1; then
+ echo 'type Ustat_t struct { Tfree int32; Tinoe uint64; Fname [5+1]int8; Fpack [5+1]int8; }' >> ${OUT}
+fi
+
+# The utimbuf struct.
+grep '^type _utimbuf ' gen-sysinfo.go | \
+ sed -e 's/_utimbuf/Utimbuf/' \
+ -e 's/actime/Actime/' \
+ -e 's/modtime/Modtime/' \
+ >> ${OUT}
+
+# The GNU/Linux LINUX_REBOOT flags.
+grep '^const _LINUX_REBOOT_' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(LINUX_REBOOT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The GNU/Linux sock_filter struct.
+grep '^type _sock_filter ' gen-sysinfo.go | \
+ sed -e 's/_sock_filter/SockFilter/' \
+ -e 's/code/Code/' \
+ -e 's/jt/Jt/' \
+ -e 's/jf/Jf/' \
+ -e 's/k /K /' \
+ >> ${OUT}
+
+# The GNU/Linux sock_fprog struct.
+grep '^type _sock_fprog ' gen-sysinfo.go | \
+ sed -e 's/_sock_fprog/SockFprog/' \
+ -e 's/len/Len/' \
+ -e 's/filter/Filter/' \
+ -e 's/_sock_filter/SockFilter/' \
+ >> ${OUT}
+
+# The Solaris 11 Update 1 _zone_net_addr_t struct.
+grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
+ sed -e 's/_in6_addr/[16]byte/' \
+ >> ${OUT}
+