summaryrefslogtreecommitdiff
path: root/src/user/lib/stdio
diff options
context:
space:
mode:
authordzwdz2023-06-17 23:41:41 +0200
committerdzwdz2023-06-17 23:41:41 +0200
commit895138e65b90c3f20712b9c31690d84a6aa956ac (patch)
treec3a840f5e41ffdc0fc7725eb839f502f55b01b64 /src/user/lib/stdio
parentb528a54a708c4cd2149c8e6884af2063c2b272cd (diff)
libc: implement dirent.h
Diffstat (limited to 'src/user/lib/stdio')
-rw-r--r--src/user/lib/stdio/file.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/user/lib/stdio/file.c b/src/user/lib/stdio/file.c
index cbacfdd..9a6e555 100644
--- a/src/user/lib/stdio/file.c
+++ b/src/user/lib/stdio/file.c
@@ -155,8 +155,9 @@ size_t fread(void *restrict ptr, size_t size, size_t nitems, FILE *restrict f) {
errno = EBADF;
return 0;
}
- if (size == 0)
+ if (size == 0) {
return 0;
+ }
while (pos < total) {
long res = _sys_read(f->fd, buf + pos, total - pos, f->pos);
@@ -207,6 +208,7 @@ int fputs(const char *s, FILE *f) {
return fprintf(f, "%s\n", s);
}
+// TODO! c file buffering
char *fgets(char *buf, int size, FILE *f) {
char c = '\0';
long pos = 0;
@@ -221,7 +223,8 @@ char *fgets(char *buf, int size, FILE *f) {
int fgetc(FILE *f) {
char c;
- return fread(&c, 1, 1, f) ? c : EOF;
+ size_t ret = fread(&c, 1, 1, f);
+ return ret ? c : EOF;
}
int getc(FILE *f) { return fgetc(f); }