github.com/fletavendor/sys@v0.0.0-20181107165924-66b7b1311ac8/unix/mkerrors.sh (about) 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" ]] && [[ "$GOARCH" != "sparc64" ]]; then 21 if [[ "$GOLANG_SYS_BUILD" != "docker" ]]; then 22 echo 1>&2 "In the new build system, mkerrors should not be called directly." 23 echo 1>&2 "See README.md" 24 exit 1 25 fi 26 fi 27 28 if [[ "$GOOS" = "aix" ]]; then 29 CC=${CC:-gcc} 30 else 31 CC=${CC:-cc} 32 fi 33 34 if [[ "$GOOS" = "solaris" ]]; then 35 # Assumes GNU versions of utilities in PATH. 36 export PATH=/usr/gnu/bin:$PATH 37 fi 38 39 uname=$(uname) 40 41 includes_AIX=' 42 #include <net/if.h> 43 #include <net/netopt.h> 44 #include <netinet/ip_mroute.h> 45 #include <sys/protosw.h> 46 #include <sys/stropts.h> 47 #include <sys/mman.h> 48 #include <sys/poll.h> 49 #include <sys/termio.h> 50 #include <termios.h> 51 #include <fcntl.h> 52 53 #define AF_LOCAL AF_UNIX 54 ' 55 56 includes_Darwin=' 57 #define _DARWIN_C_SOURCE 58 #define KERNEL 59 #define _DARWIN_USE_64_BIT_INODE 60 #include <stdint.h> 61 #include <sys/attr.h> 62 #include <sys/types.h> 63 #include <sys/event.h> 64 #include <sys/ptrace.h> 65 #include <sys/socket.h> 66 #include <sys/sockio.h> 67 #include <sys/sysctl.h> 68 #include <sys/mman.h> 69 #include <sys/mount.h> 70 #include <sys/utsname.h> 71 #include <sys/wait.h> 72 #include <sys/xattr.h> 73 #include <net/bpf.h> 74 #include <net/if.h> 75 #include <net/if_types.h> 76 #include <net/route.h> 77 #include <netinet/in.h> 78 #include <netinet/ip.h> 79 #include <termios.h> 80 ' 81 82 includes_DragonFly=' 83 #include <sys/types.h> 84 #include <sys/event.h> 85 #include <sys/socket.h> 86 #include <sys/sockio.h> 87 #include <sys/stat.h> 88 #include <sys/sysctl.h> 89 #include <sys/mman.h> 90 #include <sys/mount.h> 91 #include <sys/wait.h> 92 #include <sys/ioctl.h> 93 #include <net/bpf.h> 94 #include <net/if.h> 95 #include <net/if_types.h> 96 #include <net/route.h> 97 #include <netinet/in.h> 98 #include <termios.h> 99 #include <netinet/ip.h> 100 #include <net/ip_mroute/ip_mroute.h> 101 ' 102 103 includes_FreeBSD=' 104 #include <sys/capsicum.h> 105 #include <sys/param.h> 106 #include <sys/types.h> 107 #include <sys/event.h> 108 #include <sys/socket.h> 109 #include <sys/sockio.h> 110 #include <sys/stat.h> 111 #include <sys/sysctl.h> 112 #include <sys/mman.h> 113 #include <sys/mount.h> 114 #include <sys/wait.h> 115 #include <sys/ioctl.h> 116 #include <net/bpf.h> 117 #include <net/if.h> 118 #include <net/if_types.h> 119 #include <net/route.h> 120 #include <netinet/in.h> 121 #include <termios.h> 122 #include <netinet/ip.h> 123 #include <netinet/ip_mroute.h> 124 #include <sys/extattr.h> 125 126 #if __FreeBSD__ >= 10 127 #define IFT_CARP 0xf8 // IFT_CARP is deprecated in FreeBSD 10 128 #undef SIOCAIFADDR 129 #define SIOCAIFADDR _IOW(105, 26, struct oifaliasreq) // ifaliasreq contains if_data 130 #undef SIOCSIFPHYADDR 131 #define SIOCSIFPHYADDR _IOW(105, 70, struct oifaliasreq) // ifaliasreq contains if_data 132 #endif 133 ' 134 135 includes_Linux=' 136 #define _LARGEFILE_SOURCE 137 #define _LARGEFILE64_SOURCE 138 #ifndef __LP64__ 139 #define _FILE_OFFSET_BITS 64 140 #endif 141 #define _GNU_SOURCE 142 143 // <sys/ioctl.h> is broken on powerpc64, as it fails to include definitions of 144 // these structures. We just include them copied from <bits/termios.h>. 145 #if defined(__powerpc__) 146 struct sgttyb { 147 char sg_ispeed; 148 char sg_ospeed; 149 char sg_erase; 150 char sg_kill; 151 short sg_flags; 152 }; 153 154 struct tchars { 155 char t_intrc; 156 char t_quitc; 157 char t_startc; 158 char t_stopc; 159 char t_eofc; 160 char t_brkc; 161 }; 162 163 struct ltchars { 164 char t_suspc; 165 char t_dsuspc; 166 char t_rprntc; 167 char t_flushc; 168 char t_werasc; 169 char t_lnextc; 170 }; 171 #endif 172 173 #include <bits/sockaddr.h> 174 #include <sys/epoll.h> 175 #include <sys/eventfd.h> 176 #include <sys/inotify.h> 177 #include <sys/ioctl.h> 178 #include <sys/mman.h> 179 #include <sys/mount.h> 180 #include <sys/prctl.h> 181 #include <sys/stat.h> 182 #include <sys/types.h> 183 #include <sys/time.h> 184 #include <sys/socket.h> 185 #include <sys/xattr.h> 186 #include <linux/if.h> 187 #include <linux/if_alg.h> 188 #include <linux/if_arp.h> 189 #include <linux/if_ether.h> 190 #include <linux/if_tun.h> 191 #include <linux/if_packet.h> 192 #include <linux/if_addr.h> 193 #include <linux/falloc.h> 194 #include <linux/filter.h> 195 #include <linux/fs.h> 196 #include <linux/kexec.h> 197 #include <linux/keyctl.h> 198 #include <linux/magic.h> 199 #include <linux/memfd.h> 200 #include <linux/module.h> 201 #include <linux/netfilter/nfnetlink.h> 202 #include <linux/netlink.h> 203 #include <linux/net_namespace.h> 204 #include <linux/perf_event.h> 205 #include <linux/random.h> 206 #include <linux/reboot.h> 207 #include <linux/rtnetlink.h> 208 #include <linux/ptrace.h> 209 #include <linux/sched.h> 210 #include <linux/seccomp.h> 211 #include <linux/sockios.h> 212 #include <linux/wait.h> 213 #include <linux/icmpv6.h> 214 #include <linux/serial.h> 215 #include <linux/can.h> 216 #include <linux/vm_sockets.h> 217 #include <linux/taskstats.h> 218 #include <linux/genetlink.h> 219 #include <linux/watchdog.h> 220 #include <linux/hdreg.h> 221 #include <linux/rtc.h> 222 #include <linux/if_xdp.h> 223 #include <mtd/ubi-user.h> 224 #include <net/route.h> 225 #include <asm/termbits.h> 226 227 #ifndef MSG_FASTOPEN 228 #define MSG_FASTOPEN 0x20000000 229 #endif 230 231 #ifndef PTRACE_GETREGS 232 #define PTRACE_GETREGS 0xc 233 #endif 234 235 #ifndef PTRACE_SETREGS 236 #define PTRACE_SETREGS 0xd 237 #endif 238 239 #ifndef SOL_NETLINK 240 #define SOL_NETLINK 270 241 #endif 242 243 #ifdef SOL_BLUETOOTH 244 // SPARC includes this in /usr/include/sparc64-linux-gnu/bits/socket.h 245 // but it is already in bluetooth_linux.go 246 #undef SOL_BLUETOOTH 247 #endif 248 249 // Certain constants are missing from the fs/crypto UAPI 250 #define FS_KEY_DESC_PREFIX "fscrypt:" 251 #define FS_KEY_DESC_PREFIX_SIZE 8 252 #define FS_MAX_KEY_SIZE 64 253 254 // XDP socket constants do not appear to be picked up otherwise. 255 // Copied from samples/bpf/xdpsock_user.c. 256 #ifndef SOL_XDP 257 #define SOL_XDP 283 258 #endif 259 260 #ifndef AF_XDP 261 #define AF_XDP 44 262 #endif 263 ' 264 265 includes_NetBSD=' 266 #include <sys/types.h> 267 #include <sys/param.h> 268 #include <sys/event.h> 269 #include <sys/extattr.h> 270 #include <sys/mman.h> 271 #include <sys/mount.h> 272 #include <sys/socket.h> 273 #include <sys/sockio.h> 274 #include <sys/sysctl.h> 275 #include <sys/termios.h> 276 #include <sys/ttycom.h> 277 #include <sys/wait.h> 278 #include <net/bpf.h> 279 #include <net/if.h> 280 #include <net/if_types.h> 281 #include <net/route.h> 282 #include <netinet/in.h> 283 #include <netinet/in_systm.h> 284 #include <netinet/ip.h> 285 #include <netinet/ip_mroute.h> 286 #include <netinet/if_ether.h> 287 288 // Needed since <sys/param.h> refers to it... 289 #define schedppq 1 290 ' 291 292 includes_OpenBSD=' 293 #include <sys/types.h> 294 #include <sys/param.h> 295 #include <sys/event.h> 296 #include <sys/mman.h> 297 #include <sys/mount.h> 298 #include <sys/socket.h> 299 #include <sys/sockio.h> 300 #include <sys/stat.h> 301 #include <sys/sysctl.h> 302 #include <sys/termios.h> 303 #include <sys/ttycom.h> 304 #include <sys/unistd.h> 305 #include <sys/wait.h> 306 #include <net/bpf.h> 307 #include <net/if.h> 308 #include <net/if_types.h> 309 #include <net/if_var.h> 310 #include <net/route.h> 311 #include <netinet/in.h> 312 #include <netinet/in_systm.h> 313 #include <netinet/ip.h> 314 #include <netinet/ip_mroute.h> 315 #include <netinet/if_ether.h> 316 #include <net/if_bridge.h> 317 318 // We keep some constants not supported in OpenBSD 5.5 and beyond for 319 // the promise of compatibility. 320 #define EMUL_ENABLED 0x1 321 #define EMUL_NATIVE 0x2 322 #define IPV6_FAITH 0x1d 323 #define IPV6_OPTIONS 0x1 324 #define IPV6_RTHDR_STRICT 0x1 325 #define IPV6_SOCKOPT_RESERVED1 0x3 326 #define SIOCGIFGENERIC 0xc020693a 327 #define SIOCSIFGENERIC 0x80206939 328 #define WALTSIG 0x4 329 ' 330 331 includes_SunOS=' 332 #include <limits.h> 333 #include <sys/types.h> 334 #include <sys/socket.h> 335 #include <sys/sockio.h> 336 #include <sys/stat.h> 337 #include <sys/mman.h> 338 #include <sys/wait.h> 339 #include <sys/ioctl.h> 340 #include <sys/mkdev.h> 341 #include <net/bpf.h> 342 #include <net/if.h> 343 #include <net/if_arp.h> 344 #include <net/if_types.h> 345 #include <net/route.h> 346 #include <netinet/in.h> 347 #include <termios.h> 348 #include <netinet/ip.h> 349 #include <netinet/ip_mroute.h> 350 ' 351 352 353 includes=' 354 #include <sys/types.h> 355 #include <sys/file.h> 356 #include <fcntl.h> 357 #include <dirent.h> 358 #include <sys/socket.h> 359 #include <netinet/in.h> 360 #include <netinet/ip.h> 361 #include <netinet/ip6.h> 362 #include <netinet/tcp.h> 363 #include <errno.h> 364 #include <sys/signal.h> 365 #include <signal.h> 366 #include <sys/resource.h> 367 #include <time.h> 368 ' 369 ccflags="$@" 370 371 # Write go tool cgo -godefs input. 372 ( 373 echo package unix 374 echo 375 echo '/*' 376 indirect="includes_$(uname)" 377 echo "${!indirect} $includes" 378 echo '*/' 379 echo 'import "C"' 380 echo 'import "syscall"' 381 echo 382 echo 'const (' 383 384 # The gcc command line prints all the #defines 385 # it encounters while processing the input 386 echo "${!indirect} $includes" | $CC -x c - -E -dM $ccflags | 387 awk ' 388 $1 != "#define" || $2 ~ /\(/ || $3 == "" {next} 389 390 $2 ~ /^E([ABCD]X|[BIS]P|[SD]I|S|FL)$/ {next} # 386 registers 391 $2 ~ /^(SIGEV_|SIGSTKSZ|SIGRT(MIN|MAX))/ {next} 392 $2 ~ /^(SCM_SRCRT)$/ {next} 393 $2 ~ /^(MAP_FAILED)$/ {next} 394 $2 ~ /^ELF_.*$/ {next}# <asm/elf.h> contains ELF_ARCH, etc. 395 396 $2 ~ /^EXTATTR_NAMESPACE_NAMES/ || 397 $2 ~ /^EXTATTR_NAMESPACE_[A-Z]+_STRING/ {next} 398 399 $2 !~ /^ECCAPBITS/ && 400 $2 !~ /^ETH_/ && 401 $2 !~ /^EPROC_/ && 402 $2 !~ /^EQUIV_/ && 403 $2 !~ /^EXPR_/ && 404 $2 ~ /^E[A-Z0-9_]+$/ || 405 $2 ~ /^B[0-9_]+$/ || 406 $2 ~ /^(OLD|NEW)DEV$/ || 407 $2 == "BOTHER" || 408 $2 ~ /^CI?BAUD(EX)?$/ || 409 $2 == "IBSHIFT" || 410 $2 ~ /^V[A-Z0-9]+$/ || 411 $2 ~ /^CS[A-Z0-9]/ || 412 $2 ~ /^I(SIG|CANON|CRNL|UCLC|EXTEN|MAXBEL|STRIP|UTF8)$/ || 413 $2 ~ /^IGN/ || 414 $2 ~ /^IX(ON|ANY|OFF)$/ || 415 $2 ~ /^IN(LCR|PCK)$/ || 416 $2 !~ "X86_CR3_PCID_NOFLUSH" && 417 $2 ~ /(^FLU?SH)|(FLU?SH$)/ || 418 $2 ~ /^C(LOCAL|READ|MSPAR|RTSCTS)$/ || 419 $2 == "BRKINT" || 420 $2 == "HUPCL" || 421 $2 == "PENDIN" || 422 $2 == "TOSTOP" || 423 $2 == "XCASE" || 424 $2 == "ALTWERASE" || 425 $2 == "NOKERNINFO" || 426 $2 ~ /^PAR/ || 427 $2 ~ /^SIG[^_]/ || 428 $2 ~ /^O[CNPFPL][A-Z]+[^_][A-Z]+$/ || 429 $2 ~ /^(NL|CR|TAB|BS|VT|FF)DLY$/ || 430 $2 ~ /^(NL|CR|TAB|BS|VT|FF)[0-9]$/ || 431 $2 ~ /^O?XTABS$/ || 432 $2 ~ /^TC[IO](ON|OFF)$/ || 433 $2 ~ /^IN_/ || 434 $2 ~ /^LOCK_(SH|EX|NB|UN)$/ || 435 $2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|ICMP6|TCP|EVFILT|NOTE|EV|SHUT|PROT|MAP|MFD|T?PACKET|MSG|SCM|MCL|DT|MADV|PR)_/ || 436 $2 ~ /^TP_STATUS_/ || 437 $2 ~ /^FALLOC_/ || 438 $2 == "ICMPV6_FILTER" || 439 $2 == "SOMAXCONN" || 440 $2 == "NAME_MAX" || 441 $2 == "IFNAMSIZ" || 442 $2 ~ /^CTL_(HW|KERN|MAXNAME|NET|QUERY)$/ || 443 $2 ~ /^KERN_(HOSTNAME|OS(RELEASE|TYPE)|VERSION)$/ || 444 $2 ~ /^HW_MACHINE$/ || 445 $2 ~ /^SYSCTL_VERS/ || 446 $2 !~ "MNT_BITS" && 447 $2 ~ /^(MS|MNT|UMOUNT)_/ || 448 $2 ~ /^TUN(SET|GET|ATTACH|DETACH)/ || 449 $2 ~ /^(O|F|E?FD|NAME|S|PTRACE|PT)_/ || 450 $2 ~ /^KEXEC_/ || 451 $2 ~ /^LINUX_REBOOT_CMD_/ || 452 $2 ~ /^LINUX_REBOOT_MAGIC[12]$/ || 453 $2 ~ /^MODULE_INIT_/ || 454 $2 !~ "NLA_TYPE_MASK" && 455 $2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTC|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P|NETNSA)_/ || 456 $2 ~ /^SIOC/ || 457 $2 ~ /^TIOC/ || 458 $2 ~ /^TCGET/ || 459 $2 ~ /^TCSET/ || 460 $2 ~ /^TC(FLSH|SBRKP?|XONC)$/ || 461 $2 !~ "RTF_BITS" && 462 $2 ~ /^(IFF|IFT|NET_RT|RTM|RTF|RTV|RTA|RTAX)_/ || 463 $2 ~ /^BIOC/ || 464 $2 ~ /^RUSAGE_(SELF|CHILDREN|THREAD)/ || 465 $2 ~ /^RLIMIT_(AS|CORE|CPU|DATA|FSIZE|LOCKS|MEMLOCK|MSGQUEUE|NICE|NOFILE|NPROC|RSS|RTPRIO|RTTIME|SIGPENDING|STACK)|RLIM_INFINITY/ || 466 $2 ~ /^PRIO_(PROCESS|PGRP|USER)/ || 467 $2 ~ /^CLONE_[A-Z_]+/ || 468 $2 !~ /^(BPF_TIMEVAL)$/ && 469 $2 ~ /^(BPF|DLT)_/ || 470 $2 ~ /^CLOCK_/ || 471 $2 ~ /^CAN_/ || 472 $2 ~ /^CAP_/ || 473 $2 ~ /^ALG_/ || 474 $2 ~ /^FS_(POLICY_FLAGS|KEY_DESC|ENCRYPTION_MODE|[A-Z0-9_]+_KEY_SIZE|IOC_(GET|SET)_ENCRYPTION)/ || 475 $2 ~ /^GRND_/ || 476 $2 ~ /^KEY_(SPEC|REQKEY_DEFL)_/ || 477 $2 ~ /^KEYCTL_/ || 478 $2 ~ /^PERF_EVENT_IOC_/ || 479 $2 ~ /^SECCOMP_MODE_/ || 480 $2 ~ /^SPLICE_/ || 481 $2 ~ /^SYNC_FILE_RANGE_/ || 482 $2 !~ /^AUDIT_RECORD_MAGIC/ && 483 $2 !~ /IOC_MAGIC/ && 484 $2 ~ /^[A-Z][A-Z0-9_]+_MAGIC2?$/ || 485 $2 ~ /^(VM|VMADDR)_/ || 486 $2 ~ /^IOCTL_VM_SOCKETS_/ || 487 $2 ~ /^(TASKSTATS|TS)_/ || 488 $2 ~ /^CGROUPSTATS_/ || 489 $2 ~ /^GENL_/ || 490 $2 ~ /^STATX_/ || 491 $2 ~ /^RENAME/ || 492 $2 ~ /^UBI_IOC[A-Z]/ || 493 $2 ~ /^UTIME_/ || 494 $2 ~ /^XATTR_(CREATE|REPLACE|NO(DEFAULT|FOLLOW|SECURITY)|SHOWCOMPRESSION)/ || 495 $2 ~ /^ATTR_(BIT_MAP_COUNT|(CMN|VOL|FILE)_)/ || 496 $2 ~ /^FSOPT_/ || 497 $2 ~ /^WDIOC_/ || 498 $2 ~ /^NFN/ || 499 $2 ~ /^XDP_/ || 500 $2 ~ /^(HDIO|WIN|SMART)_/ || 501 $2 !~ "WMESGLEN" && 502 $2 ~ /^W[A-Z0-9]+$/ || 503 $2 ~ /^BLK[A-Z]*(GET$|SET$|BUF$|PART$|SIZE)/ {printf("\t%s = C.%s\n", $2, $2)} 504 $2 ~ /^__WCOREFLAG$/ {next} 505 $2 ~ /^__W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", substr($2,3), $2)} 506 507 {next} 508 ' | sort 509 510 echo ')' 511 ) >_const.go 512 513 # Pull out the error names for later. 514 errors=$( 515 echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags | 516 awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print $2 }' | 517 sort 518 ) 519 520 # Pull out the signal names for later. 521 signals=$( 522 echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags | 523 awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print $2 }' | 524 egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' | 525 sort 526 ) 527 528 # Again, writing regexps to a file. 529 echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags | 530 awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print "^\t" $2 "[ \t]*=" }' | 531 sort >_error.grep 532 echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags | 533 awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print "^\t" $2 "[ \t]*=" }' | 534 egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' | 535 sort >_signal.grep 536 537 echo '// mkerrors.sh' "$@" 538 echo '// Code generated by the command above; see README.md. DO NOT EDIT.' 539 echo 540 echo "// +build ${GOARCH},${GOOS}" 541 echo 542 go tool cgo -godefs -- "$@" _const.go >_error.out 543 cat _error.out | grep -vf _error.grep | grep -vf _signal.grep 544 echo 545 echo '// Errors' 546 echo 'const (' 547 cat _error.out | grep -f _error.grep | sed 's/=\(.*\)/= syscall.Errno(\1)/' 548 echo ')' 549 550 echo 551 echo '// Signals' 552 echo 'const (' 553 cat _error.out | grep -f _signal.grep | sed 's/=\(.*\)/= syscall.Signal(\1)/' 554 echo ')' 555 556 # Run C program to print error and syscall strings. 557 ( 558 echo -E " 559 #include <stdio.h> 560 #include <stdlib.h> 561 #include <errno.h> 562 #include <ctype.h> 563 #include <string.h> 564 #include <signal.h> 565 566 #define nelem(x) (sizeof(x)/sizeof((x)[0])) 567 568 enum { A = 'A', Z = 'Z', a = 'a', z = 'z' }; // avoid need for single quotes below 569 570 struct tuple { 571 int num; 572 const char *name; 573 }; 574 575 struct tuple errors[] = { 576 " 577 for i in $errors 578 do 579 echo -E ' {'$i', "'$i'" },' 580 done 581 582 echo -E " 583 }; 584 585 struct tuple signals[] = { 586 " 587 for i in $signals 588 do 589 echo -E ' {'$i', "'$i'" },' 590 done 591 592 # Use -E because on some systems bash builtin interprets \n itself. 593 echo -E ' 594 }; 595 596 static int 597 tuplecmp(const void *a, const void *b) 598 { 599 return ((struct tuple *)a)->num - ((struct tuple *)b)->num; 600 } 601 602 int 603 main(void) 604 { 605 int i, e; 606 char buf[1024], *p; 607 608 printf("\n\n// Error table\n"); 609 printf("var errorList = [...]struct {\n"); 610 printf("\tnum syscall.Errno\n"); 611 printf("\tname string\n"); 612 printf("\tdesc string\n"); 613 printf("} {\n"); 614 qsort(errors, nelem(errors), sizeof errors[0], tuplecmp); 615 for(i=0; i<nelem(errors); i++) { 616 e = errors[i].num; 617 if(i > 0 && errors[i-1].num == e) 618 continue; 619 strcpy(buf, strerror(e)); 620 // lowercase first letter: Bad -> bad, but STREAM -> STREAM. 621 if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) 622 buf[0] += a - A; 623 printf("\t{ %d, \"%s\", \"%s\" },\n", e, errors[i].name, buf); 624 } 625 printf("}\n\n"); 626 627 printf("\n\n// Signal table\n"); 628 printf("var signalList = [...]struct {\n"); 629 printf("\tnum syscall.Signal\n"); 630 printf("\tname string\n"); 631 printf("\tdesc string\n"); 632 printf("} {\n"); 633 qsort(signals, nelem(signals), sizeof signals[0], tuplecmp); 634 for(i=0; i<nelem(signals); i++) { 635 e = signals[i].num; 636 if(i > 0 && signals[i-1].num == e) 637 continue; 638 strcpy(buf, strsignal(e)); 639 // lowercase first letter: Bad -> bad, but STREAM -> STREAM. 640 if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) 641 buf[0] += a - A; 642 // cut trailing : number. 643 p = strrchr(buf, ":"[0]); 644 if(p) 645 *p = '\0'; 646 printf("\t{ %d, \"%s\", \"%s\" },\n", e, signals[i].name, buf); 647 } 648 printf("}\n\n"); 649 650 return 0; 651 } 652 653 ' 654 ) >_errors.c 655 656 $CC $ccflags -o _errors _errors.c && $GORUN ./_errors && rm -f _errors.c _errors _const.go _error.grep _signal.grep _error.out