Merge branch perror into main

Reviewed-on: #6
This commit is contained in:
apio 2022-10-08 10:46:02 +00:00
commit 9b778254f1
3 changed files with 8 additions and 1 deletions

View File

@ -15,6 +15,6 @@ int main()
printf("Allocating 4 MB of memory... %lx\n", (unsigned long)allocated);
sleep(1);
} while ((allocated = malloc(CHUNK)));
printf("Out of memory. (errno=%d, %s)\n", errno, strerror(errno));
perror("malloc");
printf("Press any key to restart.\n");
}

View File

@ -35,6 +35,7 @@ extern "C"
int vsprintf(char*, const char*, va_list);
int vsnprintf(char*, size_t, const char*, va_list);
int puts(const char*);
void perror(const char*);
#ifdef __cplusplus
}

View File

@ -1,3 +1,4 @@
#include <errno.h>
#include <luna.h>
#include <stdio.h>
#include <stdlib.h>
@ -78,4 +79,9 @@ extern "C"
va_end(ap);
return written;
}
void perror(const char* s) // FIXME: Print to stderr, whenever we have an stderr.
{
if (s && *s) { printf("%s: ", s); }
printf("%s\n", strerror(errno));
}
}