File: errno.ls

package info (click to toggle)
lua-cqueues 20200726-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,848 kB
  • sloc: ansic: 23,623; sh: 2,984; makefile: 24
file content (85 lines) | stat: -rwxr-xr-x 1,741 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
#
# List all EXXXX macros
#

set -e

: ${CC:=cc}
: ${xflag:=}
: ${ELAST=no}


usage() {
	cat <<-EOF
	usage: $(basename $0) -lxh
	  -l  print or compute ELAST value
	  -x  expand macros
	  -h  print this usage message

	Report bugs to <william@25thandClement.com>
	EOF
}

while getopts lxh OPT; do
	case "${OPT}" in
	l)
		if [ -n "${xflag}" ]; then
			echo "$0: -l and -x are exclusive" >&2
			usage >&2
			exit 1
		fi

		ELAST=yes
		;;
	x)
		if [ "${ELAST}" != "no" ]; then
			echo "$0: -l and -x are exclusive" >&2
			usage >&2
			exit 1
		fi

		xflag="-x"
		;;
	h)
		usage
		exit 0
		;;
	*)
		usage >&2
		exit 1
		;;
	esac
done


posix() {
	cat <<-EOF | tr " " "\n"
		E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT EAGAIN
		EWOULDBLOCK EALREADY EBADF EBADMSG EBUSY ECANCELED ECHILD
		ECONNABORTED ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ
		EDOM EDQUOT EEXIST EFAULT EFBIG EHOSTUNREACH EIDRM EILSEQ
		EINPROGRESS EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE
		EMLINK EMSGSIZE EMULTIHOP ENAMETOOLONG ENETDOWN ENETRESET
		ENETUNREACH ENFILE ENOBUFS ENODATA ENODEV ENOENT ENOEXEC
		ENOLCK ENOLINK ENOMEM ENOMSG ENOPROTOOPT ENOSPC ENOSR ENOSTR
		ENOSYS ENOTCONN ENOTDIR ENOTEMPTY ENOTRECOVERABLE ENOTSOCK
		ENOTSUP EOPNOTSUPP ENOTTY ENXIO EOPNOTSUPP ENOTSUP EOVERFLOW
		EOWNERDEAD EPERM EPIPE EPROTO EPROTONOSUPPORT EPROTOTYPE
		ERANGE EROFS ESPIPE ESRCH ESTALE ETIME ETIMEDOUT ETXTBSY
		EWOULDBLOCK EAGAIN EXDEV
	EOF
}

errno_h() {
	posix | env PATH="$(dirname $0):${PATH}" CC="${CC}" macros.ls -i "errno.h" -m "^E" -s - ${xflag}
}


if [ "${ELAST}" = "yes" ]; then
	xflag=""
	(echo "#include <errno.h>"; errno_h) | ${CC} -E - | \
	sed -ne 's/^[ 	]*\([0123456789][0123456789]*\).*$/\1/p' | sort -n | tail -1
else
	errno_h
fi