Landin library reference source

platform/posix/errno.ldn

1--  POSIX's error numbers as atoms, one for every errno Linux, Darwin and
2--  FreeBSD define, named after the C macro in lower case, with each
3--  system's number kept.  The names and numbers were read from Linux 7.1's
4--  include/uapi/asm-generic/errno-base.h and errno.h, which x86-64, arm64
5--  and RV64 share, from FreeBSD 15's sys/errno.h, the same on both of its
6--  architectures, and from the macOS SDK's sys/errno.h; the C peer of
7--  abi/posix-errno-numbers holds every entry to each system's own header.
8--  An alias names no atom of its own: EWOULDBLOCK is EAGAIN's number on
9--  all three and is `eagain`, Linux's EDEADLOCK is `edeadlk`, and
10--  ENOTSUP, a number of its own only on Darwin, is EOPNOTSUPP's on Linux
11--  and FreeBSD, where a failure gives `eopnotsupp`.
12
13--- A failure no errno this module names describes: a number newer than
14--- its tables, or a record the system filled that could not be read.  Its
15--- `number` is zero.
16public unlisted: atom
17
18--- errno EPERM: Operation not permitted.
19public eperm: atom
20--- errno ENOENT: No such file or directory.
21public enoent: atom
22--- errno ESRCH: No such process.
23public esrch: atom
24--- errno EINTR: Interrupted system call.
25public eintr: atom
26--- errno EIO: I/O error.
27public eio: atom
28--- errno ENXIO: No such device or address.
29public enxio: atom
30--- errno E2BIG: Argument list too long.
31public e2big: atom
32--- errno ENOEXEC: Exec format error.
33public enoexec: atom
34--- errno EBADF: Bad file number.
35public ebadf: atom
36--- errno ECHILD: No child processes.
37public echild: atom
38--- errno EAGAIN: Try again.
39public eagain: atom
40--- errno ENOMEM: Out of memory.
41public enomem: atom
42--- errno EACCES: Permission denied.
43public eacces: atom
44--- errno EFAULT: Bad address.
45public efault: atom
46--- errno ENOTBLK: Block device required.
47public enotblk: atom
48--- errno EBUSY: Device or resource busy.
49public ebusy: atom
50--- errno EEXIST: File exists.
51public eexist: atom
52--- errno EXDEV: Cross-device link.
53public exdev: atom
54--- errno ENODEV: No such device.
55public enodev: atom
56--- errno ENOTDIR: Not a directory.
57public enotdir: atom
58--- errno EISDIR: Is a directory.
59public eisdir: atom
60--- errno EINVAL: Invalid argument.
61public einval: atom
62--- errno ENFILE: File table overflow.
63public enfile: atom
64--- errno EMFILE: Too many open files.
65public emfile: atom
66--- errno ENOTTY: Not a typewriter.
67public enotty: atom
68--- errno ETXTBSY: Text file busy.
69public etxtbsy: atom
70--- errno EFBIG: File too large.
71public efbig: atom
72--- errno ENOSPC: No space left on device.
73public enospc: atom
74--- errno ESPIPE: Illegal seek.
75public espipe: atom
76--- errno EROFS: Read-only file system.
77public erofs: atom
78--- errno EMLINK: Too many links.
79public emlink: atom
80--- errno EPIPE: Broken pipe.
81public epipe: atom
82--- errno EDOM: Math argument out of domain of func.
83public edom: atom
84--- errno ERANGE: Math result not representable.
85public erange: atom
86--- errno EDEADLK: Resource deadlock would occur.
87public edeadlk: atom
88--- errno ENAMETOOLONG: File name too long.
89public enametoolong: atom
90--- errno ENOLCK: No record locks available.
91public enolck: atom
92--- errno ENOSYS: Invalid system call number.
93public enosys: atom
94--- errno ENOTEMPTY: Directory not empty.
95public enotempty: atom
96--- errno ELOOP: Too many symbolic links encountered.
97public eloop: atom
98--- errno ENOMSG: No message of desired type.
99public enomsg: atom
100--- errno EIDRM: Identifier removed.
101public eidrm: atom
102--- errno ECHRNG: Channel number out of range.
103public echrng: atom
104--- errno EL2NSYNC: Level 2 not synchronized.
105public el2nsync: atom
106--- errno EL3HLT: Level 3 halted.
107public el3hlt: atom
108--- errno EL3RST: Level 3 reset.
109public el3rst: atom
110--- errno ELNRNG: Link number out of range.
111public elnrng: atom
112--- errno EUNATCH: Protocol driver not attached.
113public eunatch: atom
114--- errno ENOCSI: No CSI structure available.
115public enocsi: atom
116--- errno EL2HLT: Level 2 halted.
117public el2hlt: atom
118--- errno EBADE: Invalid exchange.
119public ebade: atom
120--- errno EBADR: Invalid request descriptor.
121public ebadr: atom
122--- errno EXFULL: Exchange full.
123public exfull: atom
124--- errno ENOANO: No anode.
125public enoano: atom
126--- errno EBADRQC: Invalid request code.
127public ebadrqc: atom
128--- errno EBADSLT: Invalid slot.
129public ebadslt: atom
130--- errno EBFONT: Bad font file format.
131public ebfont: atom
132--- errno ENOSTR: Device not a stream.
133public enostr: atom
134--- errno ENODATA: No data available.
135public enodata: atom
136--- errno ETIME: Timer expired.
137public etime: atom
138--- errno ENOSR: Out of streams resources.
139public enosr: atom
140--- errno ENONET: Machine is not on the network.
141public enonet: atom
142--- errno ENOPKG: Package not installed.
143public enopkg: atom
144--- errno EREMOTE: Object is remote.
145public eremote: atom
146--- errno ENOLINK: Link has been severed.
147public enolink: atom
148--- errno EADV: Advertise error.
149public eadv: atom
150--- errno ESRMNT: Srmount error.
151public esrmnt: atom
152--- errno ECOMM: Communication error on send.
153public ecomm: atom
154--- errno EPROTO: Protocol error.
155public eproto: atom
156--- errno EMULTIHOP: Multihop attempted.
157public emultihop: atom
158--- errno EDOTDOT: RFS specific error.
159public edotdot: atom
160--- errno EBADMSG: Not a data message.
161public ebadmsg: atom
162--- errno EOVERFLOW: Value too large for defined data type.
163public eoverflow: atom
164--- errno ENOTUNIQ: Name not unique on network.
165public enotuniq: atom
166--- errno EBADFD: File descriptor in bad state.
167public ebadfd: atom
168--- errno EREMCHG: Remote address changed.
169public eremchg: atom
170--- errno ELIBACC: Can not access a needed shared library.
171public elibacc: atom
172--- errno ELIBBAD: Accessing a corrupted shared library.
173public elibbad: atom
174--- errno ELIBSCN: .lib section in a.out corrupted.
175public elibscn: atom
176--- errno ELIBMAX: Attempting to link in too many shared libraries.
177public elibmax: atom
178--- errno ELIBEXEC: Cannot exec a shared library directly.
179public elibexec: atom
180--- errno EILSEQ: Illegal byte sequence.
181public eilseq: atom
182--- errno ERESTART: Interrupted system call should be restarted.
183public erestart: atom
184--- errno ESTRPIPE: Streams pipe error.
185public estrpipe: atom
186--- errno EUSERS: Too many users.
187public eusers: atom
188--- errno ENOTSOCK: Socket operation on non-socket.
189public enotsock: atom
190--- errno EDESTADDRREQ: Destination address required.
191public edestaddrreq: atom
192--- errno EMSGSIZE: Message too long.
193public emsgsize: atom
194--- errno EPROTOTYPE: Protocol wrong type for socket.
195public eprototype: atom
196--- errno ENOPROTOOPT: Protocol not available.
197public enoprotoopt: atom
198--- errno EPROTONOSUPPORT: Protocol not supported.
199public eprotonosupport: atom
200--- errno ESOCKTNOSUPPORT: Socket type not supported.
201public esocktnosupport: atom
202--- errno EOPNOTSUPP: Operation not supported on transport endpoint.
203public eopnotsupp: atom
204--- errno EPFNOSUPPORT: Protocol family not supported.
205public epfnosupport: atom
206--- errno EAFNOSUPPORT: Address family not supported by protocol.
207public eafnosupport: atom
208--- errno EADDRINUSE: Address already in use.
209public eaddrinuse: atom
210--- errno EADDRNOTAVAIL: Cannot assign requested address.
211public eaddrnotavail: atom
212--- errno ENETDOWN: Network is down.
213public enetdown: atom
214--- errno ENETUNREACH: Network is unreachable.
215public enetunreach: atom
216--- errno ENETRESET: Network dropped connection because of reset.
217public enetreset: atom
218--- errno ECONNABORTED: Software caused connection abort.
219public econnaborted: atom
220--- errno ECONNRESET: Connection reset by peer.
221public econnreset: atom
222--- errno ENOBUFS: No buffer space available.
223public enobufs: atom
224--- errno EISCONN: Transport endpoint is already connected.
225public eisconn: atom
226--- errno ENOTCONN: Transport endpoint is not connected.
227public enotconn: atom
228--- errno ESHUTDOWN: Cannot send after transport endpoint shutdown.
229public eshutdown: atom
230--- errno ETOOMANYREFS: Too many references: cannot splice.
231public etoomanyrefs: atom
232--- errno ETIMEDOUT: Connection timed out.
233public etimedout: atom
234--- errno ECONNREFUSED: Connection refused.
235public econnrefused: atom
236--- errno EHOSTDOWN: Host is down.
237public ehostdown: atom
238--- errno EHOSTUNREACH: No route to host.
239public ehostunreach: atom
240--- errno EALREADY: Operation already in progress.
241public ealready: atom
242--- errno EINPROGRESS: Operation now in progress.
243public einprogress: atom
244--- errno ESTALE: Stale file handle.
245public estale: atom
246--- errno EUCLEAN: Structure needs cleaning.
247public euclean: atom
248--- errno ENOTNAM: Not a XENIX named type file.
249public enotnam: atom
250--- errno ENAVAIL: No XENIX semaphores available.
251public enavail: atom
252--- errno EISNAM: Is a named type file.
253public eisnam: atom
254--- errno EREMOTEIO: Remote I/O error.
255public eremoteio: atom
256--- errno EDQUOT: Quota exceeded.
257public edquot: atom
258--- errno ENOMEDIUM: No medium found.
259public enomedium: atom
260--- errno EMEDIUMTYPE: Wrong medium type.
261public emediumtype: atom
262--- errno ECANCELED: Operation Canceled.
263public ecanceled: atom
264--- errno ENOKEY: Required key not available.
265public enokey: atom
266--- errno EKEYEXPIRED: Key has expired.
267public ekeyexpired: atom
268--- errno EKEYREVOKED: Key has been revoked.
269public ekeyrevoked: atom
270--- errno EKEYREJECTED: Key was rejected by service.
271public ekeyrejected: atom
272--- errno EOWNERDEAD: Owner died.
273public eownerdead: atom
274--- errno ENOTRECOVERABLE: State not recoverable.
275public enotrecoverable: atom
276--- errno ERFKILL: Operation not possible due to RF-kill.
277public erfkill: atom
278--- errno EHWPOISON: Memory page has hardware error.
279public ehwpoison: atom
280--- errno EAUTH: Authentication error.
281public eauth: atom
282--- errno EBADARCH: Bad CPU type in executable.
283public ebadarch: atom
284--- errno EBADEXEC: Bad executable (or shared library).
285public ebadexec: atom
286--- errno EBADMACHO: Malformed Mach-o file.
287public ebadmacho: atom
288--- errno EBADRPC: RPC struct is bad.
289public ebadrpc: atom
290--- errno ECAPMODE: Not permitted in capability mode.
291public ecapmode: atom
292--- errno EDEVERR: Device error.
293public edeverr: atom
294--- errno EDOOFUS: Programming error.
295public edoofus: atom
296--- errno EFTYPE: Inappropriate file type or format.
297public eftype: atom
298--- errno EINTEGRITY: Integrity check failed.
299public eintegrity: atom
300--- errno ENEEDAUTH: Need authenticator.
301public eneedauth: atom
302--- errno ENOATTR: Attribute not found.
303public enoattr: atom
304--- errno ENOPOLICY: Policy not found.
305public enopolicy: atom
306--- errno ENOTCAPABLE: Capabilities insufficient.
307public enotcapable: atom
308--- errno ENOTSUP: Operation not supported.
309public enotsup: atom
310--- errno EPROCLIM: Too many processes.
311public eproclim: atom
312--- errno EPROCUNAVAIL: Bad procedure for program.
313public eprocunavail: atom
314--- errno EPROGMISMATCH: Program version wrong.
315public eprogmismatch: atom
316--- errno EPROGUNAVAIL: RPC prog. not avail.
317public eprogunavail: atom
318--- errno EPWROFF: Device power is off.
319public epwroff: atom
320--- errno EQFULL: Interface output queue is full.
321public eqfull: atom
322--- errno ERPCMISMATCH: RPC version wrong.
323public erpcmismatch: atom
324--- errno ESHLIBVERS: Shared library version mismatch.
325public eshlibvers: atom
326
327--- Every failure a POSIX call here reports: the errno it failed with, as
328--- an atom, or `unlisted`.  `number` gives the errno's number on this
329--- system and `errno_of` the atom for a number.
330public errno: type = eperm | enoent | esrch | eintr | eio | enxio | e2big
331    | enoexec | ebadf | echild | eagain | enomem | eacces | efault | enotblk
332    | ebusy | eexist | exdev | enodev | enotdir | eisdir | einval | enfile
333    | emfile | enotty | etxtbsy | efbig | enospc | espipe | erofs | emlink
334    | epipe | edom | erange | edeadlk | enametoolong | enolck | enosys
335    | enotempty | eloop | enomsg | eidrm | echrng | el2nsync | el3hlt | el3rst
336    | elnrng | eunatch | enocsi | el2hlt | ebade | ebadr | exfull | enoano
337    | ebadrqc | ebadslt | ebfont | enostr | enodata | etime | enosr | enonet
338    | enopkg | eremote | enolink | eadv | esrmnt | ecomm | eproto | emultihop
339    | edotdot | ebadmsg | eoverflow | enotuniq | ebadfd | eremchg | elibacc
340    | elibbad | elibscn | elibmax | elibexec | eilseq | erestart | estrpipe
341    | eusers | enotsock | edestaddrreq | emsgsize | eprototype | enoprotoopt
342    | eprotonosupport | esocktnosupport | eopnotsupp | epfnosupport
343    | eafnosupport | eaddrinuse | eaddrnotavail | enetdown | enetunreach
344    | enetreset | econnaborted | econnreset | enobufs | eisconn | enotconn
345    | eshutdown | etoomanyrefs | etimedout | econnrefused | ehostdown
346    | ehostunreach | ealready | einprogress | estale | euclean | enotnam
347    | enavail | eisnam | eremoteio | edquot | enomedium | emediumtype
348    | ecanceled | enokey | ekeyexpired | ekeyrevoked | ekeyrejected
349    | eownerdead | enotrecoverable | erfkill | ehwpoison | eauth | ebadarch
350    | ebadexec | ebadmacho | ebadrpc | ecapmode | edeverr | edoofus | eftype
351    | eintegrity | eneedauth | enoattr | enopolicy | enotcapable | enotsup
352    | eproclim | eprocunavail | eprogmismatch | eprogunavail | epwroff
353    | eqfull | erpcmismatch | eshlibvers | unlisted
354
355--  Each system's errno numbers in order: entry N is the atom for errno N,
356--  and a number the system leaves unused is `unlisted`.
357fixed if compiler.os == darwin then
358    --  Whether ENOTSUP is EOPNOTSUPP's number.
359    shared_notsup: bool = false
360else
361    shared_notsup: bool = true
362end if
363
364fixed if compiler.os == linux then
365    errno_table: [134]errno =
366        [unlisted, eperm, enoent, esrch, eintr, eio, enxio, e2big, enoexec,
367         ebadf, echild, eagain, enomem, eacces, efault, enotblk, ebusy,
368         eexist, exdev, enodev, enotdir, eisdir, einval, enfile, emfile,
369         enotty, etxtbsy, efbig, enospc, espipe, erofs, emlink, epipe, edom,
370         erange, edeadlk, enametoolong, enolck, enosys, enotempty, eloop,
371         unlisted, enomsg, eidrm, echrng, el2nsync, el3hlt, el3rst, elnrng,
372         eunatch, enocsi, el2hlt, ebade, ebadr, exfull, enoano, ebadrqc,
373         ebadslt, unlisted, ebfont, enostr, enodata, etime, enosr, enonet,
374         enopkg, eremote, enolink, eadv, esrmnt, ecomm, eproto, emultihop,
375         edotdot, ebadmsg, eoverflow, enotuniq, ebadfd, eremchg, elibacc,
376         elibbad, elibscn, elibmax, elibexec, eilseq, erestart, estrpipe,
377         eusers, enotsock, edestaddrreq, emsgsize, eprototype, enoprotoopt,
378         eprotonosupport, esocktnosupport, eopnotsupp, epfnosupport,
379         eafnosupport, eaddrinuse, eaddrnotavail, enetdown, enetunreach,
380         enetreset, econnaborted, econnreset, enobufs, eisconn, enotconn,
381         eshutdown, etoomanyrefs, etimedout, econnrefused, ehostdown,
382         ehostunreach, ealready, einprogress, estale, euclean, enotnam,
383         enavail, eisnam, eremoteio, edquot, enomedium, emediumtype,
384         ecanceled, enokey, ekeyexpired, ekeyrevoked, ekeyrejected,
385         eownerdead, enotrecoverable, erfkill, ehwpoison]
386elsif compiler.os == darwin then
387    errno_table: [108]errno =
388        [unlisted, eperm, enoent, esrch, eintr, eio, enxio, e2big, enoexec,
389         ebadf, echild, edeadlk, enomem, eacces, efault, enotblk, ebusy,
390         eexist, exdev, enodev, enotdir, eisdir, einval, enfile, emfile,
391         enotty, etxtbsy, efbig, enospc, espipe, erofs, emlink, epipe, edom,
392         erange, eagain, einprogress, ealready, enotsock, edestaddrreq,
393         emsgsize, eprototype, enoprotoopt, eprotonosupport, esocktnosupport,
394         enotsup, epfnosupport, eafnosupport, eaddrinuse, eaddrnotavail,
395         enetdown, enetunreach, enetreset, econnaborted, econnreset, enobufs,
396         eisconn, enotconn, eshutdown, etoomanyrefs, etimedout, econnrefused,
397         eloop, enametoolong, ehostdown, ehostunreach, enotempty, eproclim,
398         eusers, edquot, estale, eremote, ebadrpc, erpcmismatch,
399         eprogunavail, eprogmismatch, eprocunavail, enolck, enosys, eftype,
400         eauth, eneedauth, epwroff, edeverr, eoverflow, ebadexec, ebadarch,
401         eshlibvers, ebadmacho, ecanceled, eidrm, enomsg, eilseq, enoattr,
402         ebadmsg, emultihop, enodata, enolink, enosr, enostr, eproto, etime,
403         eopnotsupp, enopolicy, enotrecoverable, eownerdead, eqfull,
404         enotcapable]
405else
406    errno_table: [98]errno =
407        [unlisted, eperm, enoent, esrch, eintr, eio, enxio, e2big, enoexec,
408         ebadf, echild, edeadlk, enomem, eacces, efault, enotblk, ebusy,
409         eexist, exdev, enodev, enotdir, eisdir, einval, enfile, emfile,
410         enotty, etxtbsy, efbig, enospc, espipe, erofs, emlink, epipe, edom,
411         erange, eagain, einprogress, ealready, enotsock, edestaddrreq,
412         emsgsize, eprototype, enoprotoopt, eprotonosupport, esocktnosupport,
413         eopnotsupp, epfnosupport, eafnosupport, eaddrinuse, eaddrnotavail,
414         enetdown, enetunreach, enetreset, econnaborted, econnreset, enobufs,
415         eisconn, enotconn, eshutdown, etoomanyrefs, etimedout, econnrefused,
416         eloop, enametoolong, ehostdown, ehostunreach, enotempty, eproclim,
417         eusers, edquot, estale, eremote, ebadrpc, erpcmismatch,
418         eprogunavail, eprogmismatch, eprocunavail, enolck, enosys, eftype,
419         eauth, eneedauth, eidrm, enomsg, eoverflow, ecanceled, eilseq,
420         enoattr, edoofus, ebadmsg, emultihop, enolink, eproto, enotcapable,
421         ecapmode, enotrecoverable, eownerdead, eintegrity]
422end if
423
424--- The errno atom for the number `value` on this system: `unlisted` for a
425--- number it does not define.
426public link(symbol: "_landin_posix_errno_of") errno_of:
427    (value: i32) -> (problem: errno) =
428    problem = unlisted
429    return when value <= 0 or usize(value) >= lenof errno_table
430    problem = errno_table[usize(value)]
431end errno_of
432
433--- The number `problem` has on this system, as C's `errno` holds it: zero for
434--- `unlisted` and for an errno this system does not define.  ENOTSUP is
435--- EOPNOTSUPP's number on Linux and FreeBSD.
436public link(symbol: "_landin_posix_number") number:
437    (problem: errno) -> (value: i32) =
438    value = 0
439    return when problem == unlisted
440    mut sought: errno = problem
441    if shared_notsup and sought == enotsup then sought = eopnotsupp end if
442    for at in usize(1)..<lenof errno_table do
443        if errno_table[at] == sought then
444            value = i32(at)
445            return
446        end if
447    end for
448end number