Files
mercury/runtime/mercury_errno_name.c
Peter Wang aaa6ac5fe1 Introduce io.system_error to io.m public interface.
Implement the error handling proposals from February 2022 on the
mercury-users list, and August 2022 on the mercury-reviews list.

We add io.system_error to the public interface of io.m
and document what its foreign representation is for each backend.

We allow io.error to optionally contain an io.system_error value,
and provide predicates to retrieve the io.system_error from an io.error.
The user may then inspect the system error via foreign code.

We also provide a predicate that takes an io.error and returns a name
for the system error it contains (if any). This makes it relatively easy
for Mercury programs to check for specific error conditions.

By returning platform-specific (actually, implementation-dependent)
error names, we are pushing the responsibility of mapping strings to
error conditions onto the application programmer. On the other hand, it
is not practical for us to map all possible system-specific error codes
to some common set of values. We could do it for a small set of common
error codes/exceptions, perhaps.

The standard library will construct io.error values containing
io.system_errors. However, we do not yet provide a facility for user
code to do the same.

library/io.m:
    Move io.system_error to the public interface.

    Change the internal representation of io.error to support containing
    a io.system_error. An io.system_error may originate from an errno
    value or a Windows system error code; the constructor distinguishes
    those cases.

    Add predicates to retrieve a system_error from io.error.

    Add predicate to return the name of the system error in an io.error.

    Replace make_err_msg with make_io_error_from_system_error.

    Replace make_maybe_win32_err_msg with
    make_io_error_from_maybe_win32_error.

    Delete ML_make_err_msg and ML_make_win32_err_msg macros.

browser/listing.m:
library/bitmap.m:
library/dir.m:
library/io.call_system.m:
library/io.environment.m:
library/io.file.m:
library/io.text_read.m:
mdbcomp/program_representation.m:
    Conform to changes.

    Leave comments for followup work.

tools/generate_errno_name:
tools/generate_windows_error_name:
    Add scripts to generate mercury_errno_name.c and
    mercury_windows_error_name.c.

runtime/Mmakefile:
runtime/mercury_errno_name.c:
runtime/mercury_errno_name.h:
runtime/mercury_windows_error_name.c:
runtime/mercury_windows_error_name.h:
    Add MR_errno_name() and MR_win32_error_name() functions,
    used by io.m to convert error codes to string names.

tests/hard_coded/null_char.exp:
    Update expected output.
2022-08-23 16:39:48 +10:00

473 lines
9.3 KiB
C

// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 2022 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// Generated by generate_errno_name.
#include <errno.h>
#include <stdlib.h>
#include "mercury_errno_name.h"
const char *
MR_errno_name(int errnum)
{
switch (errnum) {
#ifdef ENOSYS
case ENOSYS: return "ENOSYS";
#endif
#ifdef EPERM
case EPERM: return "EPERM";
#endif
#ifdef ENOENT
case ENOENT: return "ENOENT";
#endif
#ifdef ESRCH
case ESRCH: return "ESRCH";
#endif
#ifdef EINTR
case EINTR: return "EINTR";
#endif
#ifdef EIO
case EIO: return "EIO";
#endif
#ifdef ENXIO
case ENXIO: return "ENXIO";
#endif
#ifdef E2BIG
case E2BIG: return "E2BIG";
#endif
#ifdef ENOEXEC
case ENOEXEC: return "ENOEXEC";
#endif
#ifdef EBADF
case EBADF: return "EBADF";
#endif
#ifdef ECHILD
case ECHILD: return "ECHILD";
#endif
#ifdef EAGAIN
case EAGAIN: return "EAGAIN";
#endif
#ifdef ENOMEM
case ENOMEM: return "ENOMEM";
#endif
#ifdef EACCES
case EACCES: return "EACCES";
#endif
#ifdef EFAULT
case EFAULT: return "EFAULT";
#endif
#ifdef ENOTBLK
case ENOTBLK: return "ENOTBLK";
#endif
#ifdef EBUSY
case EBUSY: return "EBUSY";
#endif
#ifdef EEXIST
case EEXIST: return "EEXIST";
#endif
#ifdef EXDEV
case EXDEV: return "EXDEV";
#endif
#ifdef ENODEV
case ENODEV: return "ENODEV";
#endif
#ifdef ENOTDIR
case ENOTDIR: return "ENOTDIR";
#endif
#ifdef EISDIR
case EISDIR: return "EISDIR";
#endif
#ifdef EINVAL
case EINVAL: return "EINVAL";
#endif
#ifdef ENFILE
case ENFILE: return "ENFILE";
#endif
#ifdef EMFILE
case EMFILE: return "EMFILE";
#endif
#ifdef ENOTTY
case ENOTTY: return "ENOTTY";
#endif
#ifdef ETXTBSY
case ETXTBSY: return "ETXTBSY";
#endif
#ifdef EFBIG
case EFBIG: return "EFBIG";
#endif
#ifdef ENOSPC
case ENOSPC: return "ENOSPC";
#endif
#ifdef EDQUOT
case EDQUOT: return "EDQUOT";
#endif
#ifdef ESPIPE
case ESPIPE: return "ESPIPE";
#endif
#ifdef EROFS
case EROFS: return "EROFS";
#endif
#ifdef EMLINK
case EMLINK: return "EMLINK";
#endif
#ifdef EPIPE
case EPIPE: return "EPIPE";
#endif
#ifdef EDOM
case EDOM: return "EDOM";
#endif
#ifdef ERANGE
case ERANGE: return "ERANGE";
#endif
#ifdef EDEADLK
case EDEADLK: return "EDEADLK";
#endif
#ifdef ENAMETOOLONG
case ENAMETOOLONG: return "ENAMETOOLONG";
#endif
#ifdef ENOLCK
case ENOLCK: return "ENOLCK";
#endif
#ifdef ENOTEMPTY
case ENOTEMPTY: return "ENOTEMPTY";
#endif
#ifdef ELOOP
case ELOOP: return "ELOOP";
#endif
#ifdef ENOMSG
case ENOMSG: return "ENOMSG";
#endif
#ifdef EIDRM
case EIDRM: return "EIDRM";
#endif
#ifdef ETIME
case ETIME: return "ETIME";
#endif
#ifdef EPROTO
case EPROTO: return "EPROTO";
#endif
#ifdef EOVERFLOW
case EOVERFLOW: return "EOVERFLOW";
#endif
#ifdef EILSEQ
case EILSEQ: return "EILSEQ";
#endif
#ifdef EUSERS
case EUSERS: return "EUSERS";
#endif
#ifdef ENOTSOCK
case ENOTSOCK: return "ENOTSOCK";
#endif
#ifdef EDESTADDRREQ
case EDESTADDRREQ: return "EDESTADDRREQ";
#endif
#ifdef EMSGSIZE
case EMSGSIZE: return "EMSGSIZE";
#endif
#ifdef EPROTOTYPE
case EPROTOTYPE: return "EPROTOTYPE";
#endif
#ifdef ENOPROTOOPT
case ENOPROTOOPT: return "ENOPROTOOPT";
#endif
#ifdef EPROTONOSUPPORT
case EPROTONOSUPPORT: return "EPROTONOSUPPORT";
#endif
#ifdef ESOCKTNOSUPPORT
case ESOCKTNOSUPPORT: return "ESOCKTNOSUPPORT";
#endif
#ifdef EOPNOTSUPP
case EOPNOTSUPP: return "EOPNOTSUPP";
#endif
#ifdef EPFNOSUPPORT
case EPFNOSUPPORT: return "EPFNOSUPPORT";
#endif
#ifdef EAFNOSUPPORT
case EAFNOSUPPORT: return "EAFNOSUPPORT";
#endif
#ifdef EADDRINUSE
case EADDRINUSE: return "EADDRINUSE";
#endif
#ifdef EADDRNOTAVAIL
case EADDRNOTAVAIL: return "EADDRNOTAVAIL";
#endif
#ifdef ENETDOWN
case ENETDOWN: return "ENETDOWN";
#endif
#ifdef ENETUNREACH
case ENETUNREACH: return "ENETUNREACH";
#endif
#ifdef ENETRESET
case ENETRESET: return "ENETRESET";
#endif
#ifdef ECONNABORTED
case ECONNABORTED: return "ECONNABORTED";
#endif
#ifdef ECONNRESET
case ECONNRESET: return "ECONNRESET";
#endif
#ifdef ENOBUFS
case ENOBUFS: return "ENOBUFS";
#endif
#ifdef EISCONN
case EISCONN: return "EISCONN";
#endif
#ifdef ENOTCONN
case ENOTCONN: return "ENOTCONN";
#endif
#ifdef ESHUTDOWN
case ESHUTDOWN: return "ESHUTDOWN";
#endif
#ifdef ETOOMANYREFS
case ETOOMANYREFS: return "ETOOMANYREFS";
#endif
#ifdef ETIMEDOUT
case ETIMEDOUT: return "ETIMEDOUT";
#endif
#ifdef ECONNREFUSED
case ECONNREFUSED: return "ECONNREFUSED";
#endif
#ifdef EHOSTDOWN
case EHOSTDOWN: return "EHOSTDOWN";
#endif
#ifdef EHOSTUNREACH
case EHOSTUNREACH: return "EHOSTUNREACH";
#endif
#ifdef EALREADY
case EALREADY: return "EALREADY";
#endif
#ifdef EINPROGRESS
case EINPROGRESS: return "EINPROGRESS";
#endif
#ifdef ESTALE
case ESTALE: return "ESTALE";
#endif
#ifdef EREMOTE
case EREMOTE: return "EREMOTE";
#endif
#ifdef EBADRPC
case EBADRPC: return "EBADRPC";
#endif
#ifdef ERPCMISMATCH
case ERPCMISMATCH: return "ERPCMISMATCH";
#endif
#ifdef EPROGUNAVAIL
case EPROGUNAVAIL: return "EPROGUNAVAIL";
#endif
#ifdef EPROGMISMATCH
case EPROGMISMATCH: return "EPROGMISMATCH";
#endif
#ifdef EPROCUNAVAIL
case EPROCUNAVAIL: return "EPROCUNAVAIL";
#endif
#ifdef EFTYPE
case EFTYPE: return "EFTYPE";
#endif
#ifdef EAUTH
case EAUTH: return "EAUTH";
#endif
#ifdef ENEEDAUTH
case ENEEDAUTH: return "ENEEDAUTH";
#endif
#ifdef EPROCLIM
case EPROCLIM: return "EPROCLIM";
#endif
#ifdef ENOATTR
case ENOATTR: return "ENOATTR";
#endif
#ifdef EPWROFF
case EPWROFF: return "EPWROFF";
#endif
#ifdef EDEVERR
case EDEVERR: return "EDEVERR";
#endif
#ifdef EBADEXEC
case EBADEXEC: return "EBADEXEC";
#endif
#ifdef EBADARCH
case EBADARCH: return "EBADARCH";
#endif
#ifdef ESHLIBVERS
case ESHLIBVERS: return "ESHLIBVERS";
#endif
#ifdef EBADMACHO
case EBADMACHO: return "EBADMACHO";
#endif
#ifdef ENOPOLICY
case ENOPOLICY: return "ENOPOLICY";
#endif
#ifdef EBADMSG
case EBADMSG: return "EBADMSG";
#endif
#ifdef ECANCELED
case ECANCELED: return "ECANCELED";
#endif
#ifdef EOWNERDEAD
case EOWNERDEAD: return "EOWNERDEAD";
#endif
#ifdef ENOTRECOVERABLE
case ENOTRECOVERABLE: return "ENOTRECOVERABLE";
#endif
#ifdef ENONET
case ENONET: return "ENONET";
#endif
#ifdef ERESTART
case ERESTART: return "ERESTART";
#endif
#ifdef ENODATA
case ENODATA: return "ENODATA";
#endif
#ifdef ENOSR
case ENOSR: return "ENOSR";
#endif
#ifdef ENOSTR
case ENOSTR: return "ENOSTR";
#endif
#ifdef EMULTIHOP
case EMULTIHOP: return "EMULTIHOP";
#endif
#ifdef ENOLINK
case ENOLINK: return "ENOLINK";
#endif
#ifdef ENOMEDIUM
case ENOMEDIUM: return "ENOMEDIUM";
#endif
#ifdef EMEDIUMTYPE
case EMEDIUMTYPE: return "EMEDIUMTYPE";
#endif
#ifdef EBADFD
case EBADFD: return "EBADFD";
#endif
#ifdef ECHRNG
case ECHRNG: return "ECHRNG";
#endif
#ifdef EL2NSYNC
case EL2NSYNC: return "EL2NSYNC";
#endif
#ifdef EL3HLT
case EL3HLT: return "EL3HLT";
#endif
#ifdef EL3RST
case EL3RST: return "EL3RST";
#endif
#ifdef ELNRNG
case ELNRNG: return "ELNRNG";
#endif
#ifdef EUNATCH
case EUNATCH: return "EUNATCH";
#endif
#ifdef ENOCSI
case ENOCSI: return "ENOCSI";
#endif
#ifdef EL2HLT
case EL2HLT: return "EL2HLT";
#endif
#ifdef EBADE
case EBADE: return "EBADE";
#endif
#ifdef EBADR
case EBADR: return "EBADR";
#endif
#ifdef EXFULL
case EXFULL: return "EXFULL";
#endif
#ifdef ENOANO
case ENOANO: return "ENOANO";
#endif
#ifdef EBADRQC
case EBADRQC: return "EBADRQC";
#endif
#ifdef EBADSLT
case EBADSLT: return "EBADSLT";
#endif
#ifdef ENOPKG
case ENOPKG: return "ENOPKG";
#endif
#ifdef EADV
case EADV: return "EADV";
#endif
#ifdef ESRMNT
case ESRMNT: return "ESRMNT";
#endif
#ifdef ECOMM
case ECOMM: return "ECOMM";
#endif
#ifdef EDOTDOT
case EDOTDOT: return "EDOTDOT";
#endif
#ifdef ENOTUNIQ
case ENOTUNIQ: return "ENOTUNIQ";
#endif
#ifdef EREMCHG
case EREMCHG: return "EREMCHG";
#endif
#ifdef ELIBACC
case ELIBACC: return "ELIBACC";
#endif
#ifdef ELIBBAD
case ELIBBAD: return "ELIBBAD";
#endif
#ifdef ELIBSCN
case ELIBSCN: return "ELIBSCN";
#endif
#ifdef ELIBMAX
case ELIBMAX: return "ELIBMAX";
#endif
#ifdef ELIBEXEC
case ELIBEXEC: return "ELIBEXEC";
#endif
#ifdef ESTRPIPE
case ESTRPIPE: return "ESTRPIPE";
#endif
#ifdef EUCLEAN
case EUCLEAN: return "EUCLEAN";
#endif
#ifdef ENOTNAM
case ENOTNAM: return "ENOTNAM";
#endif
#ifdef ENAVAIL
case ENAVAIL: return "ENAVAIL";
#endif
#ifdef EISNAM
case EISNAM: return "EISNAM";
#endif
#ifdef EREMOTEIO
case EREMOTEIO: return "EREMOTEIO";
#endif
#ifdef ENOKEY
case ENOKEY: return "ENOKEY";
#endif
#ifdef EKEYEXPIRED
case EKEYEXPIRED: return "EKEYEXPIRED";
#endif
#ifdef EKEYREVOKED
case EKEYREVOKED: return "EKEYREVOKED";
#endif
#ifdef EKEYREJECTED
case EKEYREJECTED: return "EKEYREJECTED";
#endif
#ifdef ERFKILL
case ERFKILL: return "ERFKILL";
#endif
#ifdef EHWPOISON
case EHWPOISON: return "EHWPOISON";
#endif
#ifdef EBFONT
case EBFONT: return "EBFONT";
#endif
#if defined(EWOULDBLOCK) && !defined(EAGAIN)
case EWOULDBLOCK: return "EWOULDBLOCK";
#endif
#if defined(EDEADLOCK) && !defined(EDEADLK)
case EDEADLOCK: return "EDEADLOCK";
#endif
#if defined(ENOTSUP) && !defined(EOPNOTSUPP)
case ENOTSUP: return "ENOTSUP";
#endif
default: return NULL;
}
}