banan-os/libc/string/strerror.cpp

57 lines
1022 B
C++
Raw Normal View History

#include <errno.h>
#include <string.h>
int errno = 0;
char* strerror(int error)
{
static char buffer[100];
buffer[0] = 0;
switch (error)
{
case ENOMEM:
strcpy(buffer, "Cannot allocate memory");
break;
case EINVAL:
strcpy(buffer, "Invalid argument");
break;
case EISDIR:
strcpy(buffer, "Is a directory");
break;
case ENOTDIR:
strcpy(buffer, "Not a directory");
break;
case ENOENT:
strcpy(buffer, "No such file or directory");
break;
case EIO:
strcpy(buffer, "Input/output error");
break;
2023-03-16 16:03:51 +02:00
case ENOTSUP:
strcpy(buffer, "Operation not supported");
break;
2023-03-16 16:22:11 +02:00
case EBADF:
strcpy(buffer, "Bad file descriptor");
break;
2023-03-19 04:17:39 +02:00
case EEXISTS:
strcpy(buffer, "File exists");
break;
2023-03-19 05:43:40 +02:00
case ENOTEMPTY:
strcpy(buffer, "Directory not empty");
break;
2023-03-23 14:48:42 +02:00
case ENAMETOOLONG:
strcpy(buffer, "Filename too long");
break;
default:
{
// FIXME: sprintf
//sprintf(buffer, "Unknown error %d", error);
strcpy(buffer, "Unknown error");
errno = EINVAL;
break;
}
}
return buffer;
}