Crinit -- Configurable Rootfs Init
confconv.h File Reference

(2023-08-02, commit: 9434b31)

Definitions related to conversion operations from configuration values to structured data. More...

#include <stdbool.h>
#include "envset.h"
#include "ioredir.h"
Include dependency graph for confconv.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define crinitConfConvToInteger(out, confVal, base)
 

Functions

char ** crinitConfConvToStrArr (int *numElements, const char *confVal, bool doubleQuoting)
 
int crinitConfConvToIoRedir (crinitIoRedir_t *ior, const char *confVal)
 
int crinitConfConvToEnvSetMember (crinitEnvSet_t *es, const char *confVal)
 
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)
 

Detailed Description

Definitions related to conversion operations from configuration values to structured data.

Macro Definition Documentation

◆ crinitConfConvToInteger

#define crinitConfConvToInteger (   out,
  confVal,
  base 
)
Value:
_Generic((*(out)), \
unsigned long long : crinitConfConvToIntegerULL) \
(out, confVal, base)
int crinitConfConvToIntegerULL(unsigned long long *x, const char *confVal, int base)
Definition: confconv.c:151
int crinitConfConvToIntegerI(int *x, const char *confVal, int base)
Definition: confconv.c:145

Type-generic macro for string to integer conversion.

Currently only implemented for int and unsigned long long.

Parameters
outOutput pointer, type-generic (but must be a pointer).
confValThe string to convert.
baseThe decimal base to use in conversion.
Returns
0 on success, -1 on error

Function Documentation

◆ crinitConfConvToBool()

int crinitConfConvToBool ( bool *  b,
const char *  confVal 
)

Converts a string to bool.

String must be equal to either NO (==false) or YES (==true).

Parameters
bOutput pointer to bool variable.
confValThe string to convert.
Returns
0 on success, -1 on error.

◆ crinitConfConvToEnvSetMember()

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.

Parameters
esThe environment set to be modified, must be initialized.
confValThe ENV_SET directive to be parsed and "executed" on the set.
Returns
0 on success, -1 otherwise

◆ crinitConfConvToIntegerI()

int crinitConfConvToIntegerI ( int *  x,
const char *  confVal,
int  base 
)

Converts a string to a signed integer, see crinitConfConvToInteger()

◆ crinitConfConvToIntegerULL()

int crinitConfConvToIntegerULL ( unsigned long long *  x,
const char *  confVal,
int  base 
)

Converts a string to an unsigned long long, see crinitConfConvToInteger()

◆ crinitConfConvToIoRedir()

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

<REDIRECT_FROM> <REDIRECT_TO> [ APPEND | TRUNCATE ] [ OCTAL MODE ]

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().

Parameters
iorThe crinitIoRedir_t instance to initialize.
confValThe string with the statement to parse.
Returns
0 on success, -1 otherwise

◆ crinitConfConvToStrArr()

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().

Parameters
numElementsWill contain the number of strings in the output.
confValThe string to split.
doubleQuotingIf true, crinitConfConvToStrArr will respect quoting with double quotes.
Returns
A new dynamically allocated array of the substrings in confVal on success, NULL on error.