The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
Data Structures | Typedefs | Enumerations | Functions
file.h File Reference

Various miscellaneous functions to manipulate files and paths. More...

#include <freeradius-devel/util/talloc.h>
#include <stdbool.h>
+ Include dependency graph for file.h:

Go to the source code of this file.

Data Structures

struct  fr_globdir_iter_t
 
union  fr_globdir_iter_t.__unnamed137__
 
struct  fr_mkdir_chown_t
 

Typedefs

typedef int(* fr_mkdir_func_t) (int fd, char const *path, void *uctx)
 Callback for allowing additional operations on newly created directories.
 

Enumerations

enum  fr_globdir_type_t {
  FR_GLOBDIR_INVALID = 0 ,
  FR_GLOBDIR_FILE
}
 

Functions

char const * fr_cwd_strip (char const *filename)
 Intended to be used in logging functions to make output more readable.
 
int fr_dirfd (int *dirfd, char const **filename, char const *pathname)
 From a pathname, return fd and filename needed for *at() functions.
 
int fr_globdir_iter_free (fr_globdir_iter_t *iter)
 
int fr_globdir_iter_init (char const **filename, char const *dir, char const *pattern, fr_globdir_iter_t *iter)
 Initialize an iterator over filenames.
 
int fr_globdir_iter_next (char const **filename, fr_globdir_iter_t *iter)
 Get the next filename.
 
ssize_t fr_mkdir (int *fd_out, char const *path, ssize_t len, mode_t mode, fr_mkdir_func_t func, void *uctx)
 Create directories that are missing in the specified path.
 
int fr_mkdir_chown (int fd, char const *path, void *uctx)
 Callback for the common case of chown() of the directory.
 
char * fr_realpath (TALLOC_CTX *ctx, char const *path, ssize_t len)
 Convenience wrapper around realpath.
 
ssize_t fr_touch (int *fd_out, char const *filename, mode_t mode, bool mkdir, mode_t dir_mode)
 Create an empty file.
 
int fr_unlink (char const *filename)
 Remove a regular file from the filesystem.
 

Detailed Description

Various miscellaneous functions to manipulate files and paths.

Definition in file file.h.


Data Structure Documentation

◆ fr_globdir_iter_t

struct fr_globdir_iter_t

Definition at line 86 of file file.h.

Data Fields
union fr_globdir_iter_t.__unnamed137__ __unnamed__
char * filename
char * path
fr_globdir_type_t type

◆ fr_globdir_iter_t.__unnamed137__

union fr_globdir_iter_t.__unnamed137__

Definition at line 92 of file file.h.

Data Fields
DIR * dir

◆ fr_mkdir_chown_t

struct fr_mkdir_chown_t

Definition at line 55 of file file.h.

Data Fields
gid_t gid
uid_t uid

Typedef Documentation

◆ fr_mkdir_func_t

typedef int(* fr_mkdir_func_t) (int fd, char const *path, void *uctx)

Callback for allowing additional operations on newly created directories.

Parameters
[in]fdOf newly created directory.
[in]pathEither relative or full to the new directory. Should only be used for debug messages or functions that don't have an 'at' variant.
[in]uctxUser data to pass to callback.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 53 of file file.h.

Enumeration Type Documentation

◆ fr_globdir_type_t

Enumerator
FR_GLOBDIR_INVALID 
FR_GLOBDIR_FILE 

Definition at line 75 of file file.h.

Function Documentation

◆ fr_cwd_strip()

char const * fr_cwd_strip ( char const *  filename)

Intended to be used in logging functions to make output more readable.

This function is not performant and should probably not be used at runtime.

Parameters
[in]filenameto strip working directory from.
Returns
Position in filename after our working directory.

Definition at line 384 of file file.c.

+ Here is the caller graph for this function:

◆ fr_dirfd()

int fr_dirfd ( int *  dirfd,
char const **  filename,
char const *  pathname 
)

From a pathname, return fd and filename needed for *at() functions.

Parameters
[in]dirfdpoints to place to store the dirfd
[in]filenamepoints to placd to store a pointer into pathname that points to the filename
[in]pathnamethe full pathname of the file
Returns
  • -1 on error
  • 0 on success

Definition at line 412 of file file.c.

+ Here is the caller graph for this function:

◆ fr_globdir_iter_free()

int fr_globdir_iter_free ( fr_globdir_iter_t iter)

Definition at line 879 of file file.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_globdir_iter_init()

int fr_globdir_iter_init ( char const **  filename,
char const *  dir,
char const *  pattern,
fr_globdir_iter_t iter 
)

Initialize an iterator over filenames.

Parameters
[out]filenamethe relative filename which should be opened
[in]dirthe directory to read
[in]patternthe filename or pattern to read. Cannot be an absolute path.
[in,out]iterthe iteration structure.
Returns
  • <0 on error
  • 0 on success, but no filename
  • 1 for "have file".

Definition at line 687 of file file.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_globdir_iter_next()

int fr_globdir_iter_next ( char const **  filename,
fr_globdir_iter_t iter 
)

Get the next filename.

fr_globdir_iter_init() do { ... use filename } while (fr_globdir_iter_next() == 1); fr_globdir_iter_free()

Returns
  • <0 for error
  • 0 for done
  • 1 for "have filename"

Definition at line 845 of file file.c.

+ Here is the caller graph for this function:

◆ fr_mkdir()

ssize_t fr_mkdir ( int *  fd_out,
char const *  path,
ssize_t  len,
mode_t  mode,
fr_mkdir_func_t  func,
void *  uctx 
)

Create directories that are missing in the specified path.

Parameters
[out]fd_outIf not NULL, will contain a file descriptor for the deepest path component created.
[in]pathto populate with directories.
[in]lenLength of the path string.
[in]modefor new directories.
[in]functo call each time a new directory is created.
[in]uctxto pass to func.
Returns
  • >0 on success.
  • <= 0 on failure. Negative offset pointing to the path separator of the path component that caused the error.

Definition at line 219 of file file.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_mkdir_chown()

int fr_mkdir_chown ( int  fd,
char const *  path,
void *  uctx 
)

Callback for the common case of chown() of the directory.

Definition at line 39 of file file.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_realpath()

char * fr_realpath ( TALLOC_CTX *  ctx,
char const *  path,
ssize_t  len 
)

Convenience wrapper around realpath.

Wraps realpath, but takes a path with an explicit length, and returns the result in a talloced buffer.

On error, errno is set, and the string version of the error is available with fr_strerror().

Parameters
[in]ctxin which to allocate the result.
[in]pathTo convert to an absolute path.
[in]lenHow much of 'path' to read. If < 0, then the entire path will be used.
Returns
  • NULL on error.
  • The absolute version of the input path on success.

Definition at line 284 of file file.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_touch()

ssize_t fr_touch ( int *  fd_out,
char const *  filename,
mode_t  mode,
bool  mkdir,
mode_t  dir_mode 
)

Create an empty file.

Parameters
[out]fd_outIf not NULL, will contain a file descriptor for the file we just opened.
[in]filenamepath to file.
[in]modeSpecifies the file mode bits be applied.
[in]mkdirWhether we should create directories for any missing path components.
[in]dir_modeMode of any directories created.
Returns
  • >0 on success.
  • <= 0 on failure. Error available in error stack (use fr_strerror())

Definition at line 323 of file file.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_unlink()

int fr_unlink ( char const *  filename)

Remove a regular file from the filesystem.

Parameters
[in]filenamepath to file.
Returns
  • -1 On error.
  • 0 if the file was removed.
  • 1 if the file didn't exist.

Definition at line 367 of file file.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: