diff options
Diffstat (limited to 'lib/libc/stdio')
| -rw-r--r-- | lib/libc/stdio/fdopen.c | 14 | ||||
| -rw-r--r-- | lib/libc/stdio/fmemopen.c | 7 | ||||
| -rw-r--r-- | lib/libc/stdio/fopen.c | 16 | ||||
| -rw-r--r-- | lib/libc/stdio/stdin.c | 8 | ||||
| -rw-r--r-- | lib/libc/stdio/stdout.c | 5 |
5 files changed, 24 insertions, 26 deletions
diff --git a/lib/libc/stdio/fdopen.c b/lib/libc/stdio/fdopen.c index c5db3854..bded5f27 100644 --- a/lib/libc/stdio/fdopen.c +++ b/lib/libc/stdio/fdopen.c @@ -1,10 +1,7 @@ -#include "__stdio.h" // for __FILE, __libc_fadd -#include "features.h" // for __weak -#include "stdatomic.h" // for atomic_flag_clear -#include "stddef.h" // for NULL - -#include <stdio.h> // for FILE, _IONBF, SEEK_END, _IOLBF, fdopen -#include <stdlib.h> // for calloc, free +#include "__stdio.h" // for __FILE, __libc_fadd +#include <stdio.h> // for FILE, _IONBF, SEEK_END, _IOLBF, fdopen +#include <stdlib.h> // for calloc, free +#include <sys/cdefs.h> #include <unistd.h> // for lseek, off_t __weak void __stdio_cleanup(void) @@ -15,8 +12,7 @@ FILE *fdopen(int fildes, const char *mode) { FILE *stream; - if (mode == NULL || - (mode[0] != 'r' && mode[0] != 'w' && mode[0] != 'a')) { + if (mode == NULL || (mode[0] != 'r' && mode[0] != 'w' && mode[0] != 'a')) { return NULL; } diff --git a/lib/libc/stdio/fmemopen.c b/lib/libc/stdio/fmemopen.c index 920484b3..e1b2ccff 100644 --- a/lib/libc/stdio/fmemopen.c +++ b/lib/libc/stdio/fmemopen.c @@ -1,6 +1,5 @@ -#include "__stdio.h" // for __FILE, __libc_fadd -#include "features.h" // for __weak -#include "stddef.h" // for NULL +#include "__stdio.h" // for __FILE, __libc_fadd +#include "stddef.h" // for NULL #include <errno.h> // for EINVAL, errno #include <fcntl.h> // for O_WRONLY, O_CREAT, O_RDONLY, O_APPEND, O_RDWR @@ -8,6 +7,8 @@ #include <stdlib.h> // for calloc, free #include <string.h> // for strchr +#include <sys/cdefs.h> + __weak void __stdio_cleanup(void) { } diff --git a/lib/libc/stdio/fopen.c b/lib/libc/stdio/fopen.c index bef21f46..5415e711 100644 --- a/lib/libc/stdio/fopen.c +++ b/lib/libc/stdio/fopen.c @@ -1,13 +1,11 @@ -#include "__stdio.h" // for __FILE, __libc_fadd -#include "features.h" // for __weak -#include "stdatomic.h" // for atomic_flag_clear -#include "stddef.h" // for NULL +#include <__stdio.h> #include <errno.h> // for EINVAL, errno #include <fcntl.h> // for O_WRONLY, O_CREAT, O_RDONLY, open, O_APPEND #include <stdio.h> // for FILE, BUFSIZ, fopen, _IOLBF #include <stdlib.h> // for calloc, free, malloc #include <string.h> // for strchr +#include <sys/cdefs.h> #include <unistd.h> // for close __weak void __stdio_cleanup(void) @@ -36,10 +34,12 @@ FILE *fopen(const char *restrict pathname, const char *restrict mode) flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR; } - if ((fd = open(pathname, flags, _mode)) < 0) + fd = open(pathname, flags, _mode); + if (fd < 0) return NULL; - if ((stream = calloc(1, sizeof(FILE))) == NULL) + stream = calloc(1, sizeof(struct __FILE)); + if (stream == NULL) return NULL; __FILE(stream)->fd = fd; @@ -48,7 +48,9 @@ FILE *fopen(const char *restrict pathname, const char *restrict mode) __FILE(stream)->type = _IOLBF; atomic_flag_clear(&__FILE(stream)->lock); - if ((__FILE(stream)->buf = malloc(BUFSIZ)) == NULL) { + __FILE(stream)->buf = malloc(BUFSIZ); + + if (__FILE(stream)->buf == NULL) { close(fd); free(stream); return NULL; diff --git a/lib/libc/stdio/stdin.c b/lib/libc/stdio/stdin.c index 45d42e27..0d127efa 100644 --- a/lib/libc/stdio/stdin.c +++ b/lib/libc/stdio/stdin.c @@ -1,8 +1,8 @@ -#include "__stdio.h" // for __FILE -#include "features.h" // for __weak +#include "__stdio.h" // for __FILE -#include <fcntl.h> // for O_RDONLY -#include <stdio.h> // for FILE, stdin +#include <fcntl.h> // for O_RDONLY +#include <stdio.h> // for FILE, stdin +#include <sys/cdefs.h> #include <unistd.h> // for STDOUT_FILENO #define BUFSIZ 4096 diff --git a/lib/libc/stdio/stdout.c b/lib/libc/stdio/stdout.c index 14637368..471a54b9 100644 --- a/lib/libc/stdio/stdout.c +++ b/lib/libc/stdio/stdout.c @@ -1,11 +1,10 @@ -#include "__stdio.h" // for __FILE, __libc_fadd -#include "features.h" // for __weak -#include "stdatomic.h" // for ATOMIC_FLAG_INIT, atomic_flag +#include "__stdio.h" // for __FILE, __libc_fadd #include <atomic.h> // for LIBC_LOCK, LIBC_UNLOCK #include <fcntl.h> // for O_WRONLY #include <stddef.h> // for NULL #include <stdio.h> // for stdout +#include <sys/cdefs.h> #include <unistd.h> // for STDOUT_FILENO #define BUFSIZ 4096 |
