summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/cbuf.c15
-rw-r--r--lib/cbuf.h12
-rw-r--r--lib/fmt.c23
-rw-r--r--lib/shell.c32
-rw-r--r--lib/shell.h9
5 files changed, 47 insertions, 44 deletions
diff --git a/lib/cbuf.c b/lib/cbuf.c
index e405964..ecff57a 100644
--- a/lib/cbuf.c
+++ b/lib/cbuf.c
@@ -24,6 +24,7 @@
*/
#include <assert.h>
+#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
@@ -31,8 +32,6 @@
#include <lib/cbuf.h>
#include <lib/macros.h>
-#include <src/error.h>
-
/* Negative close to 0 so that an overflow occurs early */
#define CBUF_INIT_INDEX ((size_t)-500)
@@ -71,7 +70,7 @@ cbuf_push(struct cbuf *cbuf, const void *buf, size_t size, bool erase)
free_size = cbuf_capacity(cbuf) - cbuf_size(cbuf);
if (size > free_size) {
- return ERROR_AGAIN;
+ return EAGAIN;
}
}
@@ -84,7 +83,7 @@ cbuf_pop(struct cbuf *cbuf, void *buf, size_t *sizep)
__unused int error;
if (cbuf_size(cbuf) == 0) {
- return ERROR_AGAIN;
+ return EAGAIN;
}
error = cbuf_read(cbuf, cbuf_start(cbuf), buf, sizep);
@@ -102,7 +101,7 @@ cbuf_pushb(struct cbuf *cbuf, uint8_t byte, bool erase)
free_size = cbuf_capacity(cbuf) - cbuf_size(cbuf);
if (free_size == 0) {
- return ERROR_AGAIN;
+ return EAGAIN;
}
}
@@ -118,7 +117,7 @@ cbuf_popb(struct cbuf *cbuf, void *bytep)
uint8_t *ptr;
if (cbuf_size(cbuf) == 0) {
- return ERROR_AGAIN;
+ return EAGAIN;
}
ptr = bytep;
@@ -134,7 +133,7 @@ cbuf_write(struct cbuf *cbuf, size_t index, const void *buf, size_t size)
size_t new_end, skip;
if (!cbuf_range_valid(cbuf, index, cbuf->end)) {
- return ERROR_INVAL;
+ return EINVAL;
}
new_end = index + size;
@@ -175,7 +174,7 @@ cbuf_read(const struct cbuf *cbuf, size_t index, void *buf, size_t *sizep)
/* At least one byte must be available */
if (!cbuf_range_valid(cbuf, index, index + 1)) {
- return ERROR_INVAL;
+ return EINVAL;
}
size = cbuf->end - index;
diff --git a/lib/cbuf.h b/lib/cbuf.h
index eb2ec83..8b46cd4 100644
--- a/lib/cbuf.h
+++ b/lib/cbuf.h
@@ -96,7 +96,7 @@ void cbuf_init(struct cbuf *cbuf, void *buf, size_t capacity);
* Push data to a circular buffer.
*
* If the function isn't allowed to erase old data and the circular buffer
- * doesn't have enough unused bytes for the new data, ERROR_AGAIN is returned.
+ * doesn't have enough unused bytes for the new data, EAGAIN is returned.
*/
int cbuf_push(struct cbuf *cbuf, const void *buf, size_t size, bool erase);
@@ -106,7 +106,7 @@ int cbuf_push(struct cbuf *cbuf, const void *buf, size_t size, bool erase);
* On entry, the sizep argument points to the size of the output buffer.
* On exit, it is updated to the number of bytes actually transferred.
*
- * If the buffer is empty, ERROR_AGAIN is returned, and the size of the
+ * If the buffer is empty, EAGAIN is returned, and the size of the
* output buffer is undefined.
*/
int cbuf_pop(struct cbuf *cbuf, void *buf, size_t *sizep);
@@ -115,21 +115,21 @@ int cbuf_pop(struct cbuf *cbuf, void *buf, size_t *sizep);
* Push a byte to a circular buffer.
*
* If the function isn't allowed to erase old data and the circular buffer
- * is full, ERROR_AGAIN is returned.
+ * is full, EAGAIN is returned.
*/
int cbuf_pushb(struct cbuf *cbuf, uint8_t byte, bool erase);
/*
* Pop a byte from a circular buffer.
*
- * If the buffer is empty, ERROR_AGAIN is returned.
+ * If the buffer is empty, EAGAIN is returned.
*/
int cbuf_popb(struct cbuf *cbuf, void *bytep);
/*
* Write into a circular buffer at a specific location.
*
- * If the given index is outside buffer boundaries, ERROR_INVAL is returned.
+ * If the given index is outside buffer boundaries, EINVAL is returned.
* The given [index, size) range may extend beyond the end of the circular
* buffer.
*/
@@ -141,7 +141,7 @@ int cbuf_write(struct cbuf *cbuf, size_t index, const void *buf, size_t size);
* On entry, the sizep argument points to the size of the output buffer.
* On exit, it is updated to the number of bytes actually transferred.
*
- * If the given index is outside buffer boundaries, ERROR_INVAL is returned.
+ * If the given index is outside buffer boundaries, EINVAL is returned.
*
* The circular buffer isn't changed by this operation.
*/
diff --git a/lib/fmt.c b/lib/fmt.c
index 0940f24..f180606 100644
--- a/lib/fmt.c
+++ b/lib/fmt.c
@@ -24,6 +24,7 @@
*/
#include <assert.h>
+#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdarg.h>
@@ -35,8 +36,6 @@
#include <lib/fmt.h>
#include <lib/macros.h>
-#include <src/error.h>
-
/*
* XXX This type is specified by POSIX. Directly declare it for simplicity.
*/
@@ -410,12 +409,12 @@ fmt_sprintf_state_consume(struct fmt_sprintf_state *state)
c = fmt_consume(&state->format);
if (c == '\0') {
- return ERROR_IO;
+ return EIO;
}
if (c != '%') {
fmt_sprintf_state_produce_raw_char(state, c);
- return ERROR_AGAIN;
+ return EAGAIN;
}
fmt_sprintf_state_consume_flags(state);
@@ -794,7 +793,7 @@ fmt_vsnprintf(char *str, size_t size, const char *format, va_list ap)
for (;;) {
error = fmt_sprintf_state_consume(&state);
- if (error == ERROR_AGAIN) {
+ if (error == EAGAIN) {
continue;
} else if (error) {
break;
@@ -1075,7 +1074,7 @@ fmt_sscanf_state_discard_char(struct fmt_sscanf_state *state, char c)
state->nr_convs = EOF;
}
- return ERROR_INVAL;
+ return EINVAL;
}
return 0;
@@ -1092,7 +1091,7 @@ fmt_sscanf_state_consume(struct fmt_sscanf_state *state)
c = fmt_consume(&state->format);
if (c == '\0') {
- return ERROR_IO;
+ return EIO;
}
if (c != '%') {
@@ -1102,7 +1101,7 @@ fmt_sscanf_state_consume(struct fmt_sscanf_state *state)
return error;
}
- return ERROR_AGAIN;
+ return EAGAIN;
}
fmt_sscanf_state_consume_flags(state);
@@ -1194,7 +1193,7 @@ fmt_sscanf_state_produce_int(struct fmt_sscanf_state *state)
if (i == 0) {
if (c == '\0') {
fmt_sscanf_state_report_error(state);
- return ERROR_INVAL;
+ return EINVAL;
}
buf[0] = '0';
@@ -1388,7 +1387,7 @@ fmt_sscanf_state_produce_str(struct fmt_sscanf_state *state)
if (state->str == orig) {
fmt_sscanf_state_report_error(state);
- return ERROR_INVAL;
+ return EINVAL;
}
if (dest != NULL) {
@@ -1423,7 +1422,7 @@ fmt_sscanf_state_produce(struct fmt_sscanf_state *state)
return fmt_sscanf_state_discard_char(state, '%');
default:
fmt_sscanf_state_report_error(state);
- return ERROR_INVAL;
+ return EINVAL;
}
}
@@ -1451,7 +1450,7 @@ fmt_vsscanf(const char *str, const char *format, va_list ap)
for (;;) {
error = fmt_sscanf_state_consume(&state);
- if (error == ERROR_AGAIN) {
+ if (error == EAGAIN) {
continue;
} else if (error) {
break;
diff --git a/lib/shell.c b/lib/shell.c
index 8272b24..3fada36 100644
--- a/lib/shell.c
+++ b/lib/shell.c
@@ -23,6 +23,7 @@
* http://git.sceen.net/rbraun/librbraun.git/
*/
+#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
@@ -32,7 +33,6 @@
#include <lib/hash.h>
#include <lib/shell.h>
-#include <src/error.h>
#include <src/mutex.h>
#include <src/panic.h>
#include <src/thread.h>
@@ -271,8 +271,8 @@ shell_cmd_match(const struct shell_cmd *cmd, const char *str,
* eligible for completion.
*
* If there is a single match for the given string, return 0. If there
- * are more than one match, return ERROR_AGAIN. If there is no match,
- * return ERROR_INVAL.
+ * are more than one match, return EAGAIN. If there is no match,
+ * return EINVAL.
*
* The global lock must be acquired before calling this function.
*/
@@ -292,7 +292,7 @@ shell_cmd_complete(const char *str, unsigned long *sizep,
cmd = shell_cmd_match(shell_list, str, size);
if (cmd == NULL) {
- return ERROR_INVAL;
+ return EINVAL;
}
*cmdp = cmd;
@@ -337,7 +337,7 @@ shell_cmd_complete(const char *str, unsigned long *sizep,
size--;
*sizep = size;
- return ERROR_AGAIN;
+ return EAGAIN;
}
/*
@@ -383,7 +383,7 @@ shell_cmd_check_char(char c)
return 0;
}
- return ERROR_INVAL;
+ return EINVAL;
}
static int
@@ -401,7 +401,7 @@ shell_cmd_check(const struct shell_cmd *cmd)
}
if (i == 0) {
- return ERROR_INVAL;
+ return EINVAL;
}
return 0;
@@ -459,7 +459,7 @@ shell_cmd_add(struct shell_cmd *cmd)
for (;;) {
if (strcmp(cmd->name, tmp->name) == 0) {
printf("shell: error: %s: shell command name collision", cmd->name);
- return ERROR_EXIST;
+ return EEXIST;
}
if (tmp->ht_next == NULL) {
@@ -532,11 +532,11 @@ shell_line_insert(struct shell_line *line, unsigned long index, char c)
unsigned long remaining_chars;
if (index > line->size) {
- return ERROR_INVAL;
+ return EINVAL;
}
if ((line->size + 1) == sizeof(line->str)) {
- return ERROR_NOMEM;
+ return ENOMEM;
}
remaining_chars = line->size - index;
@@ -557,7 +557,7 @@ shell_line_erase(struct shell_line *line, unsigned long index)
unsigned long remaining_chars;
if (index >= line->size) {
- return ERROR_INVAL;
+ return EINVAL;
}
remaining_chars = line->size - index - 1;
@@ -777,7 +777,7 @@ static int
shell_process_right(void)
{
if (shell_cursor >= shell_line_size(shell_history_get_newest())) {
- return ERROR_AGAIN;
+ return EAGAIN;
}
shell_cursor++;
@@ -880,12 +880,12 @@ shell_process_tabulation(void)
error = shell_cmd_complete(word, &size, &cmd);
- if (error && (error != ERROR_AGAIN)) {
+ if (error && (error != EAGAIN)) {
error = 0;
goto out;
}
- if (error == ERROR_AGAIN) {
+ if (error == EAGAIN) {
unsigned long cursor;
cursor = shell_cursor;
@@ -1069,7 +1069,7 @@ shell_process_args(void)
if (j == ARRAY_SIZE(shell_argv)) {
printf("shell: too many arguments\n");
- return ERROR_INVAL;
+ return EINVAL;
}
shell_argv[j] = NULL;
@@ -1132,7 +1132,7 @@ shell_process_ctrl_char(char c)
case '\r':
putchar('\n');
shell_process_line();
- return ERROR_AGAIN;
+ return EAGAIN;
default:
return 0;
}
diff --git a/lib/shell.h b/lib/shell.h
index f66fbf7..b5ce7d5 100644
--- a/lib/shell.h
+++ b/lib/shell.h
@@ -29,11 +29,13 @@
#ifndef _SHELL_H
#define _SHELL_H
+#include <errno.h>
#include <stddef.h>
+#include <string.h>
#include <lib/macros.h>
-#include <src/error.h>
+#include <src/panic.h>
#define SHELL_REGISTER_CMDS(cmds) \
MACRO_BEGIN \
@@ -42,7 +44,10 @@ MACRO_BEGIN \
\
for (___i = 0; ___i < ARRAY_SIZE(cmds); ___i++) { \
___error = shell_cmd_register(&(cmds)[___i]); \
- error_check(___error, __func__); \
+ \
+ if (___error) { \
+ panic("%s: %s", __func__, strerror(___error)); \
+ } \
} \
MACRO_END