The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Typedefs | 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_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. More...
 

Functions

char const * fr_cwd_strip (char const *filename)
 Intended to be used in logging functions to make output more readable. More...
 
int fr_dirfd (int *dirfd, char const **filename, char const *pathname)
 From a pathname, return fd and filename needed for *at() functions. More...
 
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. More...
 
int fr_mkdir_chown (int fd, char const *path, void *uctx)
 Callback for the common case of chown() of the directory. More...
 
char * fr_realpath (TALLOC_CTX *ctx, char const *path, ssize_t len)
 Convenience wrapper around realpath. More...
 
ssize_t fr_touch (int *fd_out, char const *filename, mode_t mode, bool mkdir, mode_t dir_mode)
 Create an empty file. More...
 
int fr_unlink (char const *filename)
 Remove a regular file from the filesystem. More...
 

Detailed Description

Various miscellaneous functions to manipulate files and paths.

Definition in file file.h.


Data Structure Documentation

◆ fr_mkdir_chown_t

struct fr_mkdir_chown_t

Definition at line 47 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 45 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_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: