summaryrefslogtreecommitdiff
path: root/userland/libc/stdio
diff options
context:
space:
mode:
Diffstat (limited to 'userland/libc/stdio')
-rw-r--r--userland/libc/stdio/feof.c2
-rw-r--r--userland/libc/stdio/ferror.c2
-rw-r--r--userland/libc/stdio/fflush.c2
-rw-r--r--userland/libc/stdio/fgetc.c9
-rw-r--r--userland/libc/stdio/fgets.c9
-rw-r--r--userland/libc/stdio/fileno.c2
-rw-r--r--userland/libc/stdio/fputc.c3
-rw-r--r--userland/libc/stdio/fputs.c6
-rw-r--r--userland/libc/stdio/fscanf.c2
-rw-r--r--userland/libc/stdio/getchar.c4
-rw-r--r--userland/libc/stdio/open_memstream.c9
-rw-r--r--userland/libc/stdio/putc.c4
-rw-r--r--userland/libc/stdio/remove.c4
-rw-r--r--userland/libc/stdio/rename.c2
-rw-r--r--userland/libc/stdio/stdin.c6
-rw-r--r--userland/libc/stdio/tmpfile.c10
-rw-r--r--userland/libc/stdio/ungetc.c3
-rw-r--r--userland/libc/stdio/vfprintf.c42
-rw-r--r--userland/libc/stdio/vprintf.c4
19 files changed, 80 insertions, 45 deletions
diff --git a/userland/libc/stdio/feof.c b/userland/libc/stdio/feof.c
index 7f46301..91e7e56 100644
--- a/userland/libc/stdio/feof.c
+++ b/userland/libc/stdio/feof.c
@@ -1,5 +1,5 @@
#include <stdio.h>
int feof(FILE *stream) {
- return stream->is_eof;
+ return stream->is_eof;
}
diff --git a/userland/libc/stdio/ferror.c b/userland/libc/stdio/ferror.c
index 8cb46cf..5049db8 100644
--- a/userland/libc/stdio/ferror.c
+++ b/userland/libc/stdio/ferror.c
@@ -1,5 +1,5 @@
#include <stdio.h>
int ferror(FILE *stream) {
- return stream->has_error;
+ return stream->has_error;
}
diff --git a/userland/libc/stdio/fflush.c b/userland/libc/stdio/fflush.c
index 1cadc72..8bfd16d 100644
--- a/userland/libc/stdio/fflush.c
+++ b/userland/libc/stdio/fflush.c
@@ -1,6 +1,6 @@
+#include <errno.h>
#include <stdio.h>
#include <syscall.h>
-#include <errno.h>
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fflush.html
int fflush(FILE *stream) {
diff --git a/userland/libc/stdio/fgetc.c b/userland/libc/stdio/fgetc.c
index afa299f..dc7af77 100644
--- a/userland/libc/stdio/fgetc.c
+++ b/userland/libc/stdio/fgetc.c
@@ -8,13 +8,16 @@ int fgetc(FILE *stream) {
return stream->buffered_char;
}
char c;
- if (1 == fread(&c, 1, 1, stream))
+ if (1 == fread(&c, 1, 1, stream)) {
return (int)c;
+ }
// FIXME: Should use feof and ferror
- if (stream->has_error)
+ if (stream->has_error) {
return EOF;
- if (stream->is_eof)
+ }
+ if (stream->is_eof) {
return EOF;
+ }
// How did we get here?
assert(0);
return EOF;
diff --git a/userland/libc/stdio/fgets.c b/userland/libc/stdio/fgets.c
index 8e21501..acc89a0 100644
--- a/userland/libc/stdio/fgets.c
+++ b/userland/libc/stdio/fgets.c
@@ -4,13 +4,16 @@ char *fgets(char *s, int n, FILE *stream) {
for (int i = 0; i < n; i++) {
char c;
fread(&c, 1, 1, stream);
- if (stream->has_error)
+ if (stream->has_error) {
return NULL;
- if (stream->is_eof)
+ }
+ if (stream->is_eof) {
return NULL;
+ }
s[i] = c;
- if (c == '\n')
+ if (c == '\n') {
break;
+ }
}
return s;
}
diff --git a/userland/libc/stdio/fileno.c b/userland/libc/stdio/fileno.c
index 246cc51..bdf9332 100644
--- a/userland/libc/stdio/fileno.c
+++ b/userland/libc/stdio/fileno.c
@@ -1,5 +1,5 @@
-#include <stdio.h>
#include <errno.h>
+#include <stdio.h>
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fileno.html
// The fileno() function shall return the integer file descriptor associated
diff --git a/userland/libc/stdio/fputc.c b/userland/libc/stdio/fputc.c
index 7c8fa7c..c41ffa4 100644
--- a/userland/libc/stdio/fputc.c
+++ b/userland/libc/stdio/fputc.c
@@ -1,7 +1,8 @@
#include <stdio.h>
int fputc(int c, FILE *stream) {
- if (fwrite(&c, 1, 1, stream) > 0)
+ if (fwrite(&c, 1, 1, stream) > 0) {
return c;
+ }
return EOF;
}
diff --git a/userland/libc/stdio/fputs.c b/userland/libc/stdio/fputs.c
index 1b70c66..5570693 100644
--- a/userland/libc/stdio/fputs.c
+++ b/userland/libc/stdio/fputs.c
@@ -2,8 +2,10 @@
int fputs(const char *s, FILE *stream) {
const char *b = s;
- for (; *s; s++)
- if (0 == fwrite(s, 1, 1, stream))
+ for (; *s; s++) {
+ if (0 == fwrite(s, 1, 1, stream)) {
return EOF;
+ }
+ }
return s - b;
}
diff --git a/userland/libc/stdio/fscanf.c b/userland/libc/stdio/fscanf.c
index 4af79f9..f8803fc 100644
--- a/userland/libc/stdio/fscanf.c
+++ b/userland/libc/stdio/fscanf.c
@@ -1,5 +1,5 @@
-#include <stdio.h>
#include <assert.h>
+#include <stdio.h>
int fscanf(FILE *stream, const char *format, ...) {
va_list ap;
diff --git a/userland/libc/stdio/getchar.c b/userland/libc/stdio/getchar.c
index dad2263..e7991cd 100644
--- a/userland/libc/stdio/getchar.c
+++ b/userland/libc/stdio/getchar.c
@@ -1,4 +1,6 @@
#include <stdio.h>
// The getchar() function shall be equivalent to getc(stdin).
-int getchar(void) { return fgetc(stdin); }
+int getchar(void) {
+ return fgetc(stdin);
+}
diff --git a/userland/libc/stdio/open_memstream.c b/userland/libc/stdio/open_memstream.c
index b129cb6..b7ea70b 100644
--- a/userland/libc/stdio/open_memstream.c
+++ b/userland/libc/stdio/open_memstream.c
@@ -35,8 +35,9 @@ size_t memstream_write(FILE *fp, const unsigned char *buf, size_t n) {
memcpy(c->buffer + fp->offset_in_file, buf, n);
fp->offset_in_file += n;
- if (fp->offset_in_file > (long)c->buffer_usage)
+ if (fp->offset_in_file > (long)c->buffer_usage) {
c->buffer_usage = fp->offset_in_file;
+ }
return n;
}
@@ -46,8 +47,9 @@ size_t memstream_read(FILE *fp, unsigned char *buf, size_t n) {
n = min(length_left, n);
memcpy(buf, c->buffer + fp->offset_in_file, n);
fp->offset_in_file += n;
- if (0 == n)
+ if (0 == n) {
fp->is_eof = 1;
+ }
return n;
}
@@ -73,8 +75,9 @@ int memstream_seek(FILE *stream, long offset, int whence) {
FILE *open_memstream(char **bufp, size_t *sizep) {
struct Memstream *c = NULL;
FILE *fp = malloc(sizeof(FILE));
- if (!fp)
+ if (!fp) {
return NULL;
+ }
fp->offset_in_file = 0;
fp->buffered_char = 0;
diff --git a/userland/libc/stdio/putc.c b/userland/libc/stdio/putc.c
index a468a95..cb89ed9 100644
--- a/userland/libc/stdio/putc.c
+++ b/userland/libc/stdio/putc.c
@@ -1,3 +1,5 @@
#include <stdio.h>
-int putc(int c, FILE *stream) { return fputc(c, stream);}
+int putc(int c, FILE *stream) {
+ return fputc(c, stream);
+}
diff --git a/userland/libc/stdio/remove.c b/userland/libc/stdio/remove.c
index 39f8af2..374be58 100644
--- a/userland/libc/stdio/remove.c
+++ b/userland/libc/stdio/remove.c
@@ -1,9 +1,9 @@
-#include <stdio.h>
#include <errno.h>
+#include <stdio.h>
extern int errno;
int remove(const char *path) {
- (void)path;
+ (void)path;
// FIXME
errno = ENAMETOOLONG;
return -1;
diff --git a/userland/libc/stdio/rename.c b/userland/libc/stdio/rename.c
index a02cacb..676fd8c 100644
--- a/userland/libc/stdio/rename.c
+++ b/userland/libc/stdio/rename.c
@@ -5,5 +5,5 @@ int rename(const char *old, const char *new) {
(void)old;
(void)new;
assert(0); // TODO: Implement
- return 0;
+ return 0;
}
diff --git a/userland/libc/stdio/stdin.c b/userland/libc/stdio/stdin.c
index e497167..4620df3 100644
--- a/userland/libc/stdio/stdin.c
+++ b/userland/libc/stdio/stdin.c
@@ -36,8 +36,9 @@ size_t write_fd(FILE *f, const unsigned char *s, size_t l) {
size_t non_cache_read_fd(FILE *f, unsigned char *s, size_t l) {
int rc = read(f->fd, s, l);
- if (rc == 0)
+ if (rc == 0) {
f->is_eof = 1;
+ }
if (rc == -1) {
f->has_error = 1;
return 0;
@@ -46,8 +47,9 @@ size_t non_cache_read_fd(FILE *f, unsigned char *s, size_t l) {
}
size_t read_fd(FILE *f, unsigned char *s, size_t l) {
- if (0 == l)
+ if (0 == l) {
return 0;
+ }
// Skip using cache if the length being requested if longer than or
// equal to the cache block size. This avoids doing a bunch of extra
diff --git a/userland/libc/stdio/tmpfile.c b/userland/libc/stdio/tmpfile.c
index cee6e0a..9d3fb92 100644
--- a/userland/libc/stdio/tmpfile.c
+++ b/userland/libc/stdio/tmpfile.c
@@ -1,9 +1,9 @@
-#include <stdio.h>
#include <assert.h>
+#include <stdio.h>
FILE *tmpfile(void) {
- // TODO
- printf("TODO: Implement tmpfile()\n");
- assert(0);
- return NULL;
+ // TODO
+ printf("TODO: Implement tmpfile()\n");
+ assert(0);
+ return NULL;
}
diff --git a/userland/libc/stdio/ungetc.c b/userland/libc/stdio/ungetc.c
index 3b93b70..18e5a21 100644
--- a/userland/libc/stdio/ungetc.c
+++ b/userland/libc/stdio/ungetc.c
@@ -1,8 +1,9 @@
#include <stdio.h>
int ungetc(int c, FILE *stream) {
- if (stream->has_buffered_char)
+ if (stream->has_buffered_char) {
return EOF;
+ }
stream->buffered_char = c;
stream->has_buffered_char = 1;
fseek(stream, -1, SEEK_CUR);
diff --git a/userland/libc/stdio/vfprintf.c b/userland/libc/stdio/vfprintf.c
index d384c1d..35a7c9a 100644
--- a/userland/libc/stdio/vfprintf.c
+++ b/userland/libc/stdio/vfprintf.c
@@ -32,8 +32,9 @@ int fprint_num(FILE *f, long long n, int base, char *char_set, int prefix,
str[i] = char_set[0];
i++;
} else {
- for (; n != 0 && i < 32; i++, n /= base)
+ for (; n != 0 && i < 32; i++, n /= base) {
str[i] = char_set[(n % base)];
+ }
}
if (is_signed) {
@@ -45,16 +46,19 @@ int fprint_num(FILE *f, long long n, int base, char *char_set, int prefix,
int orig_i = i;
if (!right_padding) {
- for (; prefix - orig_i > 0; prefix--)
+ for (; prefix - orig_i > 0; prefix--) {
FILE_WRITE(f, &t, 1, &c);
+ }
}
- for (i--; i >= 0; i--)
+ for (i--; i >= 0; i--) {
FILE_WRITE(f, &(str[i]), 1, &c);
+ }
if (right_padding) {
- for (; prefix - orig_i > 0; prefix--)
+ for (; prefix - orig_i > 0; prefix--) {
FILE_WRITE(f, &t, 1, &c);
+ }
}
return c;
}
@@ -82,16 +86,19 @@ int print_string(FILE *f, const char *s, int *rc, int prefix, int right_padding,
char t = ' ';
int c = 0;
if (!right_padding) {
- if (prefix)
+ if (prefix) {
assert(-1 == precision); // FIXME: Is this correct?
- for (; prefix - l > 0; prefix--)
+ }
+ for (; prefix - l > 0; prefix--) {
FILE_WRITE(f, &t, 1, &c);
+ }
}
int bl = precision;
for (; *s; s++, (*rc)++) {
if (precision != -1) {
- if (0 == bl)
+ if (0 == bl) {
break;
+ }
bl--;
}
int r = 0;
@@ -99,8 +106,9 @@ int print_string(FILE *f, const char *s, int *rc, int prefix, int right_padding,
}
if (right_padding) {
assert(-1 == precision); // FIXME: Is this correct?
- for (; prefix - l > 0; prefix--)
+ for (; prefix - l > 0; prefix--) {
FILE_WRITE(f, &t, 1, &c);
+ }
}
(*rc) += c;
return 0;
@@ -110,8 +118,9 @@ int parse_precision(const char **fmt) {
const char *s = *fmt;
int rc = 0;
for (int i = 0;; i++, s++) {
- if ('\0' == *s)
+ if ('\0' == *s) {
break;
+ }
const char c = *s;
if ('*' == c) {
assert(i == 0);
@@ -149,8 +158,9 @@ int vfprintf(FILE *f, const char *fmt, va_list ap) {
continue;
}
- if ('\0' == *s)
+ if ('\0' == *s) {
break;
+ }
switch (*s) {
case '.':
@@ -158,14 +168,16 @@ int vfprintf(FILE *f, const char *fmt, va_list ap) {
assert('\0' != *s);
precision = parse_precision(&s);
assert('\0' != *s);
- if (-1 == precision)
+ if (-1 == precision) {
precision = va_arg(ap, int);
+ }
cont = 1;
break;
case '0':
prefix *= 10;
- if (0 == prefix)
+ if (0 == prefix) {
zero_padding = 1;
+ }
cont = 1;
break;
case '-':
@@ -221,13 +233,15 @@ int vfprintf(FILE *f, const char *fmt, va_list ap) {
char *a = va_arg(ap, char *);
if (!a) {
if (-1 ==
- print_string(f, "(NULL)", &rc, prefix, right_padding, precision))
+ print_string(f, "(NULL)", &rc, prefix, right_padding, precision)) {
return -1;
+ }
cont = 0;
break;
}
- if (-1 == print_string(f, a, &rc, prefix, right_padding, precision))
+ if (-1 == print_string(f, a, &rc, prefix, right_padding, precision)) {
return -1;
+ }
cont = 0;
break;
}
diff --git a/userland/libc/stdio/vprintf.c b/userland/libc/stdio/vprintf.c
index 8a8dc33..c06e9f9 100644
--- a/userland/libc/stdio/vprintf.c
+++ b/userland/libc/stdio/vprintf.c
@@ -1,3 +1,5 @@
#include <stdio.h>
-int vprintf(const char *format, va_list ap) { return vdprintf(1, format, ap); }
+int vprintf(const char *format, va_list ap) {
+ return vdprintf(1, format, ap);
+}