headers of functions for control file handling
More...
#include <sys/types.h>
Go to the source code of this file.
|
typedef int(* | checkfunc) (const char *) |
|
|
size_t | lloadfilefd (int, char **, const int striptab) |
|
int | loadintfd (int, unsigned long *, const unsigned long def) |
|
size_t | loadoneliner (int base, const char *filename, char **buf, const int optional) |
| read a configuration file that only may contain one line More...
|
|
size_t | loadonelinerfd (int fd, char **buf) |
|
int | loadlistfd (int, char ***, checkfunc) |
|
int | finddomainfd (int, const char *, const int) |
|
int | finddomain (const char *buf, const off_t size, const char *domain) |
| search a domain entry in a given buffer More...
|
|
char ** | data_array (unsigned int entries, size_t datalen, void *oldbuf, size_t oldlen) |
| create a combined data and pointer array More...
|
|
headers of functions for control file handling
char** data_array |
( |
unsigned int |
entries, |
|
|
size_t |
datalen, |
|
|
void * |
oldbuf, |
|
|
size_t |
oldlen |
|
) |
| |
create a combined data and pointer array
- Parameters
-
entries | how many entries should be in the pointer array (not counting the terminating NULL entry) |
datalen | length needed for the data, 1 byte per entry is added for the terminating '\0' characters |
oldbuf | if a previous buffer should be realloc()ed, may be NULL |
oldlen | length of oldbuf, must be 0 if oldbuf is NULL |
- Returns
- new buffer or NULL on error
If oldbuf is given the contents of the old buffer are moved to the beginning of the data section of the new memory area.
If oldbuf is given, but reallocation fails (i.e. NULL is returned), then oldbuf is not freed.
int finddomain |
( |
const char * |
buf, |
|
|
const off_t |
size, |
|
|
const char * |
domain |
|
) |
| |
search a domain entry in a given buffer
- Parameters
-
buf | containing the domain list |
size | size of buffer |
domain | domain name to find |
- Return values
-
trailing spaces and tabs in a line are ignored, lines beginning with '#' are ignored, CR in file will cause trouble
int finddomainfd |
( |
int |
fd, |
|
|
const char * |
domain, |
|
|
const int |
cl |
|
) |
| |
mmap a file and search a domain entry in it
- Parameters
-
fd | file descriptor |
domain | domain name to find |
cl | close fd or not |
- Return values
-
1 | on match |
0 | if none |
-1 | on error |
trainling spaces and tabs in a line are ignored, lines beginning with '#' are ignored, CR in file will cause trouble
size_t lloadfilefd |
( |
int |
fd, |
|
|
char ** |
buf, |
|
|
const int |
striptab |
|
) |
| |
load a text file into a buffer using locked IO
- Parameters
-
fd | file descriptor of the file to load |
buf | the contents of the file will go here, memory will be malloced |
striptab | 2: strip trailing whitespace 1: compact {'\0'}* to a single '\0' 0: do nothing but load the file into the buffer |
- Returns
- length of buffer
- Return values
-
-1 | on error (errno is set) |
if the file is empty (size 0 or only comments and blank lines) 0 is returned and buf is set to NULL
- Warning
- if lloadfilefd can't get a lock on the input file (e.g. currently opened for writing by another process) the file is treated as non existent
The input file will be closed before this function returns.
striptab == 2 means: the only whitespace in a non-comment line may be immediately before the line break, in any amount.
buf is always in a sane state when this function returns: either it is NULL or a valid buffer, in the latter case the return value will be >0.
int loadintfd |
( |
int |
fd, |
|
|
unsigned long * |
result, |
|
|
const unsigned long |
def |
|
) |
| |
read a control file containing a single integer
- Parameters
-
fd | file descriptor to read from (will be closed) |
result | value will be stored here |
def | default value if file does not exist |
- Return values
-
0 | on success |
-1 | on error, parse errors in the file will set errno to EINVAL |
int loadlistfd |
( |
int |
fd, |
|
|
char *** |
bufa, |
|
|
checkfunc |
cf |
|
) |
| |
read a list from config file and validate entries
- Parameters
-
fd | file descriptor to read from (is closed on exit!) |
bufa | array to be build from buf (memory will be malloced) |
cf | function to check if an entry is valid or NULL if not to |
- Return values
-
If the file does not exist or has no content *bufa will be set to NULL and 0 is returned.
size_t loadoneliner |
( |
int |
base, |
|
|
const char * |
filename, |
|
|
char ** |
buf, |
|
|
const int |
optional |
|
) |
| |
read a configuration file that only may contain one line
- Parameters
-
base | descriptor of a file descriptor serving as base for relative paths |
filename | don't know what this can ever mean ;) |
buf | the buffer where the contents of the file will go, memory will be malloced |
optional | if set to 0 write an error message to syslog if the file does not exist |
- Returns
- length of the string
- Return values
-
size_t loadonelinerfd |
( |
int |
fd, |
|
|
char ** |
buf |
|
) |
| |
read a configuration file that only may contain one line
- Parameters
-
fd | opened file descriptor |
buf | the buffer where the contents of the file will go, memory will be malloced |
- Returns
- length of the string
- Return values
-
fd will be closed.
descriptor of the control directory