Various miscellaneous functions to manipulate files and paths.
More...
#include <sys/param.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <freeradius-devel/util/file.h>
#include <freeradius-devel/util/strerror.h>
#include <freeradius-devel/util/syserror.h>
#include <freeradius-devel/util/value.h>
Go to the source code of this file.
|
| static ssize_t | _fr_mkdir (int *fd_out, char *start, char *path, mode_t mode, fr_mkdir_func_t func, void *uctx) |
| |
| 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.
|
| |
| static bool | fr_globdir_file_ok (char const *try, fr_globdir_iter_t *iter) |
| |
| static int | fr_globdir_get_path (char const *dir, char const *pattern, fr_globdir_iter_t *iter) |
| | Create a full path from dir + pattern.
|
| |
| 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.
|
| |
Various miscellaneous functions to manipulate files and paths.
- Copyright
- 2019 The FreeRADIUS project
-
2019 Arran Cudbard-Bell (a.cud.nosp@m.bard.nosp@m.b@fre.nosp@m.erad.nosp@m.ius.o.nosp@m.rg)
Definition in file file.c.
◆ _fr_mkdir()
◆ 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] | filename | to strip working directory from. |
- Returns
- Position in filename after our working directory.
Definition at line 384 of file file.c.
◆ 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] | dirfd | points to place to store the dirfd |
| [in] | filename | points to placd to store a pointer into pathname that points to the filename |
| [in] | pathname | the full pathname of the file |
- Returns
-
Definition at line 412 of file file.c.
◆ fr_globdir_file_ok()
◆ fr_globdir_get_path()
| static int fr_globdir_get_path |
( |
char const * |
dir, |
|
|
char const * |
pattern, |
|
|
fr_globdir_iter_t * |
iter |
|
) |
| |
|
static |
Create a full path from dir + pattern.
Definition at line 564 of file file.c.
◆ fr_globdir_iter_free()
◆ 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] | filename | the relative filename which should be opened |
| [in] | dir | the directory to read |
| [in] | pattern | the filename or pattern to read. Cannot be an absolute path. |
| [in,out] | iter | the iteration structure. |
- Returns
- <0 on error
- 0 on success, but no filename
- 1 for "have file".
Definition at line 694 of file file.c.
◆ fr_globdir_iter_next()
◆ fr_mkdir()
Create directories that are missing in the specified path.
- Parameters
-
| [out] | fd_out | If not NULL, will contain a file descriptor for the deepest path component created. |
| [in] | path | to populate with directories. |
| [in] | len | Length of the path string. |
| [in] | mode | for new directories. |
| [in] | func | to call each time a new directory is created. |
| [in] | uctx | to 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.
◆ 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.
◆ 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] | ctx | in which to allocate the result. |
| [in] | path | To convert to an absolute path. |
| [in] | len | How 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.
◆ fr_touch()
Create an empty file.
- Parameters
-
| [out] | fd_out | If not NULL, will contain a file descriptor for the file we just opened. |
| [in] | filename | path to file. |
| [in] | mode | Specifies the file mode bits be applied. |
| [in] | mkdir | Whether we should create directories for any missing path components. |
| [in] | dir_mode | Mode 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.
◆ fr_unlink()
| int fr_unlink |
( |
char const * |
filename | ) |
|
Remove a regular file from the filesystem.
- Parameters
-
| [in] | filename | path 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.
◆ fr_filename_escape
Initial value:= {
.name = "filename",
.chr = '_',
.do_utf8 = true,
.do_hex = true,
.esc = {
[ 0x00 ... 0x2d ] = true,
[ 0x2f ] = true,
[ 0x3A ... 0x3f ] = true,
[ 0x5b ... 0x5e ] = true,
[ 0x60 ] = true,
[ 0x7b ... 0xff ] = true,
},
}
Definition at line 917 of file file.c.
◆ fr_filename_escape_dots
Initial value:= {
.name = "filename",
.chr = '_',
.do_utf8 = true,
.do_hex = true,
.esc = {
[ 0x00 ... 0x2f ] = true,
[ 0x3A ... 0x3f ] = true,
[ 0x5b ... 0x5e ] = true,
[ 0x60 ] = true,
[ 0x7b ... 0xff ] = true,
},
}
Definition at line 933 of file file.c.