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