From 71bfe0283dd932721763a2b5d6559eca0eb1652e Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Mon, 22 Mar 2021 00:48:28 +0000 Subject: [PATCH] libast: consolidate errno ID fallbacks into error.h In various places in libast and libcmd there are preprocessor fallbacks like this, for systems that don't define all the commonly used errno value IDs: #ifndef ENOSYS #define ENOSYS EINVAL #endif and many others. It is better to have these all in one place so they are not duplicated and we don't risk inconsistencies when adding new code. src/lib/libast/include/error.h includes the OS's , so it is the logical file to move all these fallbacks into. Quite possibly there is no remotely current system that needs any of these, but they won't do any harm either. Most files already use directly or indirectly. Four needed new #include directives to use the fallbacks if needed. The libast Mamfile is updated to make those files depend on that header. --- src/lib/libast/Mamfile | 4 +++ src/lib/libast/comp/fsync.c | 4 --- src/lib/libast/comp/iconv.c | 8 +----- src/lib/libast/comp/link.c | 4 --- src/lib/libast/comp/mkfifo.c | 4 --- src/lib/libast/comp/mknod.c | 4 --- src/lib/libast/comp/mount.c | 4 --- src/lib/libast/comp/readlink.c | 4 --- src/lib/libast/comp/setpgid.c | 4 --- src/lib/libast/comp/spawnveg.c | 4 --- src/lib/libast/comp/symlink.c | 4 --- src/lib/libast/comp/vfork.c | 4 --- src/lib/libast/include/error.h | 40 ++++++++++++++++++++++++++++- src/lib/libast/misc/fts.c | 5 ---- src/lib/libast/misc/getcwd.c | 4 --- src/lib/libast/preroot/getpreroot.c | 4 --- src/lib/libast/sfio/sfhdr.h | 22 +--------------- src/lib/libast/sfio/vthread.h | 15 +---------- src/lib/libast/string/strtoi.h | 5 +--- src/lib/libcmd/chgrp.c | 4 --- src/lib/libcmd/chmod.c | 4 --- src/lib/libcmd/date.c | 4 --- 22 files changed, 47 insertions(+), 112 deletions(-) diff --git a/src/lib/libast/Mamfile b/src/lib/libast/Mamfile index 275c60576..8b4a111d5 100644 --- a/src/lib/libast/Mamfile +++ b/src/lib/libast/Mamfile @@ -1523,6 +1523,7 @@ make install prev port/lclib.h implicit prev std/iconv.h implicit prev include/ccode.h implicit + prev include/error.h implicit prev std/dirent.h implicit prev include/ast.h implicit done comp/iconv.c @@ -1571,6 +1572,7 @@ make install make stropts.h implicit done stropts.h dontcare virtual prev std/wchar.h implicit + prev include/error.h implicit make FEATURE/float implicit meta FEATURE/float features/%>FEATURE/% features/float float make features/float @@ -1595,6 +1597,7 @@ make install make sfio/vthread.h implicit prev windows.h implicit prev std/endian.h implicit + prev include/error.h implicit prev ast_common.h implicit done sfio/vthread.h dontcare make include/sfio_t.h implicit @@ -2748,6 +2751,7 @@ make install make comp/strtol.c make string/strtoi.h implicit prev sfio/sfhdr.h implicit + prev include/error.h implicit prev include/ast.h implicit done string/strtoi.h dontcare done comp/strtol.c diff --git a/src/lib/libast/comp/fsync.c b/src/lib/libast/comp/fsync.c index 4223fa05f..44d37fe18 100644 --- a/src/lib/libast/comp/fsync.c +++ b/src/lib/libast/comp/fsync.c @@ -31,10 +31,6 @@ NoN(fsync) #include -#ifndef ENOSYS -#define ENOSYS EINVAL -#endif - int fsync(int fd) { diff --git a/src/lib/libast/comp/iconv.c b/src/lib/libast/comp/iconv.c index fb83172fb..146e992fd 100644 --- a/src/lib/libast/comp/iconv.c +++ b/src/lib/libast/comp/iconv.c @@ -31,6 +31,7 @@ #include #include +#include #define DEBUG_TRACE 0 #define _ICONV_LIST_PRIVATE_ @@ -56,13 +57,6 @@ #endif -#ifndef E2BIG -#define E2BIG ENOMEM -#endif -#ifndef EILSEQ -#define EILSEQ EIO -#endif - #define RETURN(e,n,fn) \ if (*fn && !e) e = E2BIG; \ if (e) { errno = e; return (size_t)(-1); } \ diff --git a/src/lib/libast/comp/link.c b/src/lib/libast/comp/link.c index 571806f01..c0fd3d715 100644 --- a/src/lib/libast/comp/link.c +++ b/src/lib/libast/comp/link.c @@ -31,10 +31,6 @@ NoN(link) #include -#ifndef ENOSYS -#define ENOSYS EINVAL -#endif - int link(const char* from, const char* to) { diff --git a/src/lib/libast/comp/mkfifo.c b/src/lib/libast/comp/mkfifo.c index e4b26a444..71c1945a6 100644 --- a/src/lib/libast/comp/mkfifo.c +++ b/src/lib/libast/comp/mkfifo.c @@ -32,10 +32,6 @@ NoN(mkfifo) #include #include -#ifndef ENOSYS -#define ENOSYS EINVAL -#endif - int mkfifo(const char* path, mode_t mode) { diff --git a/src/lib/libast/comp/mknod.c b/src/lib/libast/comp/mknod.c index 8172a131e..fc404964a 100644 --- a/src/lib/libast/comp/mknod.c +++ b/src/lib/libast/comp/mknod.c @@ -32,10 +32,6 @@ NoN(mknod) #include -#ifndef ENOSYS -#define ENOSYS EINVAL -#endif - int mknod(const char* path, mode_t mode, dev_t dev) { diff --git a/src/lib/libast/comp/mount.c b/src/lib/libast/comp/mount.c index eaf27e511..73ff9f926 100644 --- a/src/lib/libast/comp/mount.c +++ b/src/lib/libast/comp/mount.c @@ -31,10 +31,6 @@ NoN(mount) #include -#ifndef ENOSYS -#define ENOSYS EINVAL -#endif - int mount(const char* a, char* b, int c, void* d) { diff --git a/src/lib/libast/comp/readlink.c b/src/lib/libast/comp/readlink.c index 2af5d8fed..7526af1f1 100644 --- a/src/lib/libast/comp/readlink.c +++ b/src/lib/libast/comp/readlink.c @@ -33,10 +33,6 @@ NoN(readlink) #include -#ifndef ENOSYS -#define ENOSYS EINVAL -#endif - int readlink(const char* path, char* buf, int siz) { diff --git a/src/lib/libast/comp/setpgid.c b/src/lib/libast/comp/setpgid.c index c96691966..430535dd2 100644 --- a/src/lib/libast/comp/setpgid.c +++ b/src/lib/libast/comp/setpgid.c @@ -31,10 +31,6 @@ NoN(setpgid) #include -#ifndef ENOSYS -#define ENOSYS EINVAL -#endif - #if _lib_setpgrp2 #define setpgrp setpgrp2 #else diff --git a/src/lib/libast/comp/spawnveg.c b/src/lib/libast/comp/spawnveg.c index 78bbc349e..d172bf8be 100644 --- a/src/lib/libast/comp/spawnveg.c +++ b/src/lib/libast/comp/spawnveg.c @@ -140,10 +140,6 @@ spawnveg(const char* path, char* const argv[], char* const envv[], pid_t pgid) #include #include -#ifndef ENOSYS -#define ENOSYS EINVAL -#endif - #if _lib_spawnve && _hdr_process #include #if defined(P_NOWAIT) || defined(_P_NOWAIT) diff --git a/src/lib/libast/comp/symlink.c b/src/lib/libast/comp/symlink.c index d234d03e3..4858e0bea 100644 --- a/src/lib/libast/comp/symlink.c +++ b/src/lib/libast/comp/symlink.c @@ -33,10 +33,6 @@ NoN(symlink) #include -#ifndef ENOSYS -#define ENOSYS EINVAL -#endif - int symlink(const char* a, char* b) { diff --git a/src/lib/libast/comp/vfork.c b/src/lib/libast/comp/vfork.c index dfe2fd6b5..61ff4645e 100644 --- a/src/lib/libast/comp/vfork.c +++ b/src/lib/libast/comp/vfork.c @@ -31,10 +31,6 @@ NoN(vfork) #include -#ifndef ENOSYS -#define ENOSYS EINVAL -#endif - #undef vfork #if defined(__EXPORT__) diff --git a/src/lib/libast/include/error.h b/src/lib/libast/include/error.h index 14a636df6..cff5e4067 100644 --- a/src/lib/libast/include/error.h +++ b/src/lib/libast/include/error.h @@ -39,7 +39,6 @@ #if !defined(errno) && defined(__DYNAMIC__) #define errno __DYNAMIC__(errno) #endif - #define ERROR_debug(n) (-(n)) #define ERROR_exit(n) ((n)+ERROR_ERROR) #define ERROR_system(n) (((n)+ERROR_ERROR)|ERROR_SYSTEM) @@ -156,6 +155,45 @@ struct Error_info_s /* error state */ #ifndef errno extern int errno; /* system call error status */ #endif +#ifndef E2BIG +#define E2BIG ENOMEM +#endif +#ifndef EAGAIN +#define EAGAIN 11 +#endif +#ifndef EBADF +#define EBADF 9 +#endif +#ifndef EBUSY +#define EBUSY 16 +#endif +#ifndef EDEADLK +#define EDEADLK 45 +#endif +#ifndef EINTR +#define EINTR 4 +#endif +#ifndef EILSEQ +#define EILSEQ EIO +#endif +#ifndef EINVAL +#define EINVAL 22 +#endif +#ifndef ENOMEM +#define ENOMEM 12 +#endif +#ifndef ENOSYS +#define ENOSYS EINVAL +#endif +#ifndef EPERM +#define EPERM 1 +#endif +#ifndef ERANGE +#define ERANGE E2BIG +#endif +#ifndef ESPIPE +#define ESPIPE 29 +#endif #if _BLD_ast && defined(__EXPORT__) #define extern extern __EXPORT__ diff --git a/src/lib/libast/misc/fts.c b/src/lib/libast/misc/fts.c index c2091d043..18f864e40 100644 --- a/src/lib/libast/misc/fts.c +++ b/src/lib/libast/misc/fts.c @@ -92,11 +92,6 @@ typedef int (*Stat_f)(const char*, struct stat*); #include -#ifndef ENOSYS -#define ENOSYS EINVAL -#endif - - #if MAXNAMLEN > 16 #define MINNAME 32 #else diff --git a/src/lib/libast/misc/getcwd.c b/src/lib/libast/misc/getcwd.c index a8ac96d85..7bd2cacd9 100644 --- a/src/lib/libast/misc/getcwd.c +++ b/src/lib/libast/misc/getcwd.c @@ -80,10 +80,6 @@ getcwd(char* buf, size_t len) #include #include -#ifndef ERANGE -#define ERANGE E2BIG -#endif - #define ERROR(e) { errno = e; goto error; } struct dirlist /* long path chdir(2) component */ diff --git a/src/lib/libast/preroot/getpreroot.c b/src/lib/libast/preroot/getpreroot.c index 3747d19bc..91f3c7cbf 100644 --- a/src/lib/libast/preroot/getpreroot.c +++ b/src/lib/libast/preroot/getpreroot.c @@ -36,10 +36,6 @@ #include #include -#ifndef ERANGE -#define ERANGE E2BIG -#endif - #define ERROR(e) {errno=e;goto error;} char* diff --git a/src/lib/libast/sfio/sfhdr.h b/src/lib/libast/sfio/sfhdr.h index 629f65b19..70c7be388 100644 --- a/src/lib/libast/sfio/sfhdr.h +++ b/src/lib/libast/sfio/sfhdr.h @@ -301,7 +301,7 @@ #include "FEATURE/float" -#include +#include #include /* deal with multi-byte character and string conversions */ @@ -620,26 +620,6 @@ #define SF_FD_CLOEXEC 0x0001 -/* a couple of error number that we use, default values are like Linux */ -#ifndef EINTR -#define EINTR 4 -#endif -#ifndef EBADF -#define EBADF 9 -#endif -#ifndef EAGAIN -#define EAGAIN 11 -#endif -#ifndef ENOMEM -#define ENOMEM 12 -#endif -#ifndef EINVAL -#define EINVAL 22 -#endif -#ifndef ESPIPE -#define ESPIPE 29 -#endif - /* function to get the decimal point for local environment */ #if !defined(SFSETLOCALE) && _PACKAGE_ast #include "lclib.h" diff --git a/src/lib/libast/sfio/vthread.h b/src/lib/libast/sfio/vthread.h index 40309580c..97bbef3f5 100644 --- a/src/lib/libast/sfio/vthread.h +++ b/src/lib/libast/sfio/vthread.h @@ -32,7 +32,7 @@ */ #include -#include +#include /* ast doesn't do threads yet */ #if _PACKAGE_ast && !defined(vt_threaded) @@ -90,19 +90,6 @@ typedef struct _vtmutex_s Vtmutex_t; typedef struct _vtonce_s Vtonce_t; typedef struct _vthread_s Vthread_t; -#ifndef EINVAL -#define EINVAL 22 -#endif -#ifndef EBUSY -#define EBUSY 16 -#endif -#ifndef EDEADLK -#define EDEADLK 45 -#endif -#ifndef EPERM -#define EPERM 1 -#endif - _BEGIN_EXTERNS_ extern Vthread_t* vtopen _ARG_((Vthread_t*, int)); diff --git a/src/lib/libast/string/strtoi.h b/src/lib/libast/string/strtoi.h index 6275c23c8..c92b7b40f 100644 --- a/src/lib/libast/string/strtoi.h +++ b/src/lib/libast/string/strtoi.h @@ -85,6 +85,7 @@ #include #include +#include #include "sfhdr.h" @@ -92,10 +93,6 @@ #define const #endif -#ifndef ERANGE -#define ERANGE EINVAL -#endif - #define QL 01 #define QU 02 diff --git a/src/lib/libcmd/chgrp.c b/src/lib/libcmd/chgrp.c index 1fad5b17c..54c85ff02 100644 --- a/src/lib/libcmd/chgrp.c +++ b/src/lib/libcmd/chgrp.c @@ -109,10 +109,6 @@ __STDPP__directive pragma pp:hide lchown #include #include -#ifndef ENOSYS -#define ENOSYS EINVAL -#endif - #include "FEATURE/symlink" #if defined(__STDPP__directive) && defined(__STDPP__hide) diff --git a/src/lib/libcmd/chmod.c b/src/lib/libcmd/chmod.c index b0a8262c0..065a7ed17 100644 --- a/src/lib/libcmd/chmod.c +++ b/src/lib/libcmd/chmod.c @@ -137,10 +137,6 @@ __STDPP__directive pragma pp:hide lchmod #include #include -#ifndef ENOSYS -#define ENOSYS EINVAL -#endif - #include "FEATURE/symlink" #if defined(__STDPP__directive) && defined(__STDPP__hide) diff --git a/src/lib/libcmd/date.c b/src/lib/libcmd/date.c index be0685ba0..e84ae361c 100644 --- a/src/lib/libcmd/date.c +++ b/src/lib/libcmd/date.c @@ -207,10 +207,6 @@ typedef struct Fmt char* format; } Fmt_t; -#ifndef ENOSYS -#define ENOSYS EINVAL -#endif - /* * set the system clock * the standards wimped out here