Tor  0.4.4.0-alpha-dev
Data Structures | Functions | Variables
unitparse.h File Reference

Header for lib/confmgt/unitparse.c. More...

#include <lib/cc/torint.h>

Go to the source code of this file.

Data Structures

struct  unit_table_t
 

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 unit_table_t memory_units []
 
const unit_table_t time_units []
 
const struct unit_table_t time_msec_units []
 

Detailed Description

Header for lib/confmgt/unitparse.c.

Definition in file unitparse.h.

Function Documentation

◆ config_parse_interval()

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.

◆ config_parse_memunit()

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.

◆ config_parse_msec_interval()

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.

◆ config_parse_units()

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

Variable Documentation

◆ memory_units

const unit_table_t memory_units[]

Table to map the names of memory units to the number of bytes they contain.

Definition at line 27 of file unitparse.c.

Referenced by config_parse_memunit().

◆ time_msec_units

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 97 of file unitparse.c.

Referenced by config_parse_msec_interval().

◆ time_units

const unit_table_t time_units[]

Table to map the names of time units to the number of seconds they contain.

Definition at line 76 of file unitparse.c.

Referenced by config_parse_interval().