The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
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  */
25 RCSIDH(util_file_h, "$Id: 29d3b16c0693a372be2a70eed20a5bbf4be4910e $")
26 
27 #ifdef __cplusplus
28 extern "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  */
45 typedef int(*fr_mkdir_func_t)(int fd, char const *path, void *uctx);
46 
47 ssize_t fr_mkdir(int *fd_out, char const *path, ssize_t len, mode_t mode,
48  fr_mkdir_func_t func, void *uctx);
49 
50 char *fr_realpath(TALLOC_CTX *ctx, char const *path, ssize_t len);
51 
52 ssize_t fr_touch(int *fd_out, char const *filename, mode_t mode, bool mkdir, mode_t dir_mode);
53 
54 int fr_unlink(char const *filename);
55 
56 char const *fr_cwd_strip(char const *filename);
57 
58 int fr_dirfd(int *dirfd, char const **filename, char const *pathname) CC_HINT(nonnull);
59 
60 #ifdef __cplusplus
61 }
62 #endif
#define RCSIDH(h, id)
Definition: build.h:445
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:200
int fr_unlink(char const *filename)
Remove a regular file from the filesystem.
Definition: file.c:348
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:304
char * fr_realpath(TALLOC_CTX *ctx, char const *path, ssize_t len)
Convenience wrapper around realpath.
Definition: file.c:265
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:393
char const * fr_cwd_strip(char const *filename)
Intended to be used in logging functions to make output more readable.
Definition: file.c:365
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
Definition: merged_model.c:24
unsigned int mode_t
Definition: merged_model.c:21
int nonnull(2, 5))