Filesystem walk and stat functions.
More...
#include <stdint.h>
Go to the source code of this file.
|
| struct | fsstat_s |
| | Stat structure for storing the last modified time and file size. More...
|
| |
|
| typedef int(* | fswalkfn_t) (const char *fp, const struct fsstat_s *st, void *udata) |
| | Callback function used by fswalk to process files and directories.
|
| |
|
| int | fswalk (const char *dir, fswalkfn_t filefn, void *udata) |
| | Recursively walks the single directory described by dir and calls filefn for each file found.
|
| |
| int | fsstat (const char *fp, struct fsstat_s *s) |
| | Populates all fields of a given fsstat_s structure for the file described by the filepath fp.
|
| |
| char * | fsjoin (const char *dir, const char *file) |
| | Concatenates the two strings into a single path string, joined by a / (path separator) character. Neither input string is modified or freed.
|
| |
Filesystem walk and stat functions.
◆ fswalkfn_t
Callback function used by fswalk to process files and directories.
- Parameters
-
| fp | The file or directory path to process |
| st | File stat information |
| udata | User data passed to the callback function |
- Returns
- 0 if the walk should continue, otherwise a non-zero value to stop
◆ fsjoin()
| char * fsjoin |
( |
const char * |
dir, |
|
|
const char * |
file |
|
) |
| |
Concatenates the two strings into a single path string, joined by a / (path separator) character. Neither input string is modified or freed.
- Parameters
-
| dir | The directory path |
| file | The file path |
- Returns
- A dynamically allocated string containing the joined path (i.e.
dir/file). The caller is responsible for freeing the string. NULL is returned if an error occurred.
◆ fsstat()
| int fsstat |
( |
const char * |
fp, |
|
|
struct fsstat_s * |
s |
|
) |
| |
Populates all fields of a given fsstat_s structure for the file described by the filepath fp.
- Parameters
-
| fp | The filepath to fstat |
| s | The struct fsstat_s to populate |
- Returns
- If successful,
s is populated and 0 is returned. Otherwise -1 is returned and errno is set.
◆ fswalk()
| int fswalk |
( |
const char * |
dir, |
|
|
fswalkfn_t |
filefn, |
|
|
void * |
udata |
|
) |
| |
Recursively walks the single directory described by dir and calls filefn for each file found.
- Parameters
-
| dir | The directory to walk |
| filefn | The function to call for each file found. The filepath is passed as the first argument. If the function returns a non-zero value, the walk is terminated and the same value is returned by fswalk. |
| udata | User data to pass to filefn and dirfn |
- Returns
- If successful, 0 is returned. An internal
fswalk error will return a value of -1 and errno is set. Otherwise the return value of the first non-zero filefn or dirfn call is returned.