fsautoproc
Basic file transformation automation management utility
Loading...
Searching...
No Matches
fs.c File Reference

Filesystem walk and stat implementation. More...

#include "fs.h"
#include <assert.h>
#include <errno.h>
#include <fts.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include "jemalloc/jemalloc.h"
#include "log.h"
Include dependency graph for fs.c:

Functions

static int fsprocent (FTSENT *ent, fswalkfn_t filefn, void *udata)
 Internal helper function to process a single file entry from the FTS walk. The file's last modified time and size are extracted from the stat structure and passed to the user-defined callback function.
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.

Detailed Description

Filesystem walk and stat implementation.

Function Documentation

◆ 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
dirThe directory path
fileThe 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.
Here is the caller graph for this function:

◆ fsprocent()

int fsprocent ( FTSENT * ent,
fswalkfn_t filefn,
void * udata )
static

Internal helper function to process a single file entry from the FTS walk. The file's last modified time and size are extracted from the stat structure and passed to the user-defined callback function.

Parameters
entThe FTSENT file entry to process
filefnThe user-defined callback function to invoke for the file
udataUser data pointer to pass to the callback function
Returns
The return value of the user-defined callback function
Here is the caller graph for this function:

◆ 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
fpThe filepath to fstat
sThe struct fsstat_s to populate
Returns
If successful, s is populated and 0 is returned. Otherwise -1 is returned and errno is set.
Here is the caller graph for this function:

◆ 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
dirThe directory to walk
filefnThe 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.
udataUser 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.
Here is the call graph for this function:
Here is the caller graph for this function: