From 8ae4f8f5985445b1ce3547975f407847c0fee0f7 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sat, 28 Dec 2019 14:49:46 -0500 Subject: Documentation (and stubs) --- src/fs.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/fs.c') diff --git a/src/fs.c b/src/fs.c index 5ea8f6b..7441573 100644 --- a/src/fs.c +++ b/src/fs.c @@ -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) { @@ -345,6 +365,22 @@ int mkdirs(const char *_path, mode_t mode) { return result; } +/** + * 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 * -- cgit