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