khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # Copyright 2009 The Go Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style |
| 4 | # license that can be found in the LICENSE file. |
| 5 | |
| 6 | # Generate Go code listing errors and other #defined constant |
| 7 | # values (ENAMETOOLONG etc.), by asking the preprocessor |
| 8 | # about the definitions. |
| 9 | |
| 10 | unset LANG |
| 11 | export LC_ALL=C |
| 12 | export LC_CTYPE=C |
| 13 | |
| 14 | if test -z "$GOARCH" -o -z "$GOOS"; then |
| 15 | echo 1>&2 "GOARCH or GOOS not defined in environment" |
| 16 | exit 1 |
| 17 | fi |
| 18 | |
| 19 | # Check that we are using the new build system if we should |
| 20 | if [[ "$GOOS" = "linux" ]] && [[ "$GOLANG_SYS_BUILD" != "docker" ]]; then |
| 21 | echo 1>&2 "In the Docker based build system, mkerrors should not be called directly." |
| 22 | echo 1>&2 "See README.md" |
| 23 | exit 1 |
| 24 | fi |
| 25 | |
| 26 | if [[ "$GOOS" = "aix" ]]; then |
| 27 | CC=${CC:-gcc} |
| 28 | else |
| 29 | CC=${CC:-cc} |
| 30 | fi |
| 31 | |
| 32 | if [[ "$GOOS" = "solaris" ]]; then |
| 33 | # Assumes GNU versions of utilities in PATH. |
| 34 | export PATH=/usr/gnu/bin:$PATH |
| 35 | fi |
| 36 | |
| 37 | uname=$(uname) |
| 38 | |
| 39 | includes_AIX=' |
| 40 | #include <net/if.h> |
| 41 | #include <net/netopt.h> |
| 42 | #include <netinet/ip_mroute.h> |
| 43 | #include <sys/protosw.h> |
| 44 | #include <sys/stropts.h> |
| 45 | #include <sys/mman.h> |
| 46 | #include <sys/poll.h> |
Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 47 | #include <sys/select.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 48 | #include <sys/termio.h> |
| 49 | #include <termios.h> |
| 50 | #include <fcntl.h> |
| 51 | |
| 52 | #define AF_LOCAL AF_UNIX |
| 53 | ' |
| 54 | |
| 55 | includes_Darwin=' |
| 56 | #define _DARWIN_C_SOURCE |
| 57 | #define KERNEL |
| 58 | #define _DARWIN_USE_64_BIT_INODE |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 59 | #define __APPLE_USE_RFC_3542 |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 60 | #include <stdint.h> |
| 61 | #include <sys/attr.h> |
Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 62 | #include <sys/clonefile.h> |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 63 | #include <sys/kern_control.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 64 | #include <sys/types.h> |
| 65 | #include <sys/event.h> |
| 66 | #include <sys/ptrace.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 67 | #include <sys/select.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 68 | #include <sys/socket.h> |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 69 | #include <sys/un.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 70 | #include <sys/sockio.h> |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 71 | #include <sys/sys_domain.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 72 | #include <sys/sysctl.h> |
| 73 | #include <sys/mman.h> |
| 74 | #include <sys/mount.h> |
| 75 | #include <sys/utsname.h> |
| 76 | #include <sys/wait.h> |
| 77 | #include <sys/xattr.h> |
| 78 | #include <net/bpf.h> |
| 79 | #include <net/if.h> |
| 80 | #include <net/if_types.h> |
| 81 | #include <net/route.h> |
| 82 | #include <netinet/in.h> |
| 83 | #include <netinet/ip.h> |
| 84 | #include <termios.h> |
| 85 | ' |
| 86 | |
| 87 | includes_DragonFly=' |
| 88 | #include <sys/types.h> |
| 89 | #include <sys/event.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 90 | #include <sys/select.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 91 | #include <sys/socket.h> |
| 92 | #include <sys/sockio.h> |
| 93 | #include <sys/stat.h> |
| 94 | #include <sys/sysctl.h> |
| 95 | #include <sys/mman.h> |
| 96 | #include <sys/mount.h> |
| 97 | #include <sys/wait.h> |
| 98 | #include <sys/ioctl.h> |
| 99 | #include <net/bpf.h> |
| 100 | #include <net/if.h> |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 101 | #include <net/if_clone.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 102 | #include <net/if_types.h> |
| 103 | #include <net/route.h> |
| 104 | #include <netinet/in.h> |
| 105 | #include <termios.h> |
| 106 | #include <netinet/ip.h> |
| 107 | #include <net/ip_mroute/ip_mroute.h> |
| 108 | ' |
| 109 | |
| 110 | includes_FreeBSD=' |
| 111 | #include <sys/capsicum.h> |
| 112 | #include <sys/param.h> |
| 113 | #include <sys/types.h> |
Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 114 | #include <sys/disk.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 115 | #include <sys/event.h> |
Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 116 | #include <sys/sched.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 117 | #include <sys/select.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 118 | #include <sys/socket.h> |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 119 | #include <sys/un.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 120 | #include <sys/sockio.h> |
| 121 | #include <sys/stat.h> |
| 122 | #include <sys/sysctl.h> |
| 123 | #include <sys/mman.h> |
| 124 | #include <sys/mount.h> |
| 125 | #include <sys/wait.h> |
| 126 | #include <sys/ioctl.h> |
| 127 | #include <net/bpf.h> |
| 128 | #include <net/if.h> |
| 129 | #include <net/if_types.h> |
| 130 | #include <net/route.h> |
| 131 | #include <netinet/in.h> |
| 132 | #include <termios.h> |
| 133 | #include <netinet/ip.h> |
| 134 | #include <netinet/ip_mroute.h> |
| 135 | #include <sys/extattr.h> |
| 136 | |
| 137 | #if __FreeBSD__ >= 10 |
| 138 | #define IFT_CARP 0xf8 // IFT_CARP is deprecated in FreeBSD 10 |
| 139 | #undef SIOCAIFADDR |
| 140 | #define SIOCAIFADDR _IOW(105, 26, struct oifaliasreq) // ifaliasreq contains if_data |
| 141 | #undef SIOCSIFPHYADDR |
| 142 | #define SIOCSIFPHYADDR _IOW(105, 70, struct oifaliasreq) // ifaliasreq contains if_data |
| 143 | #endif |
| 144 | ' |
| 145 | |
| 146 | includes_Linux=' |
| 147 | #define _LARGEFILE_SOURCE |
| 148 | #define _LARGEFILE64_SOURCE |
| 149 | #ifndef __LP64__ |
| 150 | #define _FILE_OFFSET_BITS 64 |
| 151 | #endif |
| 152 | #define _GNU_SOURCE |
| 153 | |
| 154 | // <sys/ioctl.h> is broken on powerpc64, as it fails to include definitions of |
| 155 | // these structures. We just include them copied from <bits/termios.h>. |
| 156 | #if defined(__powerpc__) |
| 157 | struct sgttyb { |
| 158 | char sg_ispeed; |
| 159 | char sg_ospeed; |
| 160 | char sg_erase; |
| 161 | char sg_kill; |
| 162 | short sg_flags; |
| 163 | }; |
| 164 | |
| 165 | struct tchars { |
| 166 | char t_intrc; |
| 167 | char t_quitc; |
| 168 | char t_startc; |
| 169 | char t_stopc; |
| 170 | char t_eofc; |
| 171 | char t_brkc; |
| 172 | }; |
| 173 | |
| 174 | struct ltchars { |
| 175 | char t_suspc; |
| 176 | char t_dsuspc; |
| 177 | char t_rprntc; |
| 178 | char t_flushc; |
| 179 | char t_werasc; |
| 180 | char t_lnextc; |
| 181 | }; |
| 182 | #endif |
| 183 | |
| 184 | #include <bits/sockaddr.h> |
| 185 | #include <sys/epoll.h> |
| 186 | #include <sys/eventfd.h> |
| 187 | #include <sys/inotify.h> |
| 188 | #include <sys/ioctl.h> |
| 189 | #include <sys/mman.h> |
| 190 | #include <sys/mount.h> |
| 191 | #include <sys/prctl.h> |
| 192 | #include <sys/stat.h> |
| 193 | #include <sys/types.h> |
| 194 | #include <sys/time.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 195 | #include <sys/select.h> |
Stephane Barbarie | 260a563 | 2019-02-26 16:12:49 -0500 | [diff] [blame] | 196 | #include <sys/signalfd.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 197 | #include <sys/socket.h> |
Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 198 | #include <sys/timerfd.h> |
| 199 | #include <sys/uio.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 200 | #include <sys/xattr.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 201 | #include <linux/bpf.h> |
| 202 | #include <linux/can.h> |
Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 203 | #include <linux/can/error.h> |
| 204 | #include <linux/can/raw.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 205 | #include <linux/capability.h> |
| 206 | #include <linux/cryptouser.h> |
Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 207 | #include <linux/devlink.h> |
| 208 | #include <linux/dm-ioctl.h> |
Stephane Barbarie | 260a563 | 2019-02-26 16:12:49 -0500 | [diff] [blame] | 209 | #include <linux/errqueue.h> |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 210 | #include <linux/ethtool_netlink.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 211 | #include <linux/falloc.h> |
| 212 | #include <linux/fanotify.h> |
| 213 | #include <linux/filter.h> |
| 214 | #include <linux/fs.h> |
Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 215 | #include <linux/fscrypt.h> |
| 216 | #include <linux/fsverity.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 217 | #include <linux/genetlink.h> |
| 218 | #include <linux/hdreg.h> |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 219 | #include <linux/hidraw.h> |
| 220 | #include <linux/icmp.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 221 | #include <linux/icmpv6.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 222 | #include <linux/if.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 223 | #include <linux/if_addr.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 224 | #include <linux/if_alg.h> |
| 225 | #include <linux/if_arp.h> |
| 226 | #include <linux/if_ether.h> |
| 227 | #include <linux/if_ppp.h> |
| 228 | #include <linux/if_tun.h> |
| 229 | #include <linux/if_packet.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 230 | #include <linux/if_xdp.h> |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 231 | #include <linux/input.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 232 | #include <linux/kexec.h> |
| 233 | #include <linux/keyctl.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 234 | #include <linux/loop.h> |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 235 | #include <linux/lwtunnel.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 236 | #include <linux/magic.h> |
| 237 | #include <linux/memfd.h> |
| 238 | #include <linux/module.h> |
| 239 | #include <linux/netfilter/nfnetlink.h> |
| 240 | #include <linux/netlink.h> |
| 241 | #include <linux/net_namespace.h> |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 242 | #include <linux/nfc.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 243 | #include <linux/nsfs.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 244 | #include <linux/perf_event.h> |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 245 | #include <linux/pps.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 246 | #include <linux/ptrace.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 247 | #include <linux/random.h> |
| 248 | #include <linux/reboot.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 249 | #include <linux/rtc.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 250 | #include <linux/rtnetlink.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 251 | #include <linux/sched.h> |
| 252 | #include <linux/seccomp.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 253 | #include <linux/serial.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 254 | #include <linux/sockios.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 255 | #include <linux/taskstats.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 256 | #include <linux/tipc.h> |
| 257 | #include <linux/vm_sockets.h> |
| 258 | #include <linux/wait.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 259 | #include <linux/watchdog.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 260 | |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 261 | #include <mtd/ubi-user.h> |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 262 | #include <mtd/mtd-user.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 263 | #include <net/route.h> |
| 264 | |
| 265 | #if defined(__sparc__) |
| 266 | // On sparc{,64}, the kernel defines struct termios2 itself which clashes with the |
| 267 | // definition in glibc. As only the error constants are needed here, include the |
| 268 | // generic termibits.h (which is included by termbits.h on sparc). |
| 269 | #include <asm-generic/termbits.h> |
| 270 | #else |
| 271 | #include <asm/termbits.h> |
| 272 | #endif |
| 273 | |
| 274 | #ifndef MSG_FASTOPEN |
| 275 | #define MSG_FASTOPEN 0x20000000 |
| 276 | #endif |
| 277 | |
| 278 | #ifndef PTRACE_GETREGS |
| 279 | #define PTRACE_GETREGS 0xc |
| 280 | #endif |
| 281 | |
| 282 | #ifndef PTRACE_SETREGS |
| 283 | #define PTRACE_SETREGS 0xd |
| 284 | #endif |
| 285 | |
| 286 | #ifndef SOL_NETLINK |
| 287 | #define SOL_NETLINK 270 |
| 288 | #endif |
| 289 | |
| 290 | #ifdef SOL_BLUETOOTH |
| 291 | // SPARC includes this in /usr/include/sparc64-linux-gnu/bits/socket.h |
| 292 | // but it is already in bluetooth_linux.go |
| 293 | #undef SOL_BLUETOOTH |
| 294 | #endif |
| 295 | |
| 296 | // Certain constants are missing from the fs/crypto UAPI |
| 297 | #define FS_KEY_DESC_PREFIX "fscrypt:" |
| 298 | #define FS_KEY_DESC_PREFIX_SIZE 8 |
| 299 | #define FS_MAX_KEY_SIZE 64 |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 300 | |
| 301 | // The code generator produces -0x1 for (~0), but an unsigned value is necessary |
| 302 | // for the tipc_subscr timeout __u32 field. |
| 303 | #undef TIPC_WAIT_FOREVER |
| 304 | #define TIPC_WAIT_FOREVER 0xffffffff |
Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 305 | |
| 306 | // Copied from linux/l2tp.h |
| 307 | // Including linux/l2tp.h here causes conflicts between linux/in.h |
| 308 | // and netinet/in.h included via net/route.h above. |
| 309 | #define IPPROTO_L2TP 115 |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 310 | |
| 311 | // Copied from linux/hid.h. |
| 312 | // Keep in sync with the size of the referenced fields. |
| 313 | #define _HIDIOCGRAWNAME_LEN 128 // sizeof_field(struct hid_device, name) |
| 314 | #define _HIDIOCGRAWPHYS_LEN 64 // sizeof_field(struct hid_device, phys) |
| 315 | #define _HIDIOCGRAWUNIQ_LEN 64 // sizeof_field(struct hid_device, uniq) |
| 316 | |
| 317 | #define _HIDIOCGRAWNAME HIDIOCGRAWNAME(_HIDIOCGRAWNAME_LEN) |
| 318 | #define _HIDIOCGRAWPHYS HIDIOCGRAWPHYS(_HIDIOCGRAWPHYS_LEN) |
| 319 | #define _HIDIOCGRAWUNIQ HIDIOCGRAWUNIQ(_HIDIOCGRAWUNIQ_LEN) |
| 320 | |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 321 | ' |
| 322 | |
| 323 | includes_NetBSD=' |
| 324 | #include <sys/types.h> |
| 325 | #include <sys/param.h> |
| 326 | #include <sys/event.h> |
| 327 | #include <sys/extattr.h> |
| 328 | #include <sys/mman.h> |
| 329 | #include <sys/mount.h> |
Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 330 | #include <sys/sched.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 331 | #include <sys/select.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 332 | #include <sys/socket.h> |
| 333 | #include <sys/sockio.h> |
| 334 | #include <sys/sysctl.h> |
| 335 | #include <sys/termios.h> |
| 336 | #include <sys/ttycom.h> |
| 337 | #include <sys/wait.h> |
| 338 | #include <net/bpf.h> |
| 339 | #include <net/if.h> |
| 340 | #include <net/if_types.h> |
| 341 | #include <net/route.h> |
| 342 | #include <netinet/in.h> |
| 343 | #include <netinet/in_systm.h> |
| 344 | #include <netinet/ip.h> |
| 345 | #include <netinet/ip_mroute.h> |
| 346 | #include <netinet/if_ether.h> |
| 347 | |
| 348 | // Needed since <sys/param.h> refers to it... |
| 349 | #define schedppq 1 |
| 350 | ' |
| 351 | |
| 352 | includes_OpenBSD=' |
| 353 | #include <sys/types.h> |
| 354 | #include <sys/param.h> |
| 355 | #include <sys/event.h> |
| 356 | #include <sys/mman.h> |
| 357 | #include <sys/mount.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 358 | #include <sys/select.h> |
Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 359 | #include <sys/sched.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 360 | #include <sys/socket.h> |
| 361 | #include <sys/sockio.h> |
| 362 | #include <sys/stat.h> |
| 363 | #include <sys/sysctl.h> |
| 364 | #include <sys/termios.h> |
| 365 | #include <sys/ttycom.h> |
| 366 | #include <sys/unistd.h> |
| 367 | #include <sys/wait.h> |
| 368 | #include <net/bpf.h> |
| 369 | #include <net/if.h> |
| 370 | #include <net/if_types.h> |
| 371 | #include <net/if_var.h> |
| 372 | #include <net/route.h> |
| 373 | #include <netinet/in.h> |
| 374 | #include <netinet/in_systm.h> |
| 375 | #include <netinet/ip.h> |
| 376 | #include <netinet/ip_mroute.h> |
| 377 | #include <netinet/if_ether.h> |
| 378 | #include <net/if_bridge.h> |
| 379 | |
| 380 | // We keep some constants not supported in OpenBSD 5.5 and beyond for |
| 381 | // the promise of compatibility. |
| 382 | #define EMUL_ENABLED 0x1 |
| 383 | #define EMUL_NATIVE 0x2 |
| 384 | #define IPV6_FAITH 0x1d |
| 385 | #define IPV6_OPTIONS 0x1 |
| 386 | #define IPV6_RTHDR_STRICT 0x1 |
| 387 | #define IPV6_SOCKOPT_RESERVED1 0x3 |
| 388 | #define SIOCGIFGENERIC 0xc020693a |
| 389 | #define SIOCSIFGENERIC 0x80206939 |
| 390 | #define WALTSIG 0x4 |
| 391 | ' |
| 392 | |
| 393 | includes_SunOS=' |
| 394 | #include <limits.h> |
| 395 | #include <sys/types.h> |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 396 | #include <sys/select.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 397 | #include <sys/socket.h> |
| 398 | #include <sys/sockio.h> |
| 399 | #include <sys/stat.h> |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 400 | #include <sys/stream.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 401 | #include <sys/mman.h> |
| 402 | #include <sys/wait.h> |
| 403 | #include <sys/ioctl.h> |
| 404 | #include <sys/mkdev.h> |
| 405 | #include <net/bpf.h> |
| 406 | #include <net/if.h> |
| 407 | #include <net/if_arp.h> |
| 408 | #include <net/if_types.h> |
| 409 | #include <net/route.h> |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 410 | #include <netinet/icmp6.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 411 | #include <netinet/in.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 412 | #include <netinet/ip.h> |
| 413 | #include <netinet/ip_mroute.h> |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 414 | #include <termios.h> |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 415 | ' |
| 416 | |
| 417 | |
| 418 | includes=' |
| 419 | #include <sys/types.h> |
| 420 | #include <sys/file.h> |
| 421 | #include <fcntl.h> |
| 422 | #include <dirent.h> |
| 423 | #include <sys/socket.h> |
| 424 | #include <netinet/in.h> |
| 425 | #include <netinet/ip.h> |
| 426 | #include <netinet/ip6.h> |
| 427 | #include <netinet/tcp.h> |
| 428 | #include <errno.h> |
| 429 | #include <sys/signal.h> |
| 430 | #include <signal.h> |
| 431 | #include <sys/resource.h> |
| 432 | #include <time.h> |
| 433 | ' |
| 434 | ccflags="$@" |
| 435 | |
| 436 | # Write go tool cgo -godefs input. |
| 437 | ( |
| 438 | echo package unix |
| 439 | echo |
| 440 | echo '/*' |
| 441 | indirect="includes_$(uname)" |
| 442 | echo "${!indirect} $includes" |
| 443 | echo '*/' |
| 444 | echo 'import "C"' |
| 445 | echo 'import "syscall"' |
| 446 | echo |
| 447 | echo 'const (' |
| 448 | |
| 449 | # The gcc command line prints all the #defines |
| 450 | # it encounters while processing the input |
| 451 | echo "${!indirect} $includes" | $CC -x c - -E -dM $ccflags | |
| 452 | awk ' |
| 453 | $1 != "#define" || $2 ~ /\(/ || $3 == "" {next} |
| 454 | |
| 455 | $2 ~ /^E([ABCD]X|[BIS]P|[SD]I|S|FL)$/ {next} # 386 registers |
| 456 | $2 ~ /^(SIGEV_|SIGSTKSZ|SIGRT(MIN|MAX))/ {next} |
| 457 | $2 ~ /^(SCM_SRCRT)$/ {next} |
| 458 | $2 ~ /^(MAP_FAILED)$/ {next} |
| 459 | $2 ~ /^ELF_.*$/ {next}# <asm/elf.h> contains ELF_ARCH, etc. |
| 460 | |
| 461 | $2 ~ /^EXTATTR_NAMESPACE_NAMES/ || |
| 462 | $2 ~ /^EXTATTR_NAMESPACE_[A-Z]+_STRING/ {next} |
| 463 | |
| 464 | $2 !~ /^ECCAPBITS/ && |
| 465 | $2 !~ /^ETH_/ && |
| 466 | $2 !~ /^EPROC_/ && |
| 467 | $2 !~ /^EQUIV_/ && |
| 468 | $2 !~ /^EXPR_/ && |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 469 | $2 !~ /^EVIOC/ && |
| 470 | $2 !~ /^EV_/ && |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 471 | $2 ~ /^E[A-Z0-9_]+$/ || |
| 472 | $2 ~ /^B[0-9_]+$/ || |
| 473 | $2 ~ /^(OLD|NEW)DEV$/ || |
| 474 | $2 == "BOTHER" || |
| 475 | $2 ~ /^CI?BAUD(EX)?$/ || |
| 476 | $2 == "IBSHIFT" || |
| 477 | $2 ~ /^V[A-Z0-9]+$/ || |
| 478 | $2 ~ /^CS[A-Z0-9]/ || |
| 479 | $2 ~ /^I(SIG|CANON|CRNL|UCLC|EXTEN|MAXBEL|STRIP|UTF8)$/ || |
| 480 | $2 ~ /^IGN/ || |
| 481 | $2 ~ /^IX(ON|ANY|OFF)$/ || |
| 482 | $2 ~ /^IN(LCR|PCK)$/ || |
| 483 | $2 !~ "X86_CR3_PCID_NOFLUSH" && |
| 484 | $2 ~ /(^FLU?SH)|(FLU?SH$)/ || |
| 485 | $2 ~ /^C(LOCAL|READ|MSPAR|RTSCTS)$/ || |
| 486 | $2 == "BRKINT" || |
| 487 | $2 == "HUPCL" || |
| 488 | $2 == "PENDIN" || |
| 489 | $2 == "TOSTOP" || |
| 490 | $2 == "XCASE" || |
| 491 | $2 == "ALTWERASE" || |
| 492 | $2 == "NOKERNINFO" || |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 493 | $2 == "NFDBITS" || |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 494 | $2 ~ /^PAR/ || |
| 495 | $2 ~ /^SIG[^_]/ || |
| 496 | $2 ~ /^O[CNPFPL][A-Z]+[^_][A-Z]+$/ || |
| 497 | $2 ~ /^(NL|CR|TAB|BS|VT|FF)DLY$/ || |
| 498 | $2 ~ /^(NL|CR|TAB|BS|VT|FF)[0-9]$/ || |
| 499 | $2 ~ /^O?XTABS$/ || |
| 500 | $2 ~ /^TC[IO](ON|OFF)$/ || |
| 501 | $2 ~ /^IN_/ || |
| 502 | $2 ~ /^LOCK_(SH|EX|NB|UN)$/ || |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 503 | $2 ~ /^LO_(KEY|NAME)_SIZE$/ || |
| 504 | $2 ~ /^LOOP_(CLR|CTL|GET|SET)_/ || |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 505 | $2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|TCP|MCAST|EVFILT|NOTE|SHUT|PROT|MAP|MFD|T?PACKET|MSG|SCM|MCL|DT|MADV|PR|LOCAL)_/ || |
| 506 | $2 ~ /^NFC_(GENL|PROTO|COMM|RF|SE|DIRECTION|LLCP|SOCKPROTO)_/ || |
| 507 | $2 ~ /^NFC_.*_(MAX)?SIZE$/ || |
| 508 | $2 ~ /^RAW_PAYLOAD_/ || |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 509 | $2 ~ /^TP_STATUS_/ || |
| 510 | $2 ~ /^FALLOC_/ || |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 511 | $2 ~ /^ICMPV?6?_(FILTER|SEC)/ || |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 512 | $2 == "SOMAXCONN" || |
| 513 | $2 == "NAME_MAX" || |
| 514 | $2 == "IFNAMSIZ" || |
| 515 | $2 ~ /^CTL_(HW|KERN|MAXNAME|NET|QUERY)$/ || |
| 516 | $2 ~ /^KERN_(HOSTNAME|OS(RELEASE|TYPE)|VERSION)$/ || |
| 517 | $2 ~ /^HW_MACHINE$/ || |
| 518 | $2 ~ /^SYSCTL_VERS/ || |
| 519 | $2 !~ "MNT_BITS" && |
| 520 | $2 ~ /^(MS|MNT|UMOUNT)_/ || |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 521 | $2 ~ /^NS_GET_/ || |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 522 | $2 ~ /^TUN(SET|GET|ATTACH|DETACH)/ || |
Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 523 | $2 ~ /^(O|F|[ES]?FD|NAME|S|PTRACE|PT|TFD)_/ || |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 524 | $2 ~ /^KEXEC_/ || |
| 525 | $2 ~ /^LINUX_REBOOT_CMD_/ || |
| 526 | $2 ~ /^LINUX_REBOOT_MAGIC[12]$/ || |
| 527 | $2 ~ /^MODULE_INIT_/ || |
| 528 | $2 !~ "NLA_TYPE_MASK" && |
Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 529 | $2 !~ /^RTC_VL_(ACCURACY|BACKUP|DATA)/ && |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 530 | $2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTC|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P|NETNSA)_/ || |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 531 | $2 ~ /^FIORDCHK$/ || |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 532 | $2 ~ /^SIOC/ || |
| 533 | $2 ~ /^TIOC/ || |
| 534 | $2 ~ /^TCGET/ || |
| 535 | $2 ~ /^TCSET/ || |
| 536 | $2 ~ /^TC(FLSH|SBRKP?|XONC)$/ || |
| 537 | $2 !~ "RTF_BITS" && |
Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 538 | $2 ~ /^(IFF|IFT|NET_RT|RTM(GRP)?|RTF|RTV|RTA|RTAX)_/ || |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 539 | $2 ~ /^BIOC/ || |
Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 540 | $2 ~ /^DIOC/ || |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 541 | $2 ~ /^RUSAGE_(SELF|CHILDREN|THREAD)/ || |
| 542 | $2 ~ /^RLIMIT_(AS|CORE|CPU|DATA|FSIZE|LOCKS|MEMLOCK|MSGQUEUE|NICE|NOFILE|NPROC|RSS|RTPRIO|RTTIME|SIGPENDING|STACK)|RLIM_INFINITY/ || |
| 543 | $2 ~ /^PRIO_(PROCESS|PGRP|USER)/ || |
| 544 | $2 ~ /^CLONE_[A-Z_]+/ || |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 545 | $2 !~ /^(BPF_TIMEVAL|BPF_FIB_LOOKUP_[A-Z]+)$/ && |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 546 | $2 ~ /^(BPF|DLT)_/ || |
| 547 | $2 ~ /^(CLOCK|TIMER)_/ || |
| 548 | $2 ~ /^CAN_/ || |
| 549 | $2 ~ /^CAP_/ || |
Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 550 | $2 ~ /^CP_/ || |
| 551 | $2 ~ /^CPUSTATES$/ || |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 552 | $2 ~ /^CTLIOCGINFO$/ || |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 553 | $2 ~ /^ALG_/ || |
Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 554 | $2 ~ /^FI(CLONE|DEDUPERANGE)/ || |
| 555 | $2 ~ /^FS_(POLICY_FLAGS|KEY_DESC|ENCRYPTION_MODE|[A-Z0-9_]+_KEY_SIZE)/ || |
| 556 | $2 ~ /^FS_IOC_.*(ENCRYPTION|VERITY|[GS]ETFLAGS)/ || |
| 557 | $2 ~ /^FS_VERITY_/ || |
| 558 | $2 ~ /^FSCRYPT_/ || |
| 559 | $2 ~ /^DM_/ || |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 560 | $2 ~ /^GRND_/ || |
Stephane Barbarie | 260a563 | 2019-02-26 16:12:49 -0500 | [diff] [blame] | 561 | $2 ~ /^RND/ || |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 562 | $2 ~ /^KEY_(SPEC|REQKEY_DEFL)_/ || |
| 563 | $2 ~ /^KEYCTL_/ || |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 564 | $2 ~ /^PERF_/ || |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 565 | $2 ~ /^SECCOMP_MODE_/ || |
| 566 | $2 ~ /^SPLICE_/ || |
| 567 | $2 ~ /^SYNC_FILE_RANGE_/ || |
| 568 | $2 !~ /^AUDIT_RECORD_MAGIC/ && |
| 569 | $2 !~ /IOC_MAGIC/ && |
| 570 | $2 ~ /^[A-Z][A-Z0-9_]+_MAGIC2?$/ || |
| 571 | $2 ~ /^(VM|VMADDR)_/ || |
| 572 | $2 ~ /^IOCTL_VM_SOCKETS_/ || |
| 573 | $2 ~ /^(TASKSTATS|TS)_/ || |
| 574 | $2 ~ /^CGROUPSTATS_/ || |
| 575 | $2 ~ /^GENL_/ || |
| 576 | $2 ~ /^STATX_/ || |
| 577 | $2 ~ /^RENAME/ || |
| 578 | $2 ~ /^UBI_IOC[A-Z]/ || |
| 579 | $2 ~ /^UTIME_/ || |
| 580 | $2 ~ /^XATTR_(CREATE|REPLACE|NO(DEFAULT|FOLLOW|SECURITY)|SHOWCOMPRESSION)/ || |
| 581 | $2 ~ /^ATTR_(BIT_MAP_COUNT|(CMN|VOL|FILE)_)/ || |
| 582 | $2 ~ /^FSOPT_/ || |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 583 | $2 ~ /^WDIO[CFS]_/ || |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 584 | $2 ~ /^NFN/ || |
| 585 | $2 ~ /^XDP_/ || |
Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 586 | $2 ~ /^RWF_/ || |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 587 | $2 ~ /^(HDIO|WIN|SMART)_/ || |
Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 588 | $2 ~ /^CRYPTO_/ || |
| 589 | $2 ~ /^TIPC_/ || |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 590 | $2 !~ "DEVLINK_RELOAD_LIMITS_VALID_MASK" && |
Andrea Campanella | 3614a92 | 2021-02-25 12:40:42 +0100 | [diff] [blame] | 591 | $2 ~ /^DEVLINK_/ || |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 592 | $2 ~ /^ETHTOOL_/ || |
| 593 | $2 ~ /^LWTUNNEL_IP/ || |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 594 | $2 !~ "WMESGLEN" && |
| 595 | $2 ~ /^W[A-Z0-9]+$/ || |
| 596 | $2 ~/^PPPIOC/ || |
William Kurkian | daa6bb2 | 2019-03-07 12:26:28 -0500 | [diff] [blame] | 597 | $2 ~ /^FAN_|FANOTIFY_/ || |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 598 | $2 == "HID_MAX_DESCRIPTOR_SIZE" || |
| 599 | $2 ~ /^_?HIDIOC/ || |
| 600 | $2 ~ /^BUS_(USB|HIL|BLUETOOTH|VIRTUAL)$/ || |
| 601 | $2 ~ /^MTD/ || |
| 602 | $2 ~ /^OTP/ || |
| 603 | $2 ~ /^MEM/ || |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 604 | $2 ~ /^BLK[A-Z]*(GET$|SET$|BUF$|PART$|SIZE)/ {printf("\t%s = C.%s\n", $2, $2)} |
| 605 | $2 ~ /^__WCOREFLAG$/ {next} |
| 606 | $2 ~ /^__W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", substr($2,3), $2)} |
| 607 | |
| 608 | {next} |
| 609 | ' | sort |
| 610 | |
| 611 | echo ')' |
| 612 | ) >_const.go |
| 613 | |
| 614 | # Pull out the error names for later. |
| 615 | errors=$( |
| 616 | echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags | |
| 617 | awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print $2 }' | |
| 618 | sort |
| 619 | ) |
| 620 | |
| 621 | # Pull out the signal names for later. |
| 622 | signals=$( |
| 623 | echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags | |
| 624 | awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print $2 }' | |
| 625 | egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' | |
| 626 | sort |
| 627 | ) |
| 628 | |
| 629 | # Again, writing regexps to a file. |
| 630 | echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags | |
| 631 | awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print "^\t" $2 "[ \t]*=" }' | |
| 632 | sort >_error.grep |
| 633 | echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags | |
| 634 | awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print "^\t" $2 "[ \t]*=" }' | |
| 635 | egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' | |
| 636 | sort >_signal.grep |
| 637 | |
| 638 | echo '// mkerrors.sh' "$@" |
| 639 | echo '// Code generated by the command above; see README.md. DO NOT EDIT.' |
| 640 | echo |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 641 | echo "//go:build ${GOARCH} && ${GOOS}" |
khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 642 | echo "// +build ${GOARCH},${GOOS}" |
| 643 | echo |
| 644 | go tool cgo -godefs -- "$@" _const.go >_error.out |
| 645 | cat _error.out | grep -vf _error.grep | grep -vf _signal.grep |
| 646 | echo |
| 647 | echo '// Errors' |
| 648 | echo 'const (' |
| 649 | cat _error.out | grep -f _error.grep | sed 's/=\(.*\)/= syscall.Errno(\1)/' |
| 650 | echo ')' |
| 651 | |
| 652 | echo |
| 653 | echo '// Signals' |
| 654 | echo 'const (' |
| 655 | cat _error.out | grep -f _signal.grep | sed 's/=\(.*\)/= syscall.Signal(\1)/' |
| 656 | echo ')' |
| 657 | |
| 658 | # Run C program to print error and syscall strings. |
| 659 | ( |
| 660 | echo -E " |
| 661 | #include <stdio.h> |
| 662 | #include <stdlib.h> |
| 663 | #include <errno.h> |
| 664 | #include <ctype.h> |
| 665 | #include <string.h> |
| 666 | #include <signal.h> |
| 667 | |
| 668 | #define nelem(x) (sizeof(x)/sizeof((x)[0])) |
| 669 | |
| 670 | enum { A = 'A', Z = 'Z', a = 'a', z = 'z' }; // avoid need for single quotes below |
| 671 | |
| 672 | struct tuple { |
| 673 | int num; |
| 674 | const char *name; |
| 675 | }; |
| 676 | |
| 677 | struct tuple errors[] = { |
| 678 | " |
| 679 | for i in $errors |
| 680 | do |
| 681 | echo -E ' {'$i', "'$i'" },' |
| 682 | done |
| 683 | |
| 684 | echo -E " |
| 685 | }; |
| 686 | |
| 687 | struct tuple signals[] = { |
| 688 | " |
| 689 | for i in $signals |
| 690 | do |
| 691 | echo -E ' {'$i', "'$i'" },' |
| 692 | done |
| 693 | |
| 694 | # Use -E because on some systems bash builtin interprets \n itself. |
| 695 | echo -E ' |
| 696 | }; |
| 697 | |
| 698 | static int |
| 699 | tuplecmp(const void *a, const void *b) |
| 700 | { |
| 701 | return ((struct tuple *)a)->num - ((struct tuple *)b)->num; |
| 702 | } |
| 703 | |
| 704 | int |
| 705 | main(void) |
| 706 | { |
| 707 | int i, e; |
| 708 | char buf[1024], *p; |
| 709 | |
| 710 | printf("\n\n// Error table\n"); |
| 711 | printf("var errorList = [...]struct {\n"); |
| 712 | printf("\tnum syscall.Errno\n"); |
| 713 | printf("\tname string\n"); |
| 714 | printf("\tdesc string\n"); |
| 715 | printf("} {\n"); |
| 716 | qsort(errors, nelem(errors), sizeof errors[0], tuplecmp); |
| 717 | for(i=0; i<nelem(errors); i++) { |
| 718 | e = errors[i].num; |
| 719 | if(i > 0 && errors[i-1].num == e) |
| 720 | continue; |
| 721 | strcpy(buf, strerror(e)); |
| 722 | // lowercase first letter: Bad -> bad, but STREAM -> STREAM. |
| 723 | if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) |
| 724 | buf[0] += a - A; |
| 725 | printf("\t{ %d, \"%s\", \"%s\" },\n", e, errors[i].name, buf); |
| 726 | } |
| 727 | printf("}\n\n"); |
| 728 | |
| 729 | printf("\n\n// Signal table\n"); |
| 730 | printf("var signalList = [...]struct {\n"); |
| 731 | printf("\tnum syscall.Signal\n"); |
| 732 | printf("\tname string\n"); |
| 733 | printf("\tdesc string\n"); |
| 734 | printf("} {\n"); |
| 735 | qsort(signals, nelem(signals), sizeof signals[0], tuplecmp); |
| 736 | for(i=0; i<nelem(signals); i++) { |
| 737 | e = signals[i].num; |
| 738 | if(i > 0 && signals[i-1].num == e) |
| 739 | continue; |
| 740 | strcpy(buf, strsignal(e)); |
| 741 | // lowercase first letter: Bad -> bad, but STREAM -> STREAM. |
| 742 | if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) |
| 743 | buf[0] += a - A; |
| 744 | // cut trailing : number. |
| 745 | p = strrchr(buf, ":"[0]); |
| 746 | if(p) |
| 747 | *p = '\0'; |
| 748 | printf("\t{ %d, \"%s\", \"%s\" },\n", e, signals[i].name, buf); |
| 749 | } |
| 750 | printf("}\n\n"); |
| 751 | |
| 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | ' |
| 756 | ) >_errors.c |
| 757 | |
| 758 | $CC $ccflags -o _errors _errors.c && $GORUN ./_errors && rm -f _errors.c _errors _const.go _error.grep _signal.grep _error.out |