summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libc/include/reent.h6
-rw-r--r--libc/include/stdio.h16
-rw-r--r--libc/src/close.c2
-rw-r--r--libc/src/lseek.c6
-rw-r--r--libc/src/open.c2
-rw-r--r--[-rwxr-xr-x]libc/src/qsort.c0
-rw-r--r--libc/src/read.c4
-rw-r--r--libc/src/write.c4
-rw-r--r--[-rwxr-xr-x]libc/src/xscanf.c0
-rw-r--r--os/src/sbrk.c2
10 files changed, 20 insertions, 22 deletions
diff --git a/libc/include/reent.h b/libc/include/reent.h
index c3633ee..ddd19d3 100644
--- a/libc/include/reent.h
+++ b/libc/include/reent.h
@@ -7,10 +7,8 @@ struct _reent {
enum errno_t _errno;
};
-static inline void _REENT_INIT_PTR(struct _reent * reent) {
- reent->_errno = ENOERROR;
-}
-
+static inline void _REENT_INIT_PTR(struct _reent * reent) { reent->_errno = ENOERROR; }
extern struct _reent * _impure_ptr;
+static inline void set_errno(enum errno_t _errno) { _impure_ptr->_errno = errno = _errno; }
#endif
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index a2655ea..9a8b491 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -57,7 +57,7 @@ static inline FILE * fopen(const char * fname, const char * mode) {
FILE * r = NULL;
int flags = 0, plus = 0, append = 0, fd;
if (!mode || !mode[0]) {
- _impure_ptr->_errno = EINVAL;
+ set_errno(EINVAL);
return NULL;
}
@@ -65,7 +65,7 @@ static inline FILE * fopen(const char * fname, const char * mode) {
plus = mode[2] == '+';
} else if (mode[1]) {
if (mode[1] != '+') {
- _impure_ptr->_errno = EINVAL;
+ set_errno(EINVAL);
return NULL;
}
plus = 1;
@@ -95,7 +95,7 @@ static inline FILE * fopen(const char * fname, const char * mode) {
}
break;
default:
- _impure_ptr->_errno = EINVAL;
+ set_errno(EINVAL);
return NULL;
}
@@ -114,7 +114,7 @@ static inline int fclose(FILE * stream) {
int fd;
if (!stream) {
- _impure_ptr->_errno = EINVAL;
+ set_errno(EINVAL);
return -1;
}
@@ -131,7 +131,7 @@ static inline size_t fread(void * _ptr, size_t size, size_t nmemb, FILE * stream
size_t r;
if (!stream) {
- _impure_ptr->_errno = EINVAL;
+ set_errno(EINVAL);
return -1;
}
@@ -164,7 +164,7 @@ static inline size_t fwrite(const void * _ptr, size_t size, size_t nmemb, FILE *
const uint8_t * ptr = (const uint8_t *) _ptr;
if (!stream) {
- _impure_ptr->_errno = EINVAL;
+ set_errno(EINVAL);
return -1;
}
@@ -186,7 +186,7 @@ static inline int fgetc(FILE * stream) {
uint8_t v;
if (!stream) {
- _impure_ptr->_errno = EINVAL;
+ set_errno(EINVAL);
return -1;
}
@@ -200,7 +200,7 @@ static inline int fgetc(FILE * stream) {
static inline int fseek(FILE * stream, off_t offset, int wheel) {
int r;
if (!stream) {
- _impure_ptr->_errno = EINVAL;
+ set_errno(EINVAL);
return -1;
}
diff --git a/libc/src/close.c b/libc/src/close.c
index fd4256f..f508a2c 100644
--- a/libc/src/close.c
+++ b/libc/src/close.c
@@ -4,7 +4,7 @@
int close(int fd) {
if (!fio_is_open(fd)) {
- _impure_ptr->_errno = EBADF;
+ set_errno(EBADF);
return -1;
}
diff --git a/libc/src/lseek.c b/libc/src/lseek.c
index bffc81f..1d36c90 100644
--- a/libc/src/lseek.c
+++ b/libc/src/lseek.c
@@ -6,19 +6,19 @@ off_t lseek(int fd, off_t seek, int wheel) {
off_t r;
if ((wheel != SEEK_SET) && (wheel != SEEK_CUR) && (wheel != SEEK_END)) {
- _impure_ptr->_errno = EINVAL;
+ set_errno(EINVAL);
return -1;
}
if (!fio_is_open(fd)) {
- _impure_ptr->_errno = EBADF;
+ set_errno(EBADF);
return -1;
}
r = fio_seek(fd, seek, wheel);
if (r < 0)
- _impure_ptr->_errno = EINVAL;
+ set_errno(EINVAL);
return r;
}
diff --git a/libc/src/open.c b/libc/src/open.c
index 71a96d1..78d40be 100644
--- a/libc/src/open.c
+++ b/libc/src/open.c
@@ -12,6 +12,6 @@ int open(const char * path, int flags) {
if (r >= 0)
return r;
- _impure_ptr->_errno = EACCES;
+ set_errno(EACCES);
return -1;
}
diff --git a/libc/src/qsort.c b/libc/src/qsort.c
index eeb038b..eeb038b 100755..100644
--- a/libc/src/qsort.c
+++ b/libc/src/qsort.c
diff --git a/libc/src/read.c b/libc/src/read.c
index aeea537..dcc03e8 100644
--- a/libc/src/read.c
+++ b/libc/src/read.c
@@ -6,14 +6,14 @@ ssize_t read(int fd, void * buf, size_t size) {
ssize_t r;
if (!fio_is_open(fd)) {
- _impure_ptr->_errno = EBADF;
+ set_errno(EBADF);
return -1;
}
r = fio_read(fd, buf, size);
if (r < 0) {
- _impure_ptr->_errno = EINVAL;
+ set_errno(EINVAL);
return -1;
}
diff --git a/libc/src/write.c b/libc/src/write.c
index e44806c..52b1457 100644
--- a/libc/src/write.c
+++ b/libc/src/write.c
@@ -6,14 +6,14 @@ ssize_t write(int fd, const void * buf, size_t size) {
ssize_t r;
if (!fio_is_open(fd)) {
- _impure_ptr->_errno = EBADF;
+ set_errno(EBADF);
return -1;
}
r = fio_write(fd, buf, size);
if (r < 0) {
- _impure_ptr->_errno = EINVAL;
+ set_errno(EINVAL);
return -1;
}
diff --git a/libc/src/xscanf.c b/libc/src/xscanf.c
index d121722..d121722 100755..100644
--- a/libc/src/xscanf.c
+++ b/libc/src/xscanf.c
diff --git a/os/src/sbrk.c b/os/src/sbrk.c
index fcb6b7a..e831d38 100644
--- a/os/src/sbrk.c
+++ b/os/src/sbrk.c
@@ -25,7 +25,7 @@ void * sbrk(ptrdiff_t incr) {
/* Check if this allocation would exceed the end of the ram - would probably get into the stack first however */
if (next_heap_end > stack_min) {
- _impure_ptr->_errno = ENOMEM;
+ set_errno(ENOMEM);
ret = NULL;
} else {
heap_end = next_heap_end;