Functionality includes closing descriptors of current process, running server as a daemon, recursive remove of a directory or a file, opening and locking file, closing file.
More...
|
| int | closeall (int nostdclose) |
| | close all file descriptors of current process More...
|
| |
| pid_t | daemonize (const char *path, char *const argv[], int nochdir, int noclose) |
| | run program as daemon More...
|
| |
| int | pidlock_set (const char *path) |
| | try to save pid of calling process to file More...
|
| |
| pid_t | pidlock_get (const char *path) |
| | read pid from file and verify it More...
|
| |
| int | dir_remove (const char *path) |
| | recursive remove directory or file More...
|
| |
| int | mkdirectory (const char *path, mode_t mode) |
| | verify or create directory More...
|
| |
| int | executefile (const char *path) |
| | execute file as program More...
|
| |
| int | put_file_contents (const char *path, const void *buf, size_t len) |
| | save data to file More...
|
| |
| void * | get_file_contents (const char *path, void **buf, size_t *len) |
| | allocate memory and read data from file More...
|
| |
| FILE * | flopen (const char *path, const char *mode, FILE **fp) |
| | open and lock file More...
|
| |
| FILE * | fltryopen (const char *path, const char *mode, FILE **fp) |
| | open and try lock file More...
|
| |
| int | flclose (FILE *fp) |
| | close file openned by flopen() or fltryopen() More...
|
| |
| int | movefile (const char *oldpath, const char *newpath) |
| | move file to new path More...
|
| |
Functionality includes closing descriptors of current process, running server as a daemon, recursive remove of a directory or a file, opening and locking file, closing file.
| int closeall |
( |
int |
nostdclose | ) |
|
close all file descriptors of current process
- Parameters
-
| [in] | nostdclose | don't close stdio file descriptors |
- Returns
- zero is returned
- Return values
-
This function can be useful for implementation system() like functions.
| pid_t daemonize |
( |
const char * |
path, |
|
|
char *const |
argv[], |
|
|
int |
nochdir, |
|
|
int |
noclose |
|
) |
| |
run program as daemon
- Parameters
-
| [in] | path | path to program file |
| [in] | argv | arguments for program (last item should be NULL) |
| [in] | nochdir | don't change current directory to '/' for daemon |
| [in] | noclose | don't close stdio streams for daemon |
- Returns
- pid of started daemon
- Return values
-
| int dir_remove |
( |
const char * |
path | ) |
|
recursive remove directory or file
- Parameters
-
| [in] | path | name of directory or file |
- Returns
- on success, zero is returned
Function updates errno if error occurred:
- ENOMEM no memory format path
If function fails to delete directory (file) it will continue to delete rest of the directories (files), but don't return zero.
| int executefile |
( |
const char * |
path | ) |
|
execute file as program
- Parameters
-
| [in] | path | path to executable file |
- Returns
- status code of child process
- Return values
-
close file openned by flopen() or fltryopen()
- Parameters
-
| [in] | fp | file descriptor (can be NULL) |
- Returns
- on success, zero is returned
- Return values
-
If error occurred function update errno - see errors specified for the routines fileno(3), flock(2), and fclose(3).
| FILE* flopen |
( |
const char * |
path, |
|
|
const char * |
mode, |
|
|
FILE ** |
fp |
|
) |
| |
open and lock file
- Parameters
-
| [in] | path | name of the file to be created or opened |
| [in] | mode | permissive mode |
| [out] | fp | file descriptor |
- Returns
- pointer to descriptor
- Return values
-
| NULL | error occurred, fp also should be NULL |
If error occurred function update errno - see errors specified for the routines fopen(3), fileno(3), flock(2), and fclose(3).
| FILE* fltryopen |
( |
const char * |
path, |
|
|
const char * |
mode, |
|
|
FILE ** |
fp |
|
) |
| |
open and try lock file
- Parameters
-
| [in] | path | name of the file to be created or opened |
| [in] | mode | permissive mode |
| [out] | fp | file descriptor |
- Returns
- pointer to descriptor
- Return values
-
| NULL | error occurred, fp also should be NULL |
If error occurred function update errno - see errors specified for the routines fopen(3), fileno(3), flock(2), and fclose(3).
| void* get_file_contents |
( |
const char * |
path, |
|
|
void ** |
buf, |
|
|
size_t * |
len |
|
) |
| |
allocate memory and read data from file
- Parameters
-
| [in] | path | file name |
| [out] | buf | pointer to file data |
| [out] | len | pointer to file length |
- Returns
- on success pointer to allocated memory
- Return values
-
| int mkdirectory |
( |
const char * |
path, |
|
|
mode_t |
mode |
|
) |
| |
verify or create directory
- Parameters
-
| [in] | path | directory name |
| [in] | mode | directory permissions |
- Returns
- zero returned
- Return values
-
This function make parent directories, if needed.
| int movefile |
( |
const char * |
oldpath, |
|
|
const char * |
newpath |
|
) |
| |
move file to new path
- Parameters
-
| [in] | oldpath | filename to move |
| [in] | newpath | new path of file |
- Returns
- zero is returned
- Return values
-
| -1 | error occured, check errno for more info |
When oldpath and newpath on the same filesystem - rename() syscall will be used. If rename() syscall failed function will try create new and delete old file.
| pid_t pidlock_get |
( |
const char * |
path | ) |
|
read pid from file and verify it
- Parameters
-
- Returns
- pid of process
- Return values
-
| 0 | process don't exist |
| -1 | error occurred |
If error occurred function update errno - see errors specified for the routines flopen(), flclose(), fscanf(3) and kill(2).
| int pidlock_set |
( |
const char * |
path | ) |
|
try to save pid of calling process to file
- Parameters
-
- Returns
- on success, zero is returned
- Return values
-
Function fail, if another process already set pidlock.
If error occurred function update errno - see errors specified for the routines fltryopen(), flclose(), fscanf(3), fprintf(3), ftruncate(2) and kill(2).
| int put_file_contents |
( |
const char * |
path, |
|
|
const void * |
buf, |
|
|
size_t |
len |
|
) |
| |
save data to file
- Parameters
-
| [in] | path | file name |
| [in] | buf | pointer to data buffer |
| [in] | len | length of data at buffer buf |
- Returns
- on success, zero is returned
- Return values
-