From ab16fcf76e616dfa7cac2cb3dd909ba2a8eb2a9f Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 5 Feb 2011 13:43:35 -0800 Subject: Slightly better errno support. --- libc/include/reent.h | 6 ++---- libc/include/stdio.h | 16 ++++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'libc/include') 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; } -- cgit v1.2.3