summaryrefslogtreecommitdiff
path: root/userland/libc/stdio
diff options
context:
space:
mode:
Diffstat (limited to 'userland/libc/stdio')
-rw-r--r--userland/libc/stdio/fgetc.c1
-rw-r--r--userland/libc/stdio/fseek.c21
-rw-r--r--userland/libc/stdio/ftell.c2
-rw-r--r--userland/libc/stdio/stdin.c3
-rw-r--r--userland/libc/stdio/ungetc.c1
5 files changed, 10 insertions, 18 deletions
diff --git a/userland/libc/stdio/fgetc.c b/userland/libc/stdio/fgetc.c
index c69211f..afa299f 100644
--- a/userland/libc/stdio/fgetc.c
+++ b/userland/libc/stdio/fgetc.c
@@ -4,6 +4,7 @@
int fgetc(FILE *stream) {
if (stream->has_buffered_char) {
stream->has_buffered_char = 0;
+ fseek(stream, 1, SEEK_CUR);
return stream->buffered_char;
}
char c;
diff --git a/userland/libc/stdio/fseek.c b/userland/libc/stdio/fseek.c
index fb891ec..cbccbb8 100644
--- a/userland/libc/stdio/fseek.c
+++ b/userland/libc/stdio/fseek.c
@@ -1,21 +1,8 @@
-#include <stdio.h>
#include <assert.h>
+#include <stdio.h>
int fseek(FILE *stream, long offset, int whence) {
- return stream->seek(stream, offset, whence);
- /*
- switch (whence) {
- case SEEK_SET:
- stream->offset_in_file = offset;
- break;
- case SEEK_CUR:
- stream->offset_in_file += offset;
- break;
- case SEEK_END:
- // FIXME
- assert(0);
- break;
- }
- // FIXME: Error checking
- return 0;*/
+ stream->read_buffer_stored = 0;
+ assert(stream->seek);
+ return stream->seek(stream, offset, whence);
}
diff --git a/userland/libc/stdio/ftell.c b/userland/libc/stdio/ftell.c
index 35076d0..1729d74 100644
--- a/userland/libc/stdio/ftell.c
+++ b/userland/libc/stdio/ftell.c
@@ -1,5 +1,5 @@
#include <stdio.h>
long ftell(FILE *stream) {
- return stream->offset_in_file;
+ return fseek(stream, 0, SEEK_CUR);
}
diff --git a/userland/libc/stdio/stdin.c b/userland/libc/stdio/stdin.c
index fcfc71e..e497167 100644
--- a/userland/libc/stdio/stdin.c
+++ b/userland/libc/stdio/stdin.c
@@ -71,10 +71,13 @@ size_t read_fd(FILE *f, unsigned char *s, size_t l) {
f->read_buffer_has_read += read_len;
s += read_len;
l -= read_len;
+ lseek(f->fd, read_len, SEEK_CUR);
return read_len + read_fd(f, s, l);
}
if (0 == f->read_buffer_stored) {
+ int offset = lseek(f->fd, 0, SEEK_CUR);
f->read_buffer_stored = non_cache_read_fd(f, f->read_buffer, 4096);
+ lseek(f->fd, offset, SEEK_SET);
f->read_buffer_has_read = 0;
if (0 == f->read_buffer_stored) {
return 0;
diff --git a/userland/libc/stdio/ungetc.c b/userland/libc/stdio/ungetc.c
index 8d649bc..3b93b70 100644
--- a/userland/libc/stdio/ungetc.c
+++ b/userland/libc/stdio/ungetc.c
@@ -5,5 +5,6 @@ int ungetc(int c, FILE *stream) {
return EOF;
stream->buffered_char = c;
stream->has_buffered_char = 1;
+ fseek(stream, -1, SEEK_CUR);
return c;
}