Crinit -- Configurable Rootfs Init
|
Implementations of conversion operations from configuration values to structured data. More...
#include "confconv.h"
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include "common.h"
#include "lexers.h"
#include "logio.h"
Macros | |
#define | crinitConfConvToIntegerFnBody(resType, confVal) |
Functions | |
static char * | crinitCopyEscaped (char *dst, const char *src, const char *end) |
char ** | crinitConfConvToStrArr (int *numElements, const char *confVal, bool doubleQuoting) |
int | crinitConfConvToIntegerI (int *x, const char *confVal, int base) |
int | crinitConfConvToIntegerULL (unsigned long long *x, const char *confVal, int base) |
int | crinitConfConvToBool (bool *b, const char *confVal) |
int | crinitConfConvToIoRedir (crinitIoRedir_t *ior, const char *confVal) |
int | crinitConfConvToEnvSetMember (crinitEnvSet_t *es, const char *confVal) |
Implementations of conversion operations from configuration values to structured data.
#define crinitConfConvToIntegerFnBody | ( | resType, | |
confVal | |||
) |
Function body for type-generic string-to-integer functions, used internally to deduplicate code.
int crinitConfConvToBool | ( | bool * | b, |
const char * | confVal | ||
) |
Converts a string to bool.
String must be equal to either NO
(==false
) or YES
(==true
).
b | Output pointer to bool variable. |
confVal | The string to convert. |
int crinitConfConvToEnvSetMember | ( | crinitEnvSet_t * | es, |
const char * | confVal | ||
) |
Parses a single ENV_SET directive and sets the variable in question accordingly.
For details on the syntax, see the relevant section in README.md.
es | The environment set to be modified, must be initialized. |
confVal | The ENV_SET directive to be parsed and "executed" on the set. |
int crinitConfConvToIntegerI | ( | int * | x, |
const char * | confVal, | ||
int | base | ||
) |
Converts a string to a signed integer, see crinitConfConvToInteger()
int crinitConfConvToIntegerULL | ( | unsigned long long * | x, |
const char * | confVal, | ||
int | base | ||
) |
Converts a string to an unsigned long long, see crinitConfConvToInteger()
int crinitConfConvToIoRedir | ( | crinitIoRedir_t * | ior, |
const char * | confVal | ||
) |
Initializes an instance of crinitIoRedir_t from an IO redirection statement in a string.
The string must be of the form
Where REDIRECT_FROM is one of STDOUT, STDERR, STDIN and REDIRECT_TO may either also be one of those streams or an absolute path to a file. APPEND or TRUNCATE signify whether an existing file at that location should be appended to or truncated. Default ist TRUNCATE. OCTAL MODE sets the permission bits if the file is newly created. Default is 0644.
The function may allocate memory inside the crinitIoRedir_t struct which must be freed using crinitDestroyIoRedir().
ior | The crinitIoRedir_t instance to initialize. |
confVal | The string with the statement to parse. |
char** crinitConfConvToStrArr | ( | int * | numElements, |
const char * | confVal, | ||
bool | doubleQuoting | ||
) |
Extract an array of strings from the value mapped to an indexed key in an crinitConfKvList_t.
Will split confVal along spaces. Will optionally respect quoting using double quotes if doubleQuoting is set to true. A dynamically-allocated array-of-strings is returned. If no longer needed it should be freed using crinitFreeArgvArray(). numElements will contain the number of strings inside the output array and the output array will be additionally NULL-terminated, same as argc/argv in main()
.
numElements | Will contain the number of strings in the output. |
confVal | The string to split. |
doubleQuoting | If true, crinitConfConvToStrArr will respect quoting with double quotes. |
|
static |
Copies a string while resolving all contained escape sequences.
dst | Destination string. Must have enough space. Best practice would be "same as \a src" because escape sequence evaluation can only make the string shorter in this case. |
src | Source string, potentially containing escape sequences. |
end | End pointer, if src should not be read until the terminating null byte. |