LibC: strerror now always uses a buffer to which it copies the string

This commit is contained in:
Bananymous 2023-03-02 22:13:08 +02:00
parent 1c146ba1a5
commit 53ec66ff86
1 changed files with 28 additions and 18 deletions

View File

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