Kernel+LibC: Add some errno codes

Kernel now returns ENOMEM and other errnos, so we dont have to write
error messages
This commit is contained in:
Bananymous
2023-03-02 21:10:44 +02:00
parent 90a7268e5a
commit 52aa98ba25
16 changed files with 87 additions and 31 deletions

View File

@@ -41,9 +41,10 @@ string/memcpy.o \
string/memmove.o \
string/memset.o \
string/strcmp.o \
string/strncmp.o \
string/strcpy.o \
string/strerror.o \
string/strlen.o \
string/strncmp.o \
string/strncpy.o \
string/strstr.o \

16
libc/include/errno.h Normal file
View File

@@ -0,0 +1,16 @@
#pragma once
#include <sys/cdefs.h>
#define ENOMEM 1
#define EINVAL 2
#define ENOTDIR 3
#define EISDIR 4
#define ENOENT 5
#define EIO 6
__BEGIN_DECLS
extern int errno;
__END_DECLS

View File

@@ -19,4 +19,6 @@ char* strncpy(char* __restrict, const char* __restrict, size_t);
char* strstr(const char*, const char*);
char* strerror(int);
__END_DECLS

32
libc/string/strerror.cpp Normal file
View File

@@ -0,0 +1,32 @@
#include <errno.h>
#include <string.h>
int errno = 0;
char* strerror(int error)
{
switch (error)
{
case ENOMEM:
return "Cannot allocate memory";
case EINVAL:
return "Invalid argument";
case EISDIR:
return "Is a directory";
case ENOTDIR:
return "Not a directory";
case ENOENT:
return "No such file or directory";
case EIO:
return "Input/output error";
default:
break;
}
// FIXME: sprintf
//static char buffer[26];
//sprintf(buffer, "Unknown error %d", error);
//return buffer;
errno = EINVAL;
return "Unknown error";
}