From 4850e01e14373d9808b78f3fb7833e26583744c1 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 24 Jul 2019 14:59:48 -0500 Subject: [PATCH] Changed rdonly/wronly mistakes to assert Previously these returned LFS_ERR_BADF. But attempting to modify a file opened read-only, or reading a write-only flie, is a user error and should not occur in normal use. Changing this to an assert allows the logic to be omitted if the user disables asserts to reduce the code footprint (not suggested unless the user really really knows what they're doing). --- lfs.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/lfs.c b/lfs.c index a535295..dd63677 100644 --- a/lfs.c +++ b/lfs.c @@ -2631,10 +2631,7 @@ lfs_ssize_t lfs_file_read(lfs_t *lfs, lfs_file_t *file, lfs_size_t nsize = size; LFS_ASSERT(file->flags & LFS_F_OPENED); - - if ((file->flags & 3) == LFS_O_WRONLY) { - return LFS_ERR_BADF; - } + LFS_ASSERT((file->flags & 3) != LFS_O_WRONLY); if (file->flags & LFS_F_WRITING) { // flush out any writes @@ -2706,10 +2703,7 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, lfs_size_t nsize = size; LFS_ASSERT(file->flags & LFS_F_OPENED); - - if ((file->flags & 3) == LFS_O_RDONLY) { - return LFS_ERR_BADF; - } + LFS_ASSERT((file->flags & 3) != LFS_O_RDONLY); if (file->flags & LFS_F_READING) { // drop any reads @@ -2857,10 +2851,7 @@ lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file, int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { LFS_ASSERT(file->flags & LFS_F_OPENED); - - if ((file->flags & 3) == LFS_O_RDONLY) { - return LFS_ERR_BADF; - } + LFS_ASSERT((file->flags & 3) != LFS_O_RDONLY); if (size > LFS_FILE_MAX) { return LFS_ERR_INVAL;