Tor
0.4.7.0-alpha-dev
|
Functions for parsing values with units from a configuration file. More...
#include "orconfig.h"
#include "lib/confmgt/unitparse.h"
#include "lib/log/log.h"
#include "lib/log/util_bug.h"
#include "lib/malloc/malloc.h"
#include "lib/string/parse_int.h"
#include "lib/string/printf.h"
#include "lib/string/util_string.h"
#include "lib/intmath/muldiv.h"
#include <string.h>
Go to the source code of this file.
Functions | |
uint64_t | config_parse_units (const char *val, const unit_table_t *u, int *ok, char **errmsg_out) |
uint64_t | config_parse_memunit (const char *s, int *ok) |
int | config_parse_msec_interval (const char *s, int *ok) |
int | config_parse_interval (const char *s, int *ok) |
Variables | |
const struct unit_table_t | memory_units [] |
const struct unit_table_t | time_units [] |
const struct unit_table_t | time_msec_units [] |
Functions for parsing values with units from a configuration file.
Definition in file unitparse.c.
int config_parse_interval | ( | const char * | s, |
int * | ok | ||
) |
Parse a string in the format "number unit", where unit is a unit of time. On success, set *ok to true and return the number of seconds in the provided interval. Otherwise, set *ok to 0 and return -1.
Definition at line 250 of file unitparse.c.
uint64_t config_parse_memunit | ( | const char * | s, |
int * | ok | ||
) |
Parse a string in the format "number unit", where unit is a unit of information (byte, KB, M, etc). On success, set *ok to true and return the number of bytes specified. Otherwise, set *ok to false and return 0.
Definition at line 222 of file unitparse.c.
int config_parse_msec_interval | ( | const char * | s, |
int * | ok | ||
) |
Parse a string in the format "number unit", where unit is a unit of time in milliseconds. On success, set *ok to true and return the number of milliseconds in the provided interval. Otherwise, set *ok to 0 and return -1.
Definition at line 233 of file unitparse.c.
uint64_t config_parse_units | ( | const char * | val, |
const unit_table_t * | u, | ||
int * | ok, | ||
char ** | errmsg_out | ||
) |
Parse a string val containing a number, zero or more spaces, and an optional unit string. If the unit appears in the table u, then multiply the number by the unit multiplier. On success, set *ok to 1 and return this product. Otherwise, set *ok to 0.
If an error (like overflow or a negative value is detected), put an error message in *errmsg_out if that pointer is non-NULL, and otherwise log a warning.
Definition at line 127 of file unitparse.c.
Referenced by config_parse_interval(), config_parse_memunit(), and config_parse_msec_interval().
const struct unit_table_t memory_units[] |
Table to map the names of memory units to the number of bytes they contain.
Definition at line 1 of file unitparse.c.
Referenced by config_parse_memunit().
const struct unit_table_t time_msec_units[] |
Table to map the names of time units to the number of milliseconds they contain.
Definition at line 1 of file unitparse.c.
Referenced by config_parse_msec_interval().
const struct unit_table_t time_units[] |
Table to map the names of time units to the number of seconds they contain.
Definition at line 1 of file unitparse.c.
Referenced by config_parse_interval().