diff options
Diffstat (limited to 'userland/libc/stdio')
-rw-r--r-- | userland/libc/stdio/stdin.c | 27 |
1 files changed, 4 insertions, 23 deletions
diff --git a/userland/libc/stdio/stdin.c b/userland/libc/stdio/stdin.c index bc5c6f2..fcfc71e 100644 --- a/userland/libc/stdio/stdin.c +++ b/userland/libc/stdio/stdin.c @@ -5,12 +5,11 @@ #include <unistd.h> size_t raw_write_fd(FILE *f, const unsigned char *s, size_t l) { - int rc = pwrite(f->fd, (char *)s, l, f->offset_in_file); + int rc = write(f->fd, (char *)s, l); if (rc == -1) { f->has_error = 1; return 0; } - f->offset_in_file += rc; return rc; } @@ -36,7 +35,7 @@ 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 = pread(f->fd, s, l, f->offset_in_file); + int rc = read(f->fd, s, l); if (rc == 0) f->is_eof = 1; if (rc == -1) { @@ -57,9 +56,7 @@ size_t read_fd(FILE *f, unsigned char *s, size_t l) { // Invalidate the cache f->read_buffer_stored = 0; - size_t rc = non_cache_read_fd(f, s, l); - f->offset_in_file += rc; - return rc; + return non_cache_read_fd(f, s, l); } if (!f->read_buffer) { @@ -69,7 +66,6 @@ size_t read_fd(FILE *f, unsigned char *s, size_t l) { } if (f->read_buffer_stored > 0) { size_t read_len = min(l, f->read_buffer_stored); - f->offset_in_file += read_len; memcpy(s, f->read_buffer + f->read_buffer_has_read, read_len); f->read_buffer_stored -= read_len; f->read_buffer_has_read += read_len; @@ -91,20 +87,5 @@ size_t read_fd(FILE *f, unsigned char *s, size_t l) { int seek_fd(FILE *stream, long offset, int whence) { stream->read_buffer_stored = 0; - switch (whence) { - case SEEK_SET: - stream->offset_in_file = offset; - break; - case SEEK_CUR: - stream->offset_in_file += offset; - break; - case SEEK_END: - stream->offset_in_file = stream->file_size + offset; - break; - default: - assert(0); - break; - } - // FIXME: Error checking - return 0; + return lseek(stream->fd, offset, whence); } |