Classes | |
class | Ratio |
Class representing a ratio. More... | |
class | cstring |
A smart pointer class for C strings. More... | |
class | insensitive_less |
Functor used for case-insensitive comparison between two strings. More... | |
Enumerations | |
enum | { ctNone = 0, ctLowerCase = 1, ctUpperCase = 2 } |
Possible transformations for crc*_str() functions. More... | |
Functions | |
void | absolute_path (char *buf, size_t len, char const *default_dir, char const *filename) |
Fills buf with the absolute path to filename. | |
cstring | absolute_path (char const *default_dir, char const *filename) |
Generates a string with the absolute path to filename. | |
std::string | absolute_path (std::string const &default_dir, std::string const &filename) |
Same as absolute_path(char const *, char const *), but with std::string's. | |
size_t | base64_decode (char const *input, size_t input_len, char *output) |
Decodes the input from base64. | |
size_t | base64_encode (char const *input, size_t input_len, char *output) |
Encodes the input in base64. | |
size_t | base64_decode_str (char const *input, size_t input_len, char *output) |
Like base64_decode, but the output buffer will be NULL terminated. | |
size_t | base64_encode_str (char const *input, size_t input_len, char *output) |
Like base64_encode, but the output buffer will be NULL terminated. | |
uint16_t | crc16 (char const *buf, size_t len, uint16_t start=0) |
Computes the CRC16 checksum of the given buffer. | |
uint16_t | crc16_str (char const *s, int trans=ctNone) |
Computes the CRC16 checksum of a NULL-terminated string. | |
uint32_t | crc32 (char const *buf, size_t len, uint32_t start=0xFFFFFFFF, bool last=true) |
Computes the CRC32 checksum of the given buffer. | |
uint32_t | crc32_str (char const *s, int trans=ctNone) |
Computes the CRC32 checksum of a NULL-terminated string. | |
uint16_t | crc_ccitt (char const *buf, size_t len, uint16_t start=0xFFFF) |
Computes the CRC-CCITT checksum of the given buffer. | |
uint16_t | crc_ccitt_str (char const *s, int trans=ctNone) |
Computes the CRC-CCITT checksum of a NULL-terminated string. | |
uint16_t | crc_dnp (char const *buf, size_t len, uint16_t start=0, bool last=true) |
Computes the CRC-DNP checksum of the given buffer. | |
uint16_t | crc_dnp_str (char const *s, int trans=ctNone) |
Computes the CRC-DNP checksum of a NULL-terminated string. | |
char * | duration_expr (char *buf, size_t len, time_t secs) |
Converts a number of seconds to a duration expression. | |
bool | duration_scan (char const *expr, time_t *secs) |
Scans a string expression of a duration. | |
bool | dir_exists (char const *dirname) |
Determines whether the given directory exists. | |
bool | file_exists (char const *filename) |
Determines whether the given file exists. | |
bool | match (char const *pattern, char const *str, bool cs=false) |
Matches a string against a pattern. | |
bool | irc_match (char const *pattern, char const *str) |
Same as match but optimized and suited for IRC (always case-insensitive). | |
bool | simple_range (char const *expr, unsigned long *first, unsigned long *last, bool desc=false) |
Converts a simple range expression. | |
bool | complex_range (char const **expr, unsigned long *first, unsigned long *last, bool desc=false) |
Converts a complex range expression. | |
bool | recursive_mkdir (char const *pathname, mode_t mode) |
Creates a directory recursively. | |
bool | resolve_error (char *buf, size_t len, int err) |
Gets resolve error message. | |
bool | resolve_host (char const *host, struct in_addr *in, int *err) |
Resolves a hostname. | |
char * | nstrdup (char const *str) |
Duplicates a string using operator new []. | |
bool | strtol_range (long *num, char const *str, long min, long max, int base=10) |
Range checking version of strtol. | |
bool | strtoul_range (unsigned long *num, char const *str, unsigned long min, unsigned long max, int base=10) |
Range checking version of strtoul (see strtol_range). | |
Variables | |
size_t const | DOMAIN_MAX = 255 |
Maximum length for a domain name. | |
size_t const | LABEL_MAX = 63 |
Maximum length for labels of a domain name. |
anonymous enum |
cstring misc::absolute_path | ( | char const * | default_dir, | |
char const * | filename | |||
) |
Generates a string with the absolute path to filename. If filename is not an absolute path already, default_dir is prepended to it.
[in] | default_dir | The default directory to prepend if filename is not an absolute path. If this is NULL or an empty string, then the generated string is a copy of filename. |
[in] | filename | The filename for which absolute path is needed. |
void misc::absolute_path | ( | char * | buf, | |
size_t | len, | |||
char const * | default_dir, | |||
char const * | filename | |||
) |
Fills buf with the absolute path to filename (up to len characters). If filename is not an absolute path already, default_dir is prepended to it.
[out] | buf | The buffer to write to. |
[in] | len | Maximum number of characters to write. |
[in] | default_dir | Default directory to prepend if filename is not an absolute path. If this is NULL or an empty string, then the filename is copied as is to the buffer. |
[in] | filename | Filename for which absolute path is needed. |
size_t misc::base64_decode | ( | char const * | input, | |
size_t | input_len, | |||
char * | output | |||
) |
Decodes the input from base64.
[in] | input | The input buffer. |
[in] | input_len | The number of bytes in the input buffer. |
[out] | output | The output buffer, whose length must be the minimum for base64 decoding of the input buffer. |
size_t misc::base64_encode | ( | char const * | input, | |
size_t | input_len, | |||
char * | output | |||
) |
Encodes the input in base64.
[in] | input | The input buffer. |
[in] | input_len | The number of bytes in the input buffer. |
[out] | output | The output buffer, whose length must be the minimum for base64 encoding of the input buffer. |
bool misc::complex_range | ( | char const ** | expr, | |
unsigned long * | first, | |||
unsigned long * | last, | |||
bool | desc = false | |||
) |
This function is similar to simple_range(), except that it provides support for multiple ranges separated by commas (i.e. n1[-n2],n3[-n4]).
[in] | expr | A pointer to the multiple ranges expression. Each call to the function will only convert one range, but will make expr point to the start of the next range (if any), so you can call the function again to convert the next range. If expr or *expr is NULL, then *first will be set to 1 and last to ULONG_MAX. |
[out] | first | A pointer to an integer variable that will be set to the first number of the first range. |
[out] | last | A pointer to an integer variable that will be set to the last number of the first range. |
[in] | desc | Whether *last may be less than *first. |
uint16_t misc::crc16 | ( | char const * | buf, | |
size_t | len, | |||
uint16_t | start = 0 | |||
) |
Computes the CRC16 checksum of the given buffer.
[in] | buf | The buffer for which a CRC is needed. |
[in] | len | The number of bytes in the buffer. |
[in] | start | The value used as the base CRC (use either the default value if you just want to compute the CRC of the buffer, or a previously generated CRC if this is a followup call). |
uint16_t misc::crc16_str | ( | char const * | s, | |
int | trans = ctNone | |||
) |
Computes the CRC16 checksum of the given NULL-terminated string.
[in] | s | The string for which a CRC is needed. |
[in] | trans | A transformation to apply to each character in the string before it is used to compute the CRC. Possible values are ctNone, ctLowerCase and ctUpperCase. |
uint32_t misc::crc32 | ( | char const * | buf, | |
size_t | len, | |||
uint32_t | start = 0xFFFFFFFF , |
|||
bool | last = true | |||
) |
Computes the CRC32 checksum of the given buffer.
[in] | buf | The buffer for which a CRC is needed. |
[in] | len | The number of bytes in the buffer. |
[in] | start | The value used as the base CRC (use either the default value if you just want to compute the CRC of the buffer, or a previously generated CRC if this is a followup call). |
[in] | last | Whether to apply the extra computation required to complete the CRC. |
uint32_t misc::crc32_str | ( | char const * | s, | |
int | trans = ctNone | |||
) |
Computes the CRC32 checksum of the given NULL-terminated string.
[in] | s | The string for which a CRC is needed. |
[in] | trans | A transformation to apply to each character in the string before it is used to compute the CRC. Possible values are ctNone, ctLowerCase and ctUpperCase. |
uint16_t misc::crc_ccitt | ( | char const * | buf, | |
size_t | len, | |||
uint16_t | start = 0xFFFF | |||
) |
Computes the CRC-CCITT checksum of the given buffer.
[in] | buf | The buffer for which a CRC is needed. |
[in] | len | The number of bytes in the buffer. |
[in] | start | The value used as the base CRC (use either the default value if you just want to compute the CRC of the buffer, or a previously generated CRC if this is a followup call). |
uint16_t misc::crc_ccitt_str | ( | char const * | s, | |
int | trans = ctNone | |||
) |
Computes the CRC-CCITT checksum of the given NULL-terminated string.
[in] | s | The string for which a CRC is needed. |
[in] | trans | A transformation to apply to each character in the string before it is used to compute the CRC. Possible values are ctNone, ctLowerCase and ctUpperCase. |
uint16_t misc::crc_dnp | ( | char const * | buf, | |
size_t | len, | |||
uint16_t | start = 0 , |
|||
bool | last = true | |||
) |
Computes the CRC-DNP checksum of the given buffer.
[in] | buf | The buffer for which a CRC is needed. |
[in] | len | The number of bytes in the buffer. |
[in] | start | The value used as the base CRC (use either the default value if you just want to compute the CRC of the buffer, or a previously generated CRC if this is a followup call). |
[in] | last | Whether to apply the extra computation required to complete the CRC. |
uint16_t misc::crc_dnp_str | ( | char const * | s, | |
int | trans = ctNone | |||
) |
Computes the CRC-DNP checksum of the given NULL-terminated string.
[in] | s | The string for which a CRC is needed. |
[in] | trans | A transformation to apply to each character in the string before it is used to compute the CRC. Possible values are ctNone, ctLowerCase and ctUpperCase. |
bool misc::dir_exists | ( | char const * | dirname | ) |
Determines whether the given name is an existing directory.
[in] | dirname | The name of the directory to check for existence. |
char* misc::duration_expr | ( | char * | buf, | |
size_t | len, | |||
time_t | secs | |||
) |
Converts the given number of seconds to a duration expression that is suitable for the duration_scan() function.
[out] | buf | The buffer where the expression will be written. |
[in] | len | The maximum length of the buffer. |
[in] | secs | The number of seconds to convert. |
bool misc::duration_scan | ( | char const * | expr, | |
time_t * | secs | |||
) |
Scans a string expression of a duration to find the number of seconds in it, which is then copied to a caller-submitted variable.
[in] | expr | The expression of a duration. It's a number followed by one one optional letter (w for weeks, d for days, h for hours, m for minutes, s for seconds -- the default unit). Combinations are allowed, as are the use of negative numbers. |
[out] | secs | The number of seconds found. May be 0 (in that case it just checks whether the expression is valid). |
bool misc::file_exists | ( | char const * | filename | ) |
Determines whether the given name is an existing regular file.
[in] | filename | The name of the file to check for existence. |
bool misc::match | ( | char const * | pattern, | |
char const * | str, | |||
bool | cs = false | |||
) |
Matches a string against a pattern.
[in] | pattern | The pattern. The ? character in the pattern matches a single character in the string, while the * character matches any number of characters in the string. |
[in] | str | The string to match. |
[in] | cs | True if the string must be matched case-sensitively, false otherwise. |
char* misc::nstrdup | ( | char const * | str | ) |
Duplicates a string using operator new [] (instead of malloc for the standard strdup() function.
[in] | str | The string to duplicate. |
bool misc::recursive_mkdir | ( | char const * | pathname, | |
mode_t | mode | |||
) |
Creates a directory recursively (equivalent to the mkdir -p shell command).
[in] | pathname | The directory. |
[in] | mode | The permission bits of the created directories (modified by the process umask). |
bool misc::resolve_error | ( | char * | buf, | |
size_t | len, | |||
int | err | |||
) |
Gets an error message from an error number received by a previous call to a resolve_* function.
[out] | buf | Buffer receiving the error. |
[in] | len | Size of the buffer. |
[in] | err | The error number. |
bool misc::resolve_host | ( | char const * | host, | |
struct in_addr * | in, | |||
int * | err | |||
) |
Resolves a hostname, and filling a struct in_addr with the resulting IP, and an int with the error number if applicable.
[in] | host | The hostname to resolve. |
[out] | in | Pointer to the struct in_addr that will receive the IP address. |
[out] | err | Pointer to the int that will receive the error number (0 if no error number is needed). |
bool misc::simple_range | ( | char const * | expr, | |
unsigned long * | first, | |||
unsigned long * | last, | |||
bool | desc = false | |||
) |
Converts a simple range expression (in the form n1[-n2] where n1 and n2 are two non-zero positive numbers) to two unsigned long.
[in] | expr | The range expression. If it is NULL, then *first will be set to 1 and *last to ULONG_MAX. |
[out] | first | A pointer to an integer variable that will be set to the first number of the range. |
[out] | last | A pointer to an integer variable that will be set to the last number of the range. |
[in] | desc | Whether *last may be less than *first. |
bool misc::strtol_range | ( | long * | num, | |
char const * | str, | |||
long | min, | |||
long | max, | |||
int | base = 10 | |||
) |
This function converts the given character string in the same way as the C library strtol() function would, then ensures that the entire string is valid and that the computed number is in a given range.
[out] | num | A pointer to the variable that will hold the computed number. The variable is changed only if the function returns true. |
[in] | str | The string to convert. |
[in] | min | The minimum value allowed for the computed number. |
[in] | max | The maximum value allowed for the computed number. |
[in] | base | The base to use when converting the string. |