From 3682a560629f8db63412749397b87b91521205e4 Mon Sep 17 00:00:00 2001 From: TuxSH Date: Wed, 9 May 2018 00:53:13 +0200 Subject: [PATCH] O_RDONLY is 0 --- fusee/fusee-secondary/src/fs_dev.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fusee/fusee-secondary/src/fs_dev.c b/fusee/fusee-secondary/src/fs_dev.c index 58f1628a0..071a35d95 100644 --- a/fusee/fusee-secondary/src/fs_dev.c +++ b/fusee/fusee-secondary/src/fs_dev.c @@ -311,24 +311,29 @@ static int fsdev_open(struct _reent *r, void *fileStruct, const char *path, int { O_CREAT , FA_OPEN_ALWAYS }, { O_EXCL , FA_CREATE_NEW }, { O_TRUNC , FA_CREATE_ALWAYS }, - { O_RDONLY, FA_READ }, + /*{ O_RDONLY, FA_READ }, O_RDONLY is 0*/ { O_WRONLY, FA_WRITE }, { O_RDWR , FA_READ | FA_WRITE }, }; - if ((flags & O_RDONLY & O_WRONLY) || ((flags & O_RDWR) & (O_RDONLY | O_WRONLY))) { + if ((flags & O_RDWR) & (O_RDONLY | O_WRONLY)) { r->_errno = EINVAL; return -1; } - if (flags & O_RDONLY & O_APPEND) { + if ((flags & O_APPEND) && (flags & O_ACCMODE) == O_RDONLY) { r->_errno = EINVAL; return -1; } + for (size_t i = 0; i < sizeof(flag_mappings)/sizeof(flag_mappings[0]); i++) { if (flags & flag_mappings[i].posix_flag) { ff_flags |= flag_mappings[i].ff_flag; } } + if ((flags & O_ACCMODE) == O_RDONLY) { + ff_flags |= FA_READ; + } + /* Normalize O_CREAT|O_TRUNC */ if ((ff_flags & (FA_CREATE_ALWAYS | FA_OPEN_ALWAYS)) == (FA_CREATE_ALWAYS | FA_OPEN_ALWAYS)) { ff_flags &= ~FA_OPEN_ALWAYS;