diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-12-29 01:35:09 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-12-29 01:35:09 -0500 |
commit | 4595ada2f69b42670c85a63c7d2344af63f2afe7 (patch) | |
tree | 0d528d8177aceefcf74fb7306fc0fc7cc3c41ece /src/fs.c | |
parent | 8ae4f8f5985445b1ce3547975f407847c0fee0f7 (diff) | |
download | spmc-4595ada2f69b42670c85a63c7d2344af63f2afe7.tar.gz |
Minor fixes:
* size_t in place of int
* Moved some variables closer to their execution scope
* Add some error checks
Diffstat (limited to 'src/fs.c')
-rw-r--r-- | src/fs.c | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -85,12 +85,12 @@ int rmdirs(const char *_path) { FSTree *data = fstree(_path); if (data->files) { - for (int i = 0; data->files[i] != NULL; i++) { + for (size_t i = 0; data->files[i] != NULL; i++) { remove(data->files[i]); } } if (data->dirs) { - for (int i = data->dirs_length - 1; i != 0; i--) { + for (size_t i = data->dirs_length - 1; i != 0; i--) { remove(data->dirs[i]); } } @@ -177,7 +177,7 @@ char *expandpath(const char *_path) { } // A broken runtime environment means we can't do anything else here - if (!home) { + if (isempty(home)) { return NULL; } @@ -256,14 +256,14 @@ char *dirname(const char *_path) { */ char *basename(char *path) { char *result = NULL; - char *last = strrchr(path, DIRSEP); - if (!last) { - return NULL; - } + char *last = NULL; + if ((last = strrchr(path, DIRSEP)) == NULL) { + return result; + } // Perform a lookahead ensuring the string is valid beyond the last separator - if ((last + 1) != NULL) { - result = last + 1; + if (last++ != NULL) { + result = last; } return result; @@ -409,7 +409,7 @@ char *human_readable_size(uint64_t n) { memset(r, '\0', sizeof(r)); for (i = 0; i < sizeof(unit); i++) { - if (labs(result) < 1024) { + if (fabs(result) < 1024) { break; } result /= 1024.0; |