commit abe6c3c28a0281b373311c19b4e1512e398d5cb2
parent afe346d11a411bb48c5637e950a05094d1002584
Author: Roberto Vargas <roberto.vargas@arm.com>
Date: Fri, 23 Nov 2018 17:30:51 +0000
[libk] Add kerror()
This function is equivalent to perror() but it reallocates
the string returned by strerror().
Change-Id: Ib95f0a8d59b454071fdc26c9a03f18587932d508
Diffstat:
4 files changed, 15 insertions(+), 40 deletions(-)
diff --git a/include/libk.h b/include/libk.h
@@ -10,4 +10,5 @@ extern int kgetc(void);
extern int kputc(int ch);
extern int kputs(const char *s);
extern int kvprint(const char *fmt, va_list va);
+extern void kerror(const char *s);
extern int putenv(char *name);
diff --git a/src/libc/arch/rmode/rcode/putenv.c b/src/libc/arch/rmode/rcode/putenv.c
@@ -1,40 +0,0 @@
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-extern char **_environ();
-
-int
-putenv(char *name)
-{
- char **p, **env, *s;
- size_t len;
- int *nump;
-
- if ((s = strchr(name, '=')) == NULL) {
- errno = 1;
- return -1;
- }
- len = s - name;
-
- env = _environ();
- for (p = env + 1; *p; ++p) {
- if (!strncmp(name, *p, len) && (*p)[len] == '=')
- break;
- }
-
- if (*p) {
- *p = name;
- } else {
- nump = (int *) env;
- if (*nump == 0) {
- errno = 1;
- return -1;
- }
- --*nump;
- *p++ = name;
- *p = NULL;
- }
-
- return 0;
-}
diff --git a/src/libk/Makefile b/src/libk/Makefile
@@ -10,6 +10,7 @@ OBJS = doprnt.o \
kputs.o \
kvprint.o \
kgets.o \
+ kerror.o \
putenv-$(MODE).o \
__assert.o \
diff --git a/src/libk/kerror.c b/src/libk/kerror.c
@@ -0,0 +1,13 @@
+#include <errno.h>
+#include <string.h>
+
+#include <rcode.h>
+#include <libk.h>
+
+void
+kerror(const char *s)
+{
+ char *msg = reloc(strerror(errno));
+ kprint("errno=%d,%p,%p\n", (void *) strerror(errno), (void *) reloc(strerror(errno)));
+ kprint("%s:%s\n", s, msg);
+}