|
Defines |
| #define | srandom(x) srand(x) |
| #define | random() rand() |
| #define | RANDOM_MASK 0xffffffff |
| #define | RANDOM_MAXV RAND_MAX |
| #define | GENERATE_FILESIZE_PER_X(base) |
| #define | TM_YEAR_BASE 1900 |
| #define | GENERATE_PARSE_UNSIGNED(NAME, TYPE) |
| #define | GENERATE_PARSE_UINTX(bits) GENERATE_PARSE_UNSIGNED(CAT2(parse_uint,bits), CAT2(guint,bits)) |
| #define | REPLACE(x) { *len = CONST_STRLEN(x); return (x); } |
Functions |
| size_t | strlcpy (gchar *dst, const gchar *src, size_t dst_size) |
| | Needs to be defined if we are not using Glib 2.
|
| size_t | strlcat (gchar *dst, const gchar *src, size_t dst_size) |
| size_t | concat_strings (gchar *dst, size_t size, const gchar *s,...) |
| | Concatenates a variable number of NUL-terminated strings into ``dst''.
|
| size_t | w_concat_strings (gchar **dst_ptr, const gchar *first,...) |
| | Concatenates a variable number of NUL-terminated strings into buffer which will be allocated using walloc().
|
| gchar * | is_strprefix (const gchar *str, const gchar *prefix) |
| | Checks whether ``prefix'' is a prefix of ``str''.
|
| gchar * | is_strcaseprefix (const gchar *str, const gchar *prefix) |
| | Checks whether ``prefix'' is a prefix of ``str'' performing an case-insensitive (ASCII only) check.
|
| gboolean | file_exists (const gchar *pathname) |
| | Check for file existence.
|
| gboolean | file_does_not_exist (const gchar *pathname) |
| | Check for file non-existence.
|
| size_t | print_uint16_hex (gchar *dst, guint16 v) |
| | Prints the unsigned 16-bit value ``v'' in hexadecimal presentation as NUL-terminated string to ``dst'' and returns the length of the resulting string.
|
| guchar | dec_digit (guchar x) |
| | Converts an integer to a single decimal ASCII digit.
|
| size_t | ipv4_to_string_buf (guint32 ipv4, gchar *dst, size_t size) |
| | Converts an IPv4 address in host-endian order to a string.
|
| size_t | ipv6_to_string_buf (const uint8_t *ipv6, gchar *dst, size_t size) |
| | Prints the IPv6 address ``ipv6'' to ``dst''.
|
| const gchar * | ipv6_to_string (const guint8 *ipv6) |
| | Prints the IPv6 address ``ipv6'' to a static buffer.
|
| const gchar * | ip_to_string (guint32 ip) |
| const gchar * | hostname_port_to_string (const gchar *hostname, guint16 port) |
| guint32 | string_to_ip (const gchar *s) |
| gboolean | parse_ipv6_addr (const gchar *s, guint8 *dst, const gchar **endptr) |
| | Parses an IPv6 address.
|
| gboolean | string_to_ip_strict (const gchar *s, guint32 *addr, const gchar **endptr) |
| | A strict string to IP address conversion; when other stuff from misc.[ch] is not sufficient.
|
| gboolean | string_to_ip_port (const gchar *s, guint32 *ip_ptr, guint16 *port_ptr) |
| | Decompiles ip:port into ip and port.
|
| const gchar * | local_hostname (void) |
| size_t | str_chomp (gchar *str, size_t len) |
| | Remove antepenultimate char of string if it is a "\r" followed by "\n".
|
| gchar * | absolute_pathname (const char *file) |
| | Create an absolute path.
|
| gboolean | is_absolute_path (const char *pathname) |
| | Check whether path is an absolute path.
|
| gboolean | is_directory (const gchar *pathname) |
| | Check whether path is a directory.
|
| gboolean | is_regular (const gchar *pathname) |
| | Check whether path points to a regular file.
|
| gboolean | is_symlink (const gchar *pathname) |
| | Check whether path is a symbolic link.
|
| gint | seek_to_filepos (gint fd, filesize_t pos) |
| | A wrapper around lseek() for handling filesize_t to off_t conversion.
|
| guint | filesize_fraction (filesize_t size, filesize_t part, guint base) |
| guint | kilo (gboolean metric) |
| const gchar * | byte_suffix (gboolean metric) |
| const gchar * | scale_prefixes (gboolean metric) |
| gchar | size_scale (guint64 v, guint *q, guint *r, const gchar *s, gboolean metric) |
| | Scales v so that quotient and reminder are both in the range "0..1023".
|
| gchar | norm_size_scale (guint64 v, guint *q, guint *r, gboolean metric) |
| gchar | kib_size_scale (guint64 v, guint *q, guint *r, gboolean metric) |
| | Same as norm_size_scale_base2() but assumes v is already divided by 1024 (binary).
|
| const gchar * | short_size (guint64 size, gboolean metric) |
| const gchar * | short_html_size (guint64 size, gboolean metric) |
| | Like short_size() but with unbreakable space between the digits and unit.
|
| const gchar * | short_kb_size (guint64 size, gboolean metric) |
| const gchar * | compact_kb_size (guint32 size, gboolean metric) |
| gchar * | compact_value (gchar *buf, size_t size, guint64 v, gboolean metric) |
| gchar * | short_value (gchar *buf, size_t size, guint64 v, gboolean metric) |
| const gchar * | compact_size (guint64 size, gboolean metric) |
| const gchar * | compact_rate (guint64 rate, gboolean metric) |
| size_t | short_rate_to_string_buf (guint64 rate, gboolean metric, gchar *dst, size_t size) |
| short_string_t | short_rate_get_string (guint64 rate, gboolean metric) |
| const gchar * | short_rate (guint64 rate, gboolean metric) |
| const gchar * | short_time (time_delta_t t) |
| const gchar * | short_time_ascii (time_delta_t t) |
| const gchar * | compact_time (time_delta_t t) |
| | A variant of short_time_ascii() without whitespace.
|
| const gchar * | short_uptime (time_delta_t uptime) |
| | Alternate time formatter for uptime.
|
| size_t | guid_to_string_buf (const gchar *guid, gchar *dst, size_t size) |
| const gchar * | guid_to_string (const gchar *guid) |
| const gchar * | guid_hex_str (const gchar *guid) |
| gchar * | data_hex_str (const gchar *data, size_t len) |
| gint | hex2int (guchar c) |
| | Converts a hexadecimal char (0-9, A-F, a-f) to an integer.
|
| gint | dec2int (guchar c) |
| | Converts a decimal char (0-9) to an integer.
|
| gint | alnum2int (guchar c) |
| | Converts an alphanumeric char (0-9, A-Z, a-z) to an integer.
|
| void | hex2int_init (void) |
| | Initializes the lookup table for hex2int().
|
| void | dec2int_init (void) |
| | Initializes the lookup table for dec2int().
|
| void | alnum2int_init (void) |
| | Initializes the lookup table for alnum2int().
|
| gboolean | hex_to_guid (const gchar *hexguid, gchar *guid) |
| | Converts hexadecimal string into a GUID.
|
| gchar * | guid_base32_str (const gchar *guid) |
| | Converts GUID into its base32 representation, without the trailing padding.
|
| gchar * | base32_to_guid (const gchar *base32) |
| | Decode the base32 representation of a GUID.
|
| gchar * | sha1_to_base32_buf (const struct sha1 *sha1, gchar *dst, size_t size) |
| | Convert binary SHA1 into a base32 string.
|
| const gchar * | sha1_base32 (const struct sha1 *sha1) |
| | Convert binary SHA1 into a base32 string.
|
| const gchar * | sha1_to_string (const struct sha1 sha1) |
| size_t | sha1_to_urn_string_buf (const struct sha1 *sha1, gchar *dst, size_t size) |
| | Convert binary SHA1 into a urn:sha1:<base32> string.
|
| const gchar * | sha1_to_urn_string (const struct sha1 *sha1) |
| const gchar * | bitprint_to_urn_string (const struct sha1 *sha1, const struct tth *tth) |
| const struct sha1 * | base32_sha1 (const gchar *base32) |
| | Convert base32 string into binary SHA1.
|
| const gchar * | tth_base32 (const struct tth *tth) |
| | Convert binary TTH into a base32 string.
|
| const struct tth * | base32_tth (const gchar *base32) |
| | Convert base32 string into a binary TTH.
|
| const gchar * | timestamp_utc_to_string (time_t date) |
| | Convert time to an ISO 8601 timestamp, e.g.
|
| size_t | timestamp_to_string_buf (time_t date, gchar *dst, size_t size) |
| | Convert time to ISO 8601 date plus time, e.g.
|
| short_string_t | timestamp_get_string (time_t date) |
| const gchar * | timestamp_to_string (time_t date) |
| | Convert time to ISO 8601 date plus time, e.g.
|
| size_t | time_locale_to_string_buf (time_t t, gchar *dst, size_t size) |
| | Convert time (without the date) to a human-readable string using the time representation of the current locale.
|
| gint | tm_diff (const struct tm *a, const struct tm *b) |
| | Compute the difference in seconds between two tm structs (a - b).
|
| size_t | timestamp_rfc822_to_string_buf (time_t date, gchar *buf, size_t size) |
| | Convert time to RFC-822 style date, into supplied string buffer.
|
| const gchar * | timestamp_rfc822_to_string (time_t date) |
| | Convert time to RFC-822 style date.
|
| const gchar * | timestamp_rfc822_to_string2 (time_t date) |
| | Same as date_to_rfc822_gchar(), to be able to use the two in the same printf() line.
|
| size_t | timestamp_rfc1123_to_string_buf (time_t date, gchar *buf, size_t size) |
| | Convert time to RFC-1123 style date, into supplied string buffer.
|
| const gchar * | timestamp_rfc1123_to_string (time_t date) |
| | Convert time to RFC-1123 style date.
|
| guint32 | next_pow2 (guint32 n) |
| gint | highest_bit_set (guint32 n) |
| | Determine the highest bit set in `n', -1 if value was 0.
|
| gfloat | force_range (gfloat val, gfloat min, gfloat max) |
| | Enforce range boundaries on a given floating point number.
|
| guint32 | random_value (guint32 max) |
| guint32 | random_raw (void) |
| void | sha1_feed_ulong (SHA1Context *ctx, gulong value) |
| void | sha1_feed_double (SHA1Context *ctx, gdouble value) |
| void | sha1_feed_pointer (SHA1Context *ctx, gconstpointer p) |
| void | sha1_feed_string (SHA1Context *ctx, const gchar *s) |
| void | random_init (void) |
| | Initialize random number generator.
|
| gboolean | is_printable (const gchar *buf, gint len) |
| | Check whether buffer contains printable data, suitable for "%s" printing.
|
| void | dump_hex_line (FILE *out, const gchar *data, size_t length, size_t offset) |
| | Prints a single "dump hex" line which consists of 16 byte from data.
|
| void | dump_hex (FILE *out, const gchar *title, gconstpointer data, gint length) |
| | Displays hex & ascii lines to the terminal (for debug) Displays the "title" then the characters in "s", # of bytes to print in "b".
|
| void | locale_strlower (gchar *dst, const gchar *src) |
| | Copies ``src'' to ``dst'', converting all upper-case characters to lower-case.
|
| void | ascii_strlower (gchar *dst, const gchar *src) |
| | Copies ``src'' to ``dst'', converting all ASCII upper-case characters to ASCII lower-case.
|
| gint | ascii_strcasecmp (const gchar *s1, const gchar *s2) |
| | Same as strcasecmp() but only case-insensitive for ASCII characters.
|
| gint | ascii_strncasecmp (const gchar *s1, const gchar *s2, size_t len) |
| | Same as strncasecmp() but only case-insensitive for ASCII characters.
|
| gchar * | ascii_strcasestr (const gchar *haystack, const gchar *needle) |
| | Same as strstr() but case-insensitive with respect to ASCII characters.
|
| gint | strcmp_delimit_full (const gchar *a, const gchar *b, const gchar *delimitors, gboolean case_sensitive) |
| | Compare two strings up to the specified delimiters.
|
| gint | strcmp_delimit (const gchar *a, const gchar *b, const gchar *delimit) |
| | Compare two strings case-senstive up to the specified delimiters.
|
| gint | ascii_strcasecmp_delimit (const gchar *a, const gchar *b, const gchar *delimit) |
| | Compare two strings case-insensitive up to the specified delimiters.
|
| void | guid_random_fill (gchar *xuid) |
| | Generate a new random GUID within given `xuid'.
|
| size_t | filename_shrink (const gchar *filename, gchar *buf, size_t size) |
| | Shrinks a filename so that it fits into the given buffer.
|
| gchar * | unique_pathname (const gchar *path, const gchar *filename, gboolean(*name_is_uniq)(const gchar *pathname)) |
| size_t | utf8_truncate (const gchar *src, gchar *dst, size_t size) |
| | Copies a string into a buffer whereas the string is potentially truncated but the UTF-8 encoding is preserved.
|
| gchar * | unique_filename (const gchar *path, const gchar *name, const gchar *ext, gboolean(*name_is_uniq)(const gchar *pathname)) |
| | Determine unique filename for `file' in `path', with optional trailing extension `ext'.
|
| gboolean | char_is_space (guchar c) |
| | Allow spaces, tabs or new-lines as "spacing" chars.
|
| gboolean | char_is_safe (guchar c, gboolean strict) |
| | Nearly the same as isprint() but allows additional safe chars if !strict.
|
| gchar * | hex_escape (const gchar *name, gboolean strict) |
| | Escape all non-printable chars into the hexadecimal "\xhh" form.
|
| gboolean | escape_control_char (guchar c) |
| | Checks whether the given character is a control character that should be escaped.
|
| gchar * | control_escape (const gchar *s) |
| | Escape all ASCII control chars except LF into the hexadecimal "\xhh" form.
|
| guint | char_to_printf_escape (guchar c, gchar *esc, const char *safe_chars) |
| const gchar * | lazy_string_to_printf_escape (const gchar *src) |
| | Escapes a string so that it can be used careless with the POSIX printf tool.
|
| gboolean | string_to_ip_and_mask (const gchar *str, guint32 *ip, guint32 *netmask) |
| | Extracts the IP address into `ip' and the netmask into `netmask'.
|
| gint | do_stat (const gchar *path, struct stat *buf) |
| | Wrapper for the stat() system call.
|
| gchar * | make_pathname (const gchar *dir, const gchar *file) |
| | Create new pathname from the concatenation of the dirname and the basename of the file.
|
| gchar * | short_filename (gchar *fullname) |
| | Determine stripped down path, removing SRC_PREFIX if present.
|
| gint | create_directory (const gchar *dir, mode_t mode) |
| | Creates the given directory including sub-directories if necessary.
|
| const gchar * | filepath_basename (const gchar *pathname) |
| | Returns a pointer to the basename of the given pathname.
|
| const gchar * | filepath_directory_end (const gchar *pathname, gchar separator) |
| gchar * | filepath_directory (const gchar *pathname) |
| | Creates a copy with the given pathname with the basename cut off.
|
| gboolean | filepath_exists (const gchar *dir, const gchar *file) |
| | Check whether file given by its dirname and its basename exists.
|
| size_t | reverse_strlcpy (gchar *const dst, size_t size, const gchar *src, size_t src_len) |
| | Copies "src_len" chars from "src" to "dst" reversing their order.
|
| size_t | uint32_to_string_buf (guint32 v, gchar *dst, size_t size) |
| size_t | uint64_to_string_buf (guint64 v, gchar *dst, size_t size) |
| size_t | off_t_to_string_buf (off_t v, gchar *dst, size_t size) |
| size_t | time_t_to_string_buf (time_t v, gchar *dst, size_t size) |
| const gchar * | uint32_to_string (guint32 v) |
| const gchar * | uint64_to_string (guint64 v) |
| const gchar * | uint64_to_string2 (guint64 v) |
| const gchar * | filesize_to_string (filesize_t v) |
| const gchar * | off_t_to_string (off_t v) |
| const gchar * | time_t_to_string (time_t v) |
| gint | parse_major_minor (const gchar *src, gchar const **endptr, guint *major, guint *minor) |
| guint8 | find_common_leading (guint32 ip1, guint32 ip2) |
| | Find amount of common leading bits between two IP addresses.
|
| void | ip_range_split (guint32 lower_ip, guint32 upper_ip, cidr_split_t cb, gpointer udata) |
| | Computes the set of CIDR ranges that make up the set of IPs between two boundary IPs, included.
|
| signal_handler_t | set_signal (gint signo, signal_handler_t handler) |
| | Installs a signal handler.
|
| const gchar * | html_escape_replacement (gchar c, size_t *len) |
| size_t | html_escape (const gchar *src, gchar *dst, size_t dst_size) |
| | Copies the NUL-terminated string ``src'' to ``dst'' replacing all characters which are reserved in HTML with a replacement string.
|
| guint32 | html_decode_entity (const gchar *src, const gchar **endptr) |
| gint | canonize_path (gchar *dst, const gchar *path) |
| | Creates the canonical representation of a path.
|
| guint | compat_max_fd (void) |
| gint | compat_mkdir (const gchar *path, mode_t mode) |
| gboolean | compat_is_superuser (void) |
| int | compat_daemonize (const char *directory) |
| | Daemonizes the current process.
|
| void | compat_fadvise_sequential (int fd, off_t offset, off_t size) |
| size_t | memcmp_diff (const void *a, const void *b, size_t size) |
| | Counts the number of bytes that differ between two chunks of memory.
|
| guint32 | cpu_noise (void) |
| gchar * | normalize_dir_separators (const gchar *s) |
| | Creates a string copy with all directory separators replaced with the canonic path component separator '/' (a slash).
|
| void | set_close_on_exec (gint fd) |
| void | close_file_descriptors (const int first_fd) |
| | Closes all file descriptors greater or equal to ``first_fd''.
|
| void * | compat_memmem (const void *data, size_t data_size, const void *pattern, size_t pattern_size) |
| | Equivalent to strstr() for raw memory without NUL-termination.
|
| gboolean | need_get_non_stdio_fd (void) |
| int | get_non_stdio_fd (int fd) |
| | If we detect that stdio cannot handle file descriptors above 255, this functions tries to reassign 'fd' to a file descriptor above 255 in order to reserve lower file descriptors for stdio.
|
| void | misc_init (void) |
Variables |
| const char | hex_alphabet [] = "0123456789ABCDEF" |
| const char | hex_alphabet_lower [] = "0123456789abcdef" |
| gint8 | char2int_tabs [3][(size_t)(guchar)-1+1] |
| const gint8 * | hex2int_tab = char2int_tabs[0] |
| const gint8 * | dec2int_tab = char2int_tabs[1] |
| const gint8 * | alnum2int_tab = char2int_tabs[2] |
| const gchar | days [7][4] |
| const gchar | months [12][4] |
| const gchar | escape_char = '\\' |
| gint | do_errno |