diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/include/camellia/errno.h | 9 | ||||
-rw-r--r-- | src/user/lib/include/__errno.h | 16 | ||||
-rw-r--r-- | src/user/lib/include/__errno.h.awk | 20 | ||||
-rw-r--r-- | src/user/lib/stdio/misc.c | 2 | ||||
-rw-r--r-- | src/user/lib/string/strerror.c | 11 | ||||
-rw-r--r-- | src/user/lib/string/string.c (renamed from src/user/lib/string.c) | 6 |
6 files changed, 54 insertions, 10 deletions
diff --git a/src/shared/include/camellia/errno.h b/src/shared/include/camellia/errno.h index 1e4841c..263bd25 100644 --- a/src/shared/include/camellia/errno.h +++ b/src/shared/include/camellia/errno.h @@ -1,15 +1,18 @@ #pragma once +/* the comments are directly pasted into user visible strings. + * keep them short, don't include " */ +#define EGENERIC 1 /* unknown error */ #define EFAULT 2 -#define EBADF 3 /* Invalid file descriptor. */ +#define EBADF 3 /* bad file descriptor */ #define EINVAL 4 -#define ENOSYS 5 /* Unsupported. */ +#define ENOSYS 5 /* unsupported */ #define ERANGE 6 #define ENOMEM 7 #define ENOENT 8 #define ENOTEMPTY 9 #define EACCES 10 -#define EMFILE 11 /* All file descriptors taken. */ +#define EMFILE 11 /* all file descriptors taken */ #define ECONNRESET 12 #define EISDIR 200 diff --git a/src/user/lib/include/__errno.h b/src/user/lib/include/__errno.h new file mode 100644 index 0000000..d6d5e6a --- /dev/null +++ b/src/user/lib/include/__errno.h @@ -0,0 +1,16 @@ +/* generated by awk */ +#ifdef E +E( 1, "EGENERIC unknown error") +E( 2, "EFAULT") +E( 3, "EBADF bad file descriptor") +E( 4, "EINVAL") +E( 5, "ENOSYS unsupported") +E( 6, "ERANGE") +E( 7, "ENOMEM") +E( 8, "ENOENT") +E( 9, "ENOTEMPTY") +E( 10, "EACCES") +E( 11, "EMFILE all file descriptors taken") +E( 12, "ECONNRESET") +E(200, "EISDIR") +#endif diff --git a/src/user/lib/include/__errno.h.awk b/src/user/lib/include/__errno.h.awk new file mode 100644 index 0000000..6232835 --- /dev/null +++ b/src/user/lib/include/__errno.h.awk @@ -0,0 +1,20 @@ +BEGIN { + print "/* generated by awk */"; + print "#ifdef E"; +} + +END { + print "#endif"; +} + +/#define/ { + comment = $2; + num = $3; + # extract the comment, if present + if (index($0, "/*")) { + sub(/[^/]*\/\*/, ""); + sub(/ *\*\//, ""); + comment = comment $0; + } + printf "E(%3s, \"%s\")\n", num, comment; +} diff --git a/src/user/lib/stdio/misc.c b/src/user/lib/stdio/misc.c index a140ee4..45144f3 100644 --- a/src/user/lib/stdio/misc.c +++ b/src/user/lib/stdio/misc.c @@ -5,7 +5,7 @@ void perror(const char *s) { if (s) fprintf(stderr, "%s: ", s); - fprintf(stderr, "errno %d\n", errno); + fprintf(stderr, "%s\n", strerror(errno)); } int puts(const char *s) { diff --git a/src/user/lib/string/strerror.c b/src/user/lib/string/strerror.c new file mode 100644 index 0000000..1f5fc29 --- /dev/null +++ b/src/user/lib/string/strerror.c @@ -0,0 +1,11 @@ +#include <string.h> + +static const char *errstr[] = { +# define E(n, str) [n] = str, +# include <__errno.h> +# undef E +}; + +char *strerror(int n) { + return (char*)(errstr[n] ? errstr[n] : "unknown error"); +} diff --git a/src/user/lib/string.c b/src/user/lib/string/string.c index fa9c0ca..f141a3d 100644 --- a/src/user/lib/string.c +++ b/src/user/lib/string/string.c @@ -151,12 +151,6 @@ char *strdup(const char *s) { return buf; } -// TODO strerror mapping -char *strerror(int errnum) { - (void)errnum; - return "unknown error"; -} - /* strings.h */ int strcasecmp(const char *s1, const char *s2) { return strncasecmp(s1, s2, ~0); |