From 680defd654d795a1a44682dcb903b2746b6ef723 Mon Sep 17 00:00:00 2001 From: pjht Date: Tue, 9 Apr 2019 09:05:47 -0500 Subject: [PATCH] VFS functions now check mode --- kernel/vfs.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/kernel/vfs.c b/kernel/vfs.c index e47b19c..0a0463c 100644 --- a/kernel/vfs.c +++ b/kernel/vfs.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "vfs.h" typedef struct _vfs_mapping_struct { char* mntpnt; @@ -126,6 +127,11 @@ FILE* fopen(const char* filename,const char* mode) { } int fgetc(FILE* stream) { + if (!stream->rd) { + errno=EBADF; + stream->error=1; + return EOF; + } int c; drvs[stream->type](FSOP_GETC,stream,&c,NULL); return c; @@ -136,6 +142,11 @@ int getc() { } char* fgets(char* str,int count,FILE* stream) { + if (!stream->rd) { + errno=EBADF; + stream->error=1; + return NULL; + } int i; for (i=0;ird) { + errno=EBADF; + stream->error=1; + return 0; + } char* buffer=(char*)buffer_ptr; size_t bytes=size*count; for (size_t i=0;iwr) { + errno=EBADF; + stream->error=1; + return EOF; + } char ok=drvs[stream->type](FSOP_PUTC,stream,&c,NULL); if (ok) { return c; @@ -179,6 +200,11 @@ int putc(int c) { } int fputs(const char* s,FILE* stream) { + if (!stream->wr) { + errno=EBADF; + stream->error=1; + return EOF; + } size_t len=strlen(s); for (size_t i=0;i