summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2018-01-05 01:58:08 +0100
committerRichard Braun <rbraun@sceen.net>2018-01-05 01:58:26 +0100
commit62d27d872769ebcd79a931fa07b1128576e65e65 (patch)
tree0a99e87809c9055dcdcfbd9ed4bec1a72534ced9 /src
parenta6c056ce150bd0339d5325edc18717b2d02a5b8d (diff)
error: remove and use standard errno codes instead
This change also adds strerror to string.h.
Diffstat (limited to 'src')
-rw-r--r--src/cpu.c1
-rw-r--r--src/error.c67
-rw-r--r--src/error.h50
-rw-r--r--src/i8259.c4
-rw-r--r--src/mutex.c4
-rw-r--r--src/mutex.h2
-rw-r--r--src/string.c24
-rw-r--r--src/thread.c6
-rw-r--r--src/uart.c4
-rw-r--r--src/uart.h2
10 files changed, 35 insertions, 129 deletions
diff --git a/src/cpu.c b/src/cpu.c
index c336c5e..3e00d61 100644
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -33,7 +33,6 @@
#include <lib/macros.h>
#include "cpu.h"
-#include "error.h"
#include "i8259.h"
#include "thread.h"
diff --git a/src/error.c b/src/error.c
deleted file mode 100644
index 8bd7875..0000000
--- a/src/error.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2017 Richard Braun.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <lib/macros.h>
-
-#include "error.h"
-#include "panic.h"
-
-/*
- * Error message table.
- *
- * This table must be consistent with the enum defined in error.h.
- */
-static const char *error_msg_table[] = {
- "success",
- "invalid argument",
- "resource temporarily unavailable",
- "not enough space",
- "input/output error",
- "resource busy",
- "entry exist",
-};
-
-const char *
-error_str(unsigned int error)
-{
- if (error >= ARRAY_SIZE(error_msg_table)) {
- return "invalid error code";
- }
-
- return error_msg_table[error];
-}
-
-void
-error_check(int error, const char *prefix)
-{
- if (!error) {
- return;
- }
-
- panic("%s%s%s",
- (prefix == NULL) ? "" : prefix,
- (prefix == NULL) ? "" : ": ",
- error_str(error));
-}
diff --git a/src/error.h b/src/error.h
deleted file mode 100644
index fca3980..0000000
--- a/src/error.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2017 Richard Braun.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef _ERROR_H
-#define _ERROR_H
-
-enum {
- ERROR_INVAL = 1,
- ERROR_AGAIN,
- ERROR_NOMEM,
- ERROR_IO,
- ERROR_BUSY,
- ERROR_EXIST,
-};
-
-/*
- * Return the message matching the given error.
- *
- * The returned address points to a statically allocated, read only,
- * null-terminated string literal. The caller must not attempt to use it
- * for anything else than error reporting.
- */
-const char * error_str(unsigned int error);
-
-/*
- * If error denotes an actual error (i.e. is not 0), panic, using the given
- * string as a prefix for the error message. A NULL prefix is allowed.
- */
-void error_check(int error, const char *prefix);
-
-#endif /* _ERROR_H */
diff --git a/src/i8259.c b/src/i8259.c
index 589e13c..aed7068 100644
--- a/src/i8259.c
+++ b/src/i8259.c
@@ -38,6 +38,7 @@
*/
#include <assert.h>
+#include <errno.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
@@ -45,7 +46,6 @@
#include <lib/macros.h>
#include "cpu.h"
-#include "error.h"
#include "i8259.h"
#include "io.h"
@@ -131,7 +131,7 @@ i8259_convert_global_irq(unsigned int irq, struct i8259_pic **pic,
error = 0;
} else {
*local_irq = 0;
- error = ERROR_INVAL;
+ error = EINVAL;
}
return error;
diff --git a/src/mutex.c b/src/mutex.c
index d70bd82..336f192 100644
--- a/src/mutex.c
+++ b/src/mutex.c
@@ -21,13 +21,13 @@
*/
#include <assert.h>
+#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include <lib/list.h>
#include <lib/macros.h>
-#include "error.h"
#include "mutex.h"
#include "thread.h"
@@ -122,7 +122,7 @@ mutex_trylock(struct mutex *mutex)
thread_preempt_disable();
if (mutex->locked) {
- error = ERROR_BUSY;
+ error = EBUSY;
} else {
error = 0;
mutex_set_owner(mutex, thread_self());
diff --git a/src/mutex.h b/src/mutex.h
index c158d5e..fedbb8f 100644
--- a/src/mutex.h
+++ b/src/mutex.h
@@ -151,7 +151,7 @@ void mutex_lock(struct mutex *mutex);
*
* This is the non-blocking variant of mutex_lock().
*
- * Return 0 on success, ERROR_BUSY if locking the mutex failed.
+ * Return 0 on success, EBUSY if locking the mutex failed.
*/
int mutex_trylock(struct mutex *mutex);
diff --git a/src/string.c b/src/string.c
index 210b2bc..dbdb234 100644
--- a/src/string.c
+++ b/src/string.c
@@ -20,6 +20,7 @@
* DEALINGS IN THE SOFTWARE.
*/
+#include <errno.h>
#include <stddef.h>
#include <string.h>
@@ -141,3 +142,26 @@ strncmp(const char *s1, const char *s2, size_t n)
return (int)c1 - (int)c2;
}
+
+char *
+strerror(int errnum)
+{
+ switch (errnum) {
+ case 0:
+ return "success";
+ case EINVAL:
+ return "invalid argument";
+ case EAGAIN:
+ return "resource temporarily unavailable";
+ case ENOMEM:
+ return "not enough space";
+ case EIO:
+ return "input/output error";
+ case EBUSY:
+ return "resource busy";
+ case EEXIST:
+ return "entry exist";
+ default:
+ return "unknown error";
+ }
+}
diff --git a/src/thread.c b/src/thread.c
index 0d63be8..70f036e 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -22,6 +22,7 @@
*/
#include <assert.h>
+#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@@ -32,7 +33,6 @@
#include <lib/list.h>
#include "cpu.h"
-#include "error.h"
#include "panic.h"
#include "thread.h"
#include "timer.h"
@@ -675,7 +675,7 @@ thread_create(struct thread **threadp, thread_fn_t fn, void *arg,
thread = malloc(sizeof(*thread));
if (!thread) {
- return ERROR_NOMEM;
+ return ENOMEM;
}
if (stack_size < THREAD_STACK_MIN_SIZE) {
@@ -686,7 +686,7 @@ thread_create(struct thread **threadp, thread_fn_t fn, void *arg,
if (!stack) {
free(thread);
- return ERROR_NOMEM;
+ return ENOMEM;
}
thread_init(thread, fn, arg, name, stack, stack_size, priority);
diff --git a/src/uart.c b/src/uart.c
index eed7fe4..8697874 100644
--- a/src/uart.c
+++ b/src/uart.c
@@ -22,6 +22,7 @@
*/
#include <assert.h>
+#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@@ -31,7 +32,6 @@
#include <lib/macros.h>
#include "cpu.h"
-#include "error.h"
#include "io.h"
#include "uart.h"
#include "thread.h"
@@ -164,7 +164,7 @@ uart_read(uint8_t *byte)
eflags = cpu_intr_save();
if (uart_waiter) {
- error = ERROR_BUSY;
+ error = EBUSY;
goto out;
}
diff --git a/src/uart.h b/src/uart.h
index 0dd2864..c3b91db 100644
--- a/src/uart.h
+++ b/src/uart.h
@@ -52,7 +52,7 @@ void uart_write(uint8_t byte);
* until there is data to consume.
*
* If successful, return 0. If another thread is already waiting for data,
- * ERROR_BUSY is returned.
+ * EBUSY is returned.
*
* Preemption must be enabled when calling this function.
*/