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