The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
file.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/** Various miscellaneous functions to manipulate files and paths
19 *
20 * @file src/lib/util/file.h
21 *
22 * @copyright 2019 The FreeRADIUS project
23 * @copyright 2019 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
24 */
25RCSIDH(util_file_h, "$Id: a95d4ecbddee28a251d2f0c415fa7c7557fe8951 $")
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#include <freeradius-devel/util/talloc.h>
32#include <stdbool.h>
33
34/** Callback for allowing additional operations on newly created directories
35 *
36 * @param[in] fd Of newly created directory.
37 * @param[in] path Either relative or full to the new directory.
38 * Should only be used for debug messages or functions
39 * that don't have an 'at' variant.
40 * @param[in] uctx User data to pass to callback.
41 * @return
42 * - 0 on success.
43 * - -1 on failure.
44 */
45typedef int(*fr_mkdir_func_t)(int fd, char const *path, void *uctx);
46
47typedef struct {
48 uid_t uid;
49 gid_t gid;
51
52int fr_mkdir_chown(int fd, char const *path, void *uctx);
53
54ssize_t fr_mkdir(int *fd_out, char const *path, ssize_t len, mode_t mode,
55 fr_mkdir_func_t func, void *uctx);
56
57char *fr_realpath(TALLOC_CTX *ctx, char const *path, ssize_t len);
58
59ssize_t fr_touch(int *fd_out, char const *filename, mode_t mode, bool mkdir, mode_t dir_mode);
60
61int fr_unlink(char const *filename);
62
63char const *fr_cwd_strip(char const *filename);
64
65int fr_dirfd(int *dirfd, char const **filename, char const *pathname) CC_HINT(nonnull);
66
67#ifdef __cplusplus
68}
69#endif
#define RCSIDH(h, id)
Definition build.h:484
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.
Definition file.c:219
int fr_unlink(char const *filename)
Remove a regular file from the filesystem.
Definition file.c:367
int fr_mkdir_chown(int fd, char const *path, void *uctx)
Callback for the common case of chown() of the directory.
Definition file.c:39
uid_t uid
Definition file.h:48
ssize_t fr_touch(int *fd_out, char const *filename, mode_t mode, bool mkdir, mode_t dir_mode)
Create an empty file.
Definition file.c:323
gid_t gid
Definition file.h:49
char const * fr_cwd_strip(char const *filename)
Intended to be used in logging functions to make output more readable.
Definition file.c:384
int fr_dirfd(int *dirfd, char const **filename, char const *pathname)
From a pathname, return fd and filename needed for *at() functions.
Definition file.c:412
char * fr_realpath(TALLOC_CTX *ctx, char const *path, ssize_t len)
Convenience wrapper around realpath.
Definition file.c:284
int(* fr_mkdir_func_t)(int fd, char const *path, void *uctx)
Callback for allowing additional operations on newly created directories.
Definition file.h:45
long int ssize_t
unsigned int mode_t
int nonnull(2, 5))