From dc9f9f55cb6b38b87d8c228ae9abb4b53ebfb25c Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Mon, 15 Mar 2021 22:54:54 +0100 Subject: System hardening and errno impl --- libc/str.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'libc/str.c') diff --git a/libc/str.c b/libc/str.c index 13ac27f..54be4f6 100644 --- a/libc/str.c +++ b/libc/str.c @@ -1,6 +1,7 @@ // MIT License, Copyright (c) 2020 Marvin Borner #include <def.h> +#include <errno.h> #include <mem.h> #include <str.h> @@ -124,3 +125,48 @@ char *strdup(const char *s) return d; } + +static const char *strerrors[EMAX] = { + "Success", + "Operation not permitted", + "No such file or directory", + "No such process", + "Interrupted system call", + "I/O error", + "No such device or address", + "Argument list too long", + "Exec format error", + "Bad file number", + "No child processes", + "Try again", + "Out of memory", + "Permission denied", + "Bad address", + "Block device required", + "Device or resource busy", + "File exists", + "Cross-device link", + "No such device", + "Not a directory", + "Is a directory", + "Invalid argument", + "File table overflow", + "Too many open files", + "Not a typewriter", + "Text file busy", + "File too large", + "No space left on device", + "Illegal seek", + "Read-only file system", + "Too many links", + "Broken pipe", + "Math argument out of domain of func", + "Math result not representable", +}; + +const char *strerror(u32 error) +{ + if (error <= EMAX) + return strerrors[error]; + return "Unknown error"; +} -- cgit v1.2.3