comparison vendor/golang.org/x/sys/unix/mkerrors.sh @ 66:787b5ee0289d draft

Use vendored modules Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja>
author yakumo.izuru
date Sun, 23 Jul 2023 13:18:53 +0000
parents
children 4b79810863f6
comparison
equal deleted inserted replaced
65:6d985efa0f7a 66:787b5ee0289d
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/select.h>
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 1
58 #define _DARWIN_USE_64_BIT_INODE
59 #define __APPLE_USE_RFC_3542
60 #include <stdint.h>
61 #include <sys/attr.h>
62 #include <sys/clonefile.h>
63 #include <sys/kern_control.h>
64 #include <sys/types.h>
65 #include <sys/event.h>
66 #include <sys/ptrace.h>
67 #include <sys/select.h>
68 #include <sys/socket.h>
69 #include <sys/un.h>
70 #include <sys/sockio.h>
71 #include <sys/sys_domain.h>
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 <sys/vsock.h>
79 #include <net/bpf.h>
80 #include <net/if.h>
81 #include <net/if_types.h>
82 #include <net/route.h>
83 #include <netinet/in.h>
84 #include <netinet/ip.h>
85 #include <termios.h>
86
87 // for backwards compatibility because moved TIOCREMOTE to Kernel.framework after MacOSX12.0.sdk.
88 #define TIOCREMOTE 0x80047469
89 '
90
91 includes_DragonFly='
92 #include <sys/types.h>
93 #include <sys/event.h>
94 #include <sys/select.h>
95 #include <sys/socket.h>
96 #include <sys/sockio.h>
97 #include <sys/stat.h>
98 #include <sys/sysctl.h>
99 #include <sys/mman.h>
100 #include <sys/mount.h>
101 #include <sys/wait.h>
102 #include <sys/ioctl.h>
103 #include <net/bpf.h>
104 #include <net/if.h>
105 #include <net/if_clone.h>
106 #include <net/if_types.h>
107 #include <net/route.h>
108 #include <netinet/in.h>
109 #include <termios.h>
110 #include <netinet/ip.h>
111 #include <net/ip_mroute/ip_mroute.h>
112 '
113
114 includes_FreeBSD='
115 #include <sys/capsicum.h>
116 #include <sys/param.h>
117 #include <sys/types.h>
118 #include <sys/disk.h>
119 #include <sys/event.h>
120 #include <sys/sched.h>
121 #include <sys/select.h>
122 #include <sys/socket.h>
123 #include <sys/un.h>
124 #include <sys/sockio.h>
125 #include <sys/stat.h>
126 #include <sys/sysctl.h>
127 #include <sys/mman.h>
128 #include <sys/mount.h>
129 #include <sys/wait.h>
130 #include <sys/ioctl.h>
131 #include <sys/ptrace.h>
132 #include <net/bpf.h>
133 #include <net/if.h>
134 #include <net/if_types.h>
135 #include <net/route.h>
136 #include <netinet/in.h>
137 #include <termios.h>
138 #include <netinet/ip.h>
139 #include <netinet/ip_mroute.h>
140 #include <sys/extattr.h>
141
142 #if __FreeBSD__ >= 10
143 #define IFT_CARP 0xf8 // IFT_CARP is deprecated in FreeBSD 10
144 #undef SIOCAIFADDR
145 #define SIOCAIFADDR _IOW(105, 26, struct oifaliasreq) // ifaliasreq contains if_data
146 #undef SIOCSIFPHYADDR
147 #define SIOCSIFPHYADDR _IOW(105, 70, struct oifaliasreq) // ifaliasreq contains if_data
148 #endif
149 '
150
151 includes_Linux='
152 #define _LARGEFILE_SOURCE
153 #define _LARGEFILE64_SOURCE
154 #ifndef __LP64__
155 #define _FILE_OFFSET_BITS 64
156 #endif
157 #define _GNU_SOURCE
158
159 // <sys/ioctl.h> is broken on powerpc64, as it fails to include definitions of
160 // these structures. We just include them copied from <bits/termios.h>.
161 #if defined(__powerpc__)
162 struct sgttyb {
163 char sg_ispeed;
164 char sg_ospeed;
165 char sg_erase;
166 char sg_kill;
167 short sg_flags;
168 };
169
170 struct tchars {
171 char t_intrc;
172 char t_quitc;
173 char t_startc;
174 char t_stopc;
175 char t_eofc;
176 char t_brkc;
177 };
178
179 struct ltchars {
180 char t_suspc;
181 char t_dsuspc;
182 char t_rprntc;
183 char t_flushc;
184 char t_werasc;
185 char t_lnextc;
186 };
187 #endif
188
189 #include <bits/sockaddr.h>
190 #include <sys/epoll.h>
191 #include <sys/eventfd.h>
192 #include <sys/inotify.h>
193 #include <sys/ioctl.h>
194 #include <sys/mman.h>
195 #include <sys/mount.h>
196 #include <sys/prctl.h>
197 #include <sys/stat.h>
198 #include <sys/types.h>
199 #include <sys/time.h>
200 #include <sys/select.h>
201 #include <sys/signalfd.h>
202 #include <sys/socket.h>
203 #include <sys/timerfd.h>
204 #include <sys/uio.h>
205 #include <sys/xattr.h>
206 #include <linux/audit.h>
207 #include <linux/bpf.h>
208 #include <linux/can.h>
209 #include <linux/can/error.h>
210 #include <linux/can/netlink.h>
211 #include <linux/can/raw.h>
212 #include <linux/capability.h>
213 #include <linux/cryptouser.h>
214 #include <linux/devlink.h>
215 #include <linux/dm-ioctl.h>
216 #include <linux/errqueue.h>
217 #include <linux/ethtool_netlink.h>
218 #include <linux/falloc.h>
219 #include <linux/fanotify.h>
220 #include <linux/fib_rules.h>
221 #include <linux/filter.h>
222 #include <linux/fs.h>
223 #include <linux/fscrypt.h>
224 #include <linux/fsverity.h>
225 #include <linux/genetlink.h>
226 #include <linux/hdreg.h>
227 #include <linux/hidraw.h>
228 #include <linux/if.h>
229 #include <linux/if_addr.h>
230 #include <linux/if_alg.h>
231 #include <linux/if_arp.h>
232 #include <linux/if_ether.h>
233 #include <linux/if_ppp.h>
234 #include <linux/if_tun.h>
235 #include <linux/if_packet.h>
236 #include <linux/if_xdp.h>
237 #include <linux/input.h>
238 #include <linux/kcm.h>
239 #include <linux/kexec.h>
240 #include <linux/keyctl.h>
241 #include <linux/landlock.h>
242 #include <linux/loop.h>
243 #include <linux/lwtunnel.h>
244 #include <linux/magic.h>
245 #include <linux/memfd.h>
246 #include <linux/module.h>
247 #include <linux/mount.h>
248 #include <linux/netfilter/nfnetlink.h>
249 #include <linux/netlink.h>
250 #include <linux/net_namespace.h>
251 #include <linux/nfc.h>
252 #include <linux/nsfs.h>
253 #include <linux/perf_event.h>
254 #include <linux/pps.h>
255 #include <linux/ptrace.h>
256 #include <linux/random.h>
257 #include <linux/reboot.h>
258 #include <linux/rtc.h>
259 #include <linux/rtnetlink.h>
260 #include <linux/sched.h>
261 #include <linux/seccomp.h>
262 #include <linux/serial.h>
263 #include <linux/sockios.h>
264 #include <linux/taskstats.h>
265 #include <linux/tipc.h>
266 #include <linux/vm_sockets.h>
267 #include <linux/wait.h>
268 #include <linux/watchdog.h>
269 #include <linux/wireguard.h>
270
271 #include <mtd/ubi-user.h>
272 #include <mtd/mtd-user.h>
273 #include <net/route.h>
274
275 #if defined(__sparc__)
276 // On sparc{,64}, the kernel defines struct termios2 itself which clashes with the
277 // definition in glibc. As only the error constants are needed here, include the
278 // generic termibits.h (which is included by termbits.h on sparc).
279 #include <asm-generic/termbits.h>
280 #else
281 #include <asm/termbits.h>
282 #endif
283
284 #ifndef MSG_FASTOPEN
285 #define MSG_FASTOPEN 0x20000000
286 #endif
287
288 #ifndef PTRACE_GETREGS
289 #define PTRACE_GETREGS 0xc
290 #endif
291
292 #ifndef PTRACE_SETREGS
293 #define PTRACE_SETREGS 0xd
294 #endif
295
296 #ifndef SOL_NETLINK
297 #define SOL_NETLINK 270
298 #endif
299
300 #ifdef SOL_BLUETOOTH
301 // SPARC includes this in /usr/include/sparc64-linux-gnu/bits/socket.h
302 // but it is already in bluetooth_linux.go
303 #undef SOL_BLUETOOTH
304 #endif
305
306 // Certain constants are missing from the fs/crypto UAPI
307 #define FS_KEY_DESC_PREFIX "fscrypt:"
308 #define FS_KEY_DESC_PREFIX_SIZE 8
309 #define FS_MAX_KEY_SIZE 64
310
311 // The code generator produces -0x1 for (~0), but an unsigned value is necessary
312 // for the tipc_subscr timeout __u32 field.
313 #undef TIPC_WAIT_FOREVER
314 #define TIPC_WAIT_FOREVER 0xffffffff
315
316 // Copied from linux/l2tp.h
317 // Including linux/l2tp.h here causes conflicts between linux/in.h
318 // and netinet/in.h included via net/route.h above.
319 #define IPPROTO_L2TP 115
320
321 // Copied from linux/hid.h.
322 // Keep in sync with the size of the referenced fields.
323 #define _HIDIOCGRAWNAME_LEN 128 // sizeof_field(struct hid_device, name)
324 #define _HIDIOCGRAWPHYS_LEN 64 // sizeof_field(struct hid_device, phys)
325 #define _HIDIOCGRAWUNIQ_LEN 64 // sizeof_field(struct hid_device, uniq)
326
327 #define _HIDIOCGRAWNAME HIDIOCGRAWNAME(_HIDIOCGRAWNAME_LEN)
328 #define _HIDIOCGRAWPHYS HIDIOCGRAWPHYS(_HIDIOCGRAWPHYS_LEN)
329 #define _HIDIOCGRAWUNIQ HIDIOCGRAWUNIQ(_HIDIOCGRAWUNIQ_LEN)
330
331 '
332
333 includes_NetBSD='
334 #include <sys/types.h>
335 #include <sys/param.h>
336 #include <sys/event.h>
337 #include <sys/extattr.h>
338 #include <sys/mman.h>
339 #include <sys/mount.h>
340 #include <sys/sched.h>
341 #include <sys/select.h>
342 #include <sys/socket.h>
343 #include <sys/sockio.h>
344 #include <sys/sysctl.h>
345 #include <sys/termios.h>
346 #include <sys/ttycom.h>
347 #include <sys/wait.h>
348 #include <net/bpf.h>
349 #include <net/if.h>
350 #include <net/if_types.h>
351 #include <net/route.h>
352 #include <netinet/in.h>
353 #include <netinet/in_systm.h>
354 #include <netinet/ip.h>
355 #include <netinet/ip_mroute.h>
356 #include <netinet/if_ether.h>
357
358 // Needed since <sys/param.h> refers to it...
359 #define schedppq 1
360 '
361
362 includes_OpenBSD='
363 #include <sys/types.h>
364 #include <sys/param.h>
365 #include <sys/event.h>
366 #include <sys/mman.h>
367 #include <sys/mount.h>
368 #include <sys/select.h>
369 #include <sys/sched.h>
370 #include <sys/socket.h>
371 #include <sys/sockio.h>
372 #include <sys/stat.h>
373 #include <sys/sysctl.h>
374 #include <sys/termios.h>
375 #include <sys/ttycom.h>
376 #include <sys/unistd.h>
377 #include <sys/wait.h>
378 #include <net/bpf.h>
379 #include <net/if.h>
380 #include <net/if_types.h>
381 #include <net/if_var.h>
382 #include <net/route.h>
383 #include <netinet/in.h>
384 #include <netinet/in_systm.h>
385 #include <netinet/ip.h>
386 #include <netinet/ip_mroute.h>
387 #include <netinet/if_ether.h>
388 #include <net/if_bridge.h>
389
390 // We keep some constants not supported in OpenBSD 5.5 and beyond for
391 // the promise of compatibility.
392 #define EMUL_ENABLED 0x1
393 #define EMUL_NATIVE 0x2
394 #define IPV6_FAITH 0x1d
395 #define IPV6_OPTIONS 0x1
396 #define IPV6_RTHDR_STRICT 0x1
397 #define IPV6_SOCKOPT_RESERVED1 0x3
398 #define SIOCGIFGENERIC 0xc020693a
399 #define SIOCSIFGENERIC 0x80206939
400 #define WALTSIG 0x4
401 '
402
403 includes_SunOS='
404 #include <limits.h>
405 #include <sys/types.h>
406 #include <sys/select.h>
407 #include <sys/socket.h>
408 #include <sys/sockio.h>
409 #include <sys/stat.h>
410 #include <sys/stream.h>
411 #include <sys/mman.h>
412 #include <sys/wait.h>
413 #include <sys/ioctl.h>
414 #include <sys/mkdev.h>
415 #include <net/bpf.h>
416 #include <net/if.h>
417 #include <net/if_arp.h>
418 #include <net/if_types.h>
419 #include <net/route.h>
420 #include <netinet/icmp6.h>
421 #include <netinet/in.h>
422 #include <netinet/ip.h>
423 #include <netinet/ip_mroute.h>
424 #include <termios.h>
425 '
426
427
428 includes='
429 #include <sys/types.h>
430 #include <sys/file.h>
431 #include <fcntl.h>
432 #include <dirent.h>
433 #include <sys/socket.h>
434 #include <netinet/in.h>
435 #include <netinet/ip.h>
436 #include <netinet/ip6.h>
437 #include <netinet/tcp.h>
438 #include <errno.h>
439 #include <sys/signal.h>
440 #include <signal.h>
441 #include <sys/resource.h>
442 #include <time.h>
443 '
444 ccflags="$@"
445
446 # Write go tool cgo -godefs input.
447 (
448 echo package unix
449 echo
450 echo '/*'
451 indirect="includes_$(uname)"
452 echo "${!indirect} $includes"
453 echo '*/'
454 echo 'import "C"'
455 echo 'import "syscall"'
456 echo
457 echo 'const ('
458
459 # The gcc command line prints all the #defines
460 # it encounters while processing the input
461 echo "${!indirect} $includes" | $CC -x c - -E -dM $ccflags |
462 awk '
463 $1 != "#define" || $2 ~ /\(/ || $3 == "" {next}
464
465 $2 ~ /^E([ABCD]X|[BIS]P|[SD]I|S|FL)$/ {next} # 386 registers
466 $2 ~ /^(SIGEV_|SIGSTKSZ|SIGRT(MIN|MAX))/ {next}
467 $2 ~ /^(SCM_SRCRT)$/ {next}
468 $2 ~ /^(MAP_FAILED)$/ {next}
469 $2 ~ /^ELF_.*$/ {next}# <asm/elf.h> contains ELF_ARCH, etc.
470
471 $2 ~ /^EXTATTR_NAMESPACE_NAMES/ ||
472 $2 ~ /^EXTATTR_NAMESPACE_[A-Z]+_STRING/ {next}
473
474 $2 !~ /^ECCAPBITS/ &&
475 $2 !~ /^ETH_/ &&
476 $2 !~ /^EPROC_/ &&
477 $2 !~ /^EQUIV_/ &&
478 $2 !~ /^EXPR_/ &&
479 $2 !~ /^EVIOC/ &&
480 $2 ~ /^E[A-Z0-9_]+$/ ||
481 $2 ~ /^B[0-9_]+$/ ||
482 $2 ~ /^(OLD|NEW)DEV$/ ||
483 $2 == "BOTHER" ||
484 $2 ~ /^CI?BAUD(EX)?$/ ||
485 $2 == "IBSHIFT" ||
486 $2 ~ /^V[A-Z0-9]+$/ ||
487 $2 ~ /^CS[A-Z0-9]/ ||
488 $2 ~ /^I(SIG|CANON|CRNL|UCLC|EXTEN|MAXBEL|STRIP|UTF8)$/ ||
489 $2 ~ /^IGN/ ||
490 $2 ~ /^IX(ON|ANY|OFF)$/ ||
491 $2 ~ /^IN(LCR|PCK)$/ ||
492 $2 !~ "X86_CR3_PCID_NOFLUSH" &&
493 $2 ~ /(^FLU?SH)|(FLU?SH$)/ ||
494 $2 ~ /^C(LOCAL|READ|MSPAR|RTSCTS)$/ ||
495 $2 == "BRKINT" ||
496 $2 == "HUPCL" ||
497 $2 == "PENDIN" ||
498 $2 == "TOSTOP" ||
499 $2 == "XCASE" ||
500 $2 == "ALTWERASE" ||
501 $2 == "NOKERNINFO" ||
502 $2 == "NFDBITS" ||
503 $2 ~ /^PAR/ ||
504 $2 ~ /^SIG[^_]/ ||
505 $2 ~ /^O[CNPFPL][A-Z]+[^_][A-Z]+$/ ||
506 $2 ~ /^(NL|CR|TAB|BS|VT|FF)DLY$/ ||
507 $2 ~ /^(NL|CR|TAB|BS|VT|FF)[0-9]$/ ||
508 $2 ~ /^O?XTABS$/ ||
509 $2 ~ /^TC[IO](ON|OFF)$/ ||
510 $2 ~ /^IN_/ ||
511 $2 ~ /^KCM/ ||
512 $2 ~ /^LANDLOCK_/ ||
513 $2 ~ /^LOCK_(SH|EX|NB|UN)$/ ||
514 $2 ~ /^LO_(KEY|NAME)_SIZE$/ ||
515 $2 ~ /^LOOP_(CLR|CTL|GET|SET)_/ ||
516 $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|TCPOPT)_/ ||
517 $2 ~ /^NFC_(GENL|PROTO|COMM|RF|SE|DIRECTION|LLCP|SOCKPROTO)_/ ||
518 $2 ~ /^NFC_.*_(MAX)?SIZE$/ ||
519 $2 ~ /^RAW_PAYLOAD_/ ||
520 $2 ~ /^TP_STATUS_/ ||
521 $2 ~ /^FALLOC_/ ||
522 $2 ~ /^ICMPV?6?_(FILTER|SEC)/ ||
523 $2 == "SOMAXCONN" ||
524 $2 == "NAME_MAX" ||
525 $2 == "IFNAMSIZ" ||
526 $2 ~ /^CTL_(HW|KERN|MAXNAME|NET|QUERY)$/ ||
527 $2 ~ /^KERN_(HOSTNAME|OS(RELEASE|TYPE)|VERSION)$/ ||
528 $2 ~ /^HW_MACHINE$/ ||
529 $2 ~ /^SYSCTL_VERS/ ||
530 $2 !~ "MNT_BITS" &&
531 $2 ~ /^(MS|MNT|MOUNT|UMOUNT)_/ ||
532 $2 ~ /^NS_GET_/ ||
533 $2 ~ /^TUN(SET|GET|ATTACH|DETACH)/ ||
534 $2 ~ /^(O|F|[ES]?FD|NAME|S|PTRACE|PT|PIOD|TFD)_/ ||
535 $2 ~ /^KEXEC_/ ||
536 $2 ~ /^LINUX_REBOOT_CMD_/ ||
537 $2 ~ /^LINUX_REBOOT_MAGIC[12]$/ ||
538 $2 ~ /^MODULE_INIT_/ ||
539 $2 !~ "NLA_TYPE_MASK" &&
540 $2 !~ /^RTC_VL_(ACCURACY|BACKUP|DATA)/ &&
541 $2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTC|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P|NETNSA)_/ ||
542 $2 ~ /^FIORDCHK$/ ||
543 $2 ~ /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/ ||
616 $2 ~ /^OTP/ ||
617 $2 ~ /^MEM/ ||
618 $2 ~ /^WG/ ||
619 $2 ~ /^FIB_RULE_/ ||
620 $2 ~ /^BLK[A-Z]*(GET$|SET$|BUF$|PART$|SIZE)/ {printf("\t%s = C.%s\n", $2, $2)}
621 $2 ~ /^__WCOREFLAG$/ {next}
622 $2 ~ /^__W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", substr($2,3), $2)}
623
624 {next}
625 ' | sort
626
627 echo ')'
628 ) >_const.go
629
630 # Pull out the error names for later.
631 errors=$(
632 echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags |
633 awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print $2 }' |
634 sort
635 )
636
637 # Pull out the signal names for later.
638 signals=$(
639 echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags |
640 awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print $2 }' |
641 egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' |
642 sort
643 )
644
645 # Again, writing regexps to a file.
646 echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags |
647 awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print "^\t" $2 "[ \t]*=" }' |
648 sort >_error.grep
649 echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags |
650 awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print "^\t" $2 "[ \t]*=" }' |
651 egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' |
652 sort >_signal.grep
653
654 echo '// mkerrors.sh' "$@"
655 echo '// Code generated by the command above; see README.md. DO NOT EDIT.'
656 echo
657 echo "//go:build ${GOARCH} && ${GOOS}"
658 echo "// +build ${GOARCH},${GOOS}"
659 echo
660 go tool cgo -godefs -- "$@" _const.go >_error.out
661 cat _error.out | grep -vf _error.grep | grep -vf _signal.grep
662 echo
663 echo '// Errors'
664 echo 'const ('
665 cat _error.out | grep -f _error.grep | sed 's/=\(.*\)/= syscall.Errno(\1)/'
666 echo ')'
667
668 echo
669 echo '// Signals'
670 echo 'const ('
671 cat _error.out | grep -f _signal.grep | sed 's/=\(.*\)/= syscall.Signal(\1)/'
672 echo ')'
673
674 # Run C program to print error and syscall strings.
675 (
676 echo -E "
677 #include <stdio.h>
678 #include <stdlib.h>
679 #include <errno.h>
680 #include <ctype.h>
681 #include <string.h>
682 #include <signal.h>
683
684 #define nelem(x) (sizeof(x)/sizeof((x)[0]))
685
686 enum { A = 'A', Z = 'Z', a = 'a', z = 'z' }; // avoid need for single quotes below
687
688 struct tuple {
689 int num;
690 const char *name;
691 };
692
693 struct tuple errors[] = {
694 "
695 for i in $errors
696 do
697 echo -E ' {'$i', "'$i'" },'
698 done
699
700 echo -E "
701 };
702
703 struct tuple signals[] = {
704 "
705 for i in $signals
706 do
707 echo -E ' {'$i', "'$i'" },'
708 done
709
710 # Use -E because on some systems bash builtin interprets \n itself.
711 echo -E '
712 };
713
714 static int
715 tuplecmp(const void *a, const void *b)
716 {
717 return ((struct tuple *)a)->num - ((struct tuple *)b)->num;
718 }
719
720 int
721 main(void)
722 {
723 int i, e;
724 char buf[1024], *p;
725
726 printf("\n\n// Error table\n");
727 printf("var errorList = [...]struct {\n");
728 printf("\tnum syscall.Errno\n");
729 printf("\tname string\n");
730 printf("\tdesc string\n");
731 printf("} {\n");
732 qsort(errors, nelem(errors), sizeof errors[0], tuplecmp);
733 for(i=0; i<nelem(errors); i++) {
734 e = errors[i].num;
735 if(i > 0 && errors[i-1].num == e)
736 continue;
737 strcpy(buf, strerror(e));
738 // lowercase first letter: Bad -> bad, but STREAM -> STREAM.
739 if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z)
740 buf[0] += a - A;
741 printf("\t{ %d, \"%s\", \"%s\" },\n", e, errors[i].name, buf);
742 }
743 printf("}\n\n");
744
745 printf("\n\n// Signal table\n");
746 printf("var signalList = [...]struct {\n");
747 printf("\tnum syscall.Signal\n");
748 printf("\tname string\n");
749 printf("\tdesc string\n");
750 printf("} {\n");
751 qsort(signals, nelem(signals), sizeof signals[0], tuplecmp);
752 for(i=0; i<nelem(signals); i++) {
753 e = signals[i].num;
754 if(i > 0 && signals[i-1].num == e)
755 continue;
756 strcpy(buf, strsignal(e));
757 // lowercase first letter: Bad -> bad, but STREAM -> STREAM.
758 if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z)
759 buf[0] += a - A;
760 // cut trailing : number.
761 p = strrchr(buf, ":"[0]);
762 if(p)
763 *p = '\0';
764 printf("\t{ %d, \"%s\", \"%s\" },\n", e, signals[i].name, buf);
765 }
766 printf("}\n\n");
767
768 return 0;
769 }
770
771 '
772 ) >_errors.c
773
774 $CC $ccflags -o _errors _errors.c && $GORUN ./_errors && rm -f _errors.c _errors _const.go _error.grep _signal.grep _error.out