diff options
| author | Joey Castillo <joeycastillo@utexas.edu> | 2022-05-09 13:17:51 -0400 | 
|---|---|---|
| committer | Joey Castillo <joeycastillo@utexas.edu> | 2022-05-09 13:17:51 -0400 | 
| commit | 8455bfc9a5b07d58fcabf35bba6f32837ea91f46 (patch) | |
| tree | 54e3d42d7cd2824a2a53c7ef57293d3a635a5d32 | |
| parent | e71a70d23100c178e7300f1c0bddccfc51d99eb7 (diff) | |
| download | Sensor-Watch-8455bfc9a5b07d58fcabf35bba6f32837ea91f46.tar.gz Sensor-Watch-8455bfc9a5b07d58fcabf35bba6f32837ea91f46.tar.bz2 Sensor-Watch-8455bfc9a5b07d58fcabf35bba6f32837ea91f46.zip | |
filesystem: only throw errors for negative error codes
| -rw-r--r-- | movement/filesystem.c | 16 | 
1 files changed, 8 insertions, 8 deletions
| diff --git a/movement/filesystem.c b/movement/filesystem.c index 559bd53d..dc1f98c6 100644 --- a/movement/filesystem.c +++ b/movement/filesystem.c @@ -77,7 +77,7 @@ int filesystem_get_free_space(void) {  static int filesystem_ls(lfs_t *lfs, const char *path) {      lfs_dir_t dir;      int err = lfs_dir_open(lfs, &dir, path); -    if (err) { +    if (err < 0) {          return err;      } @@ -104,7 +104,7 @@ static int filesystem_ls(lfs_t *lfs, const char *path) {      }      err = lfs_dir_close(lfs, &dir); -    if (err) { +    if (err < 0) {          return err;      } @@ -116,10 +116,10 @@ bool filesystem_init(void) {      // reformat if we can't mount the filesystem      // this should only happen on the first boot -    if (err) { +    if (err < 0) {          printf("Ignore that error! Formatting filesystem...\n");          err = lfs_format(&lfs, &cfg); -        if (err) return false; +        if (err < 0) return false;          err = lfs_mount(&lfs, &cfg) == LFS_ERR_OK;          printf("Filesystem mounted with %d bytes free.\n", filesystem_get_free_space());      } @@ -157,9 +157,9 @@ bool filesystem_read_file(char *filename, char *buf, int32_t length) {      int32_t file_size = filesystem_get_file_size(filename);      if (file_size > 0) {          int err = lfs_file_open(&lfs, &file, filename, LFS_O_RDONLY); -        if (err) return false; +        if (err < 0) return false;          err = lfs_file_read(&lfs, &file, buf, min(length, file_size)); -        if (err) return false; +        if (err < 0) return false;          return lfs_file_close(&lfs, &file) == LFS_ERR_OK;      } @@ -185,9 +185,9 @@ static void filesystem_cat(char *filename) {  bool filesystem_write_file(char *filename, char *text, int32_t length) {      int err = lfs_file_open(&lfs, &file, filename, LFS_O_RDWR | LFS_O_CREAT | LFS_O_TRUNC); -    if (err) return false; +    if (err < 0) return false;      err = lfs_file_write(&lfs, &file, text, length); -    if (err) return false; +    if (err < 0) return false;      return lfs_file_close(&lfs, &file) == LFS_ERR_OK;  } | 
