tor  0.4.2.1-alpha-dev
Data Structures | Typedefs | Functions | Variables
unitparse.h File Reference
#include <lib/cc/torint.h>

Go to the source code of this file.

Data Structures

struct  unit_table_t
 

Typedefs

typedef struct unit_table_t unit_table_t
 

Functions

uint64_t config_parse_units (const char *val, const unit_table_t *u, int *ok)
 
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.

Typedef Documentation

◆ unit_table_t

typedef struct unit_table_t unit_table_t

Mapping from a unit name to a multiplier for converting that unit into a base unit. Used by config_parse_unit.

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

References config_parse_units(), and time_units.

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

References config_parse_units(), and memory_units.

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

References config_parse_units(), and time_msec_units.

◆ config_parse_units()

uint64_t config_parse_units ( const char *  val,
const unit_table_t u,
int *  ok 
)

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.

Definition at line 114 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 23 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 89 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 70 of file unitparse.c.

Referenced by config_parse_interval().