diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-12-28 14:49:46 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-12-28 14:49:46 -0500 |
commit | 8ae4f8f5985445b1ce3547975f407847c0fee0f7 (patch) | |
tree | a107d4e30fc4a414d2fb3fc656887651e810311e /src/fs.c | |
parent | 5a754bcdc0f5e432c1d7cd358c74dfb2d6f0f1ea (diff) | |
download | spmc-8ae4f8f5985445b1ce3547975f407847c0fee0f7.tar.gz |
Documentation (and stubs)
Diffstat (limited to 'src/fs.c')
-rw-r--r-- | src/fs.c | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -3,6 +3,11 @@ */ #include "spm.h" +/** + * + * @param _path + * @return + */ FSTree *fstree(const char *_path) { FTS *parent = NULL; FTSENT *node = NULL; @@ -58,10 +63,21 @@ FSTree *fstree(const char *_path) { return fsdata; } +/** + * + * @param one + * @param two + * @return + */ int _fstree_compare(const FTSENT **one, const FTSENT **two) { return (strcmp((*one)->fts_name, (*two)->fts_name)); } +/** + * + * @param _path + * @return + */ int rmdirs(const char *_path) { if (access(_path, F_OK) != 0) { return -1; @@ -84,6 +100,10 @@ int rmdirs(const char *_path) { return 0; } +/** + * Free a `FSTree` structure + * @param fsdata + */ void fstree_free(FSTree *fsdata) { if (fsdata != NULL) { if (fsdata->root != NULL) { @@ -346,6 +366,22 @@ int mkdirs(const char *_path, mode_t mode) { } /** + * Short wrapper for `access`. Check if file exists. + * + * Example: + * ~~~{.c} + * if (exists("example.txt") != 0) { + * // handle error + * } + * ~~~ + * @param filename + * @return + */ +int exists(const char *filename) { + return access(filename, F_OK); +} + +/** * Convert size in bytes to the closest human-readable unit * * NOTE: Caller is responsible for freeing memory |