diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/user/vfs.c | 4 | ||||
-rw-r--r-- | src/lib/include/stdio.h | 2 | ||||
-rw-r--r-- | src/sysbin/shell/main.c | 5 |
3 files changed, 8 insertions, 3 deletions
diff --git a/src/kernel/user/vfs.c b/src/kernel/user/vfs.c index fa226f8..0cb7f3f 100644 --- a/src/kernel/user/vfs.c +++ b/src/kernel/user/vfs.c @@ -497,6 +497,8 @@ void unref_file(fs_handle_t *file) { } size_t file_read(fs_handle_t *f, size_t offset, size_t len, char* buf) { + if (len == 0) return 0; + if (!(f->mode & FM_READ)) return 0; if (f->node->ops->read == 0) return 0; @@ -505,6 +507,8 @@ size_t file_read(fs_handle_t *f, size_t offset, size_t len, char* buf) { } size_t file_write(fs_handle_t *f, size_t offset, size_t len, const char* buf) { + if (len == 0) return 0; + if (!(f->mode & FM_WRITE)) return 0; if (f->node->ops->write == 0) return 0; diff --git a/src/lib/include/stdio.h b/src/lib/include/stdio.h index 4b300da..b51bee4 100644 --- a/src/lib/include/stdio.h +++ b/src/lib/include/stdio.h @@ -4,6 +4,8 @@ #include <stdarg.h> #include <stdint.h> +extern fd_t stdio; + void putchar(int c); void puts(char* s); void printf(char* arg, ...); diff --git a/src/sysbin/shell/main.c b/src/sysbin/shell/main.c index 2eb2c6c..b093430 100644 --- a/src/sysbin/shell/main.c +++ b/src/sysbin/shell/main.c @@ -33,8 +33,7 @@ void cat(char* file) { while (true) { size_t r = read(f, p, 128, buf); p += r; - buf[r] = 0; - puts(buf); + write(stdio, 0, r, buf); if (r < 128) break; } close(f); @@ -46,7 +45,7 @@ void cat(char* file) { int main(int argc, char **argv) { dbg_printf("[shell] Starting\n"); - fctl(1, FC_SET_BLOCKING, 0); + fctl(stdio, FC_SET_BLOCKING, 0); puts("Kogata shell.\n"); |