ref: f25ac60f427a1eb55971e17921c72ef2afa7e8f8
parent: 46d3eab0b1e077005fcc4a7bc5257be9a411d1a1
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Dec 7 04:07:39 EST 2017
[lib/c] Add perror() and strerror()
--- a/lib/c/include/errno.h
+++ b/lib/c/include/errno.h
@@ -8,5 +8,7 @@
#define EBADF 5
extern int errno;
+extern char *_sys_errlist[];
+extern int _sys_nerr;
#endif
--- a/lib/c/src/Makefile
+++ b/lib/c/src/Makefile
@@ -4,6 +4,7 @@
OBJ = bsearch.o \
abs.o __abs.o labs.o __labs.o llabs.o __labs.o \
+ perror.o strerror.o \
printf.o fprintf.o vfprintf.o \
fgets.o gets.of fgetc.o fputc.o getchar.o putchar.o \
fputs.o puts.o fread.o fwrite.o \
--- /dev/null
+++ b/lib/c/src/perror.c
@@ -1,0 +1,17 @@
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#undef perror
+
+void
+perror(const char *msg)
+{
+ if (msg && *msg) {
+ fputs(msg, stderr);
+ putc(':', stderr);
+ putc(' ', stderr);
+ }
+ fputs(strerror(errno), stderr);
+ putc('\n', stderr);
+}
--- /dev/null
+++ b/lib/c/src/strerror.c
@@ -1,0 +1,13 @@
+
+#include <errno.h>
+#include <string.h>
+#undef strerror
+
+char *
+strerror(int errnum)
+{
+ if (errnum < _sys_nerr)
+ return _sys_errlist[errnum];
+ else
+ return "Unknown error";
+}