diff options
author | Pixel <pixel@nobis-crew.org> | 2011-02-05 13:43:35 -0800 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2011-02-05 13:43:35 -0800 |
commit | ab16fcf76e616dfa7cac2cb3dd909ba2a8eb2a9f (patch) | |
tree | 5f93ecc452d648bbd84ffeda38ee5a0247e37dcc /libc/include | |
parent | 8361bc28f9215a07e2275f55561408d1bfca112f (diff) |
Slightly better errno support.
Diffstat (limited to 'libc/include')
-rw-r--r-- | libc/include/reent.h | 6 | ||||
-rw-r--r-- | libc/include/stdio.h | 16 |
2 files changed, 10 insertions, 12 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; } |