Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

lib/misc.h File Reference


Detailed Description

Misc functions.

This misc.[ch] provides several miscellaneous small routines & macros for:

Author:
Raphael Manfredi
Date:
2001-2003

#include "common.h"
#include "vmm.h"

Go to the source code of this file.

Data Structures

struct  short_string
struct  sha1
struct  tth

Defines

#define SIZE_FIELD_MAX   64
 Max size of sprintf-ed size quantity.
#define GUID_RAW_SIZE   16
 Binary representation of 128 bits.
#define GUID_HEX_SIZE   32
 Hexadecimal GUID representation.
#define GUID_BASE32_SIZE   26
 base32 GUID representation
#define g_string_printf   g_string_sprintf
#define g_strlcpy   strlcpy
#define g_strlcat   strlcat
#define CONST_STRLEN(x)   (sizeof(x) - 1)
#define set_flags(r, f)   (r |= (f))
#define clear_flags(r, f)   (r &= ~(f))
#define UINT8_HEX_BUFLEN   (sizeof "FF")
#define UINT8_DEC_BUFLEN   (sizeof "255")
#define UINT16_HEX_BUFLEN   (sizeof "01234")
#define UINT16_DEC_BUFLEN   (sizeof "65535")
#define UINT32_HEX_BUFLEN   (sizeof "012345678")
#define UINT32_DEC_BUFLEN   (sizeof "4294967295")
#define UINT64_HEX_BUFLEN   (sizeof "0123456789ABCDEF")
#define UINT64_DEC_BUFLEN   (sizeof "18446744073709551615")
#define IPV4_ADDR_BUFLEN   (sizeof "255.255.255.255")
#define IPV6_ADDR_BUFLEN   (sizeof "0001:0203:0405:0607:0809:1011:255.255.255.255")
#define TIMESTAMP_BUF_LEN   (sizeof "9999-12-31 23:59:61")
#define OFF_T_DEC_BUFLEN   (sizeof(off_t) * CHAR_BIT)
#define TIME_T_DEC_BUFLEN   (sizeof(time_t) * CHAR_BIT)
#define HOST_ADDR_BUFLEN   (MAX(IPV4_ADDR_BUFLEN, IPV6_ADDR_BUFLEN))
#define HOST_ADDR_PORT_BUFLEN   (HOST_ADDR_BUFLEN + sizeof ":[65535]")
#define port_is_valid(port)   (port != 0)
#define IS_POWER_OF_2(x)   ((x) && 0 == ((x) & ((x) - 1)))
#define DEFAULT_DIRECTORY_MODE   (S_IRWXU | S_IRGRP | S_IXGRP)
#define BINARY_SEARCH(bs_type, bs_key, bs_size, bs_cmp, bs_get_key, bs_found)
 Perform a binary search over an array.
#define BINARY_ARRAY_SORTED(bs_array, bs_type, bs_field, bs_cmp, bs_field2str)
 Ensure a table used for binary search is sorted.

Typedefs

typedef short_string short_string_t
typedef guint16 flag_t
typedef time_t time_delta_t
typedef sha1 sha1_t
typedef tth tth_t
typedef void(* signal_handler_t )(gint signo)
typedef void(* cidr_split_t )(guint32 ip, guint bits, gpointer udata)

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,...) G_GNUC_NULL_TERMINATED
 Concatenates a variable number of NUL-terminated strings into ``dst''.
size_t w_concat_strings (gchar **dst, const gchar *first,...) G_GNUC_NULL_TERMINATED
 Concatenates a variable number of NUL-terminated strings into buffer which will be allocated using walloc().
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.
guchar hex_digit (guchar x)
 Converts an integer to a single hexadecimal ASCII digit.
gint hex2int_inline (guchar c)
 Converts a hexadecimal char (0-9, A-F, a-f) to an integer.
gint dec2int_inline (guchar c)
 Converts a decimal char (0-9) to an integer.
gint alnum2int_inline (guchar c)
 Converts an alphanumeric char (0-9, A-Z, a-z) to an integer.
G_GNUC_CONST WARN_UNUSED_RESULT
gboolean 
is_ascii_blank (gint c)
 ctype-like functions that allow only ASCII characters whereas the locale would allow others.
G_GNUC_CONST WARN_UNUSED_RESULT
gboolean 
is_ascii_cntrl (gint c)
G_GNUC_CONST WARN_UNUSED_RESULT
gboolean 
is_ascii_digit (gint c)
G_GNUC_CONST WARN_UNUSED_RESULT
gboolean 
is_ascii_xdigit (gint c)
G_GNUC_CONST WARN_UNUSED_RESULT
gboolean 
is_ascii_upper (gint c)
G_GNUC_CONST WARN_UNUSED_RESULT
gboolean 
is_ascii_lower (gint c)
G_GNUC_CONST WARN_UNUSED_RESULT
gboolean 
is_ascii_alpha (gint c)
G_GNUC_CONST WARN_UNUSED_RESULT
gboolean 
is_ascii_alnum (gint c)
G_GNUC_CONST WARN_UNUSED_RESULT
gboolean 
is_ascii_space (gint c)
G_GNUC_CONST WARN_UNUSED_RESULT
gboolean 
is_ascii_graph (gint c)
G_GNUC_CONST WARN_UNUSED_RESULT
gboolean 
is_ascii_print (gint c)
G_GNUC_CONST WARN_UNUSED_RESULT
gboolean 
is_ascii_punct (gint c)
G_GNUC_CONST WARN_UNUSED_RESULT
gint 
ascii_toupper (gint c)
G_GNUC_CONST WARN_UNUSED_RESULT
gint 
ascii_tolower (gint c)
WARN_UNUSED_RESULT const gchar * g_strip_context (const gchar *id, const gchar *val)
WARN_UNUSED_RESULT gchar * skip_ascii_spaces (const gchar *s)
 Skips over all ASCII space characters starting at ``s''.
WARN_UNUSED_RESULT gchar * skip_ascii_non_spaces (const gchar *s)
 Skips over all characters which are not ASCII spaces starting at ``s''.
WARN_UNUSED_RESULT gchar * skip_ascii_alnum (const gchar *s)
 Skips over all characters which are ASCII alphanumerical characters starting at ``s''.
WARN_UNUSED_RESULT gchar * skip_ascii_blanks (const gchar *s)
 Skips over all ASCII blank characters starting at ``s''.
WARN_UNUSED_RESULT gchar * skip_dir_separators (const gchar *s)
gboolean parse_ipv6_addr (const gchar *s, uint8_t *dst, const gchar **endptr)
const gchar * ipv6_to_string (const guint8 *ipv6)
 Prints the IPv6 address ``ipv6'' to a static buffer.
size_t ipv6_to_string_buf (const guint8 *ipv6, gchar *dst, size_t size)
guint32 string_to_ip (const gchar *)
gboolean string_to_ip_strict (const gchar *s, guint32 *addr, const gchar **ep)
 A strict string to IP address conversion; when other stuff from misc.[ch] is not sufficient.
gboolean string_to_ip_and_mask (const gchar *str, guint32 *ip, guint32 *netmask)
 Extracts the IP address into `ip' and the netmask into `netmask'.
gboolean string_to_ip_port (const gchar *str, guint32 *ip, guint16 *port)
 Decompiles ip:port into ip and port.
const gchar * ip_to_string (guint32)
size_t ipv4_to_string_buf (guint32 ip, gchar *buf, size_t size)
 Converts an IPv4 address in host-endian order to a string.
const gchar * hostname_port_to_string (const gchar *hostname, guint16 port)
const gchar * local_hostname (void)
const gchar * timestamp_to_string (time_t date)
 Convert time to ISO 8601 date plus time, e.g.
const gchar * timestamp_utc_to_string (time_t date)
 Convert time to an ISO 8601 timestamp, e.g.
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.
const gchar * timestamp_rfc1123_to_string (time_t date)
 Convert time to RFC-1123 style date.
size_t timestamp_to_string_buf (time_t date, gchar *dst, size_t size)
 Convert time to ISO 8601 date plus time, e.g.
size_t time_locale_to_string_buf (time_t date, gchar *dst, size_t size)
 Convert time (without the date) to a human-readable string using the time representation of the current locale.
short_string_t timestamp_get_string (time_t date)
time_delta_t delta_time (time_t t1, time_t t0)
void time_t_check (void)
time_t time_advance (time_t t, gulong delta)
 Advances the given timestamp by delta using saturation arithmetic.
const gchar * short_time (time_delta_t s)
const gchar * short_time_ascii (time_delta_t t)
const gchar * short_uptime (time_delta_t s)
 Alternate time formatter for uptime.
const gchar * compact_time (time_delta_t t)
 A variant of short_time_ascii() without whitespace.
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 * short_rate (guint64 rate, gboolean metric)
const gchar * compact_size (guint64 size, gboolean metric)
const gchar * compact_rate (guint64 rate, gboolean metric)
const gchar * compact_kb_size (guint32 size, gboolean metric)
gchar * short_value (gchar *buf, size_t size, guint64 v, gboolean metric)
gchar * compact_value (gchar *buf, size_t size, guint64 v, gboolean metric)
short_string_t short_rate_get_string (guint64 rate, gboolean metric)
const gchar * sha1_to_string (const struct sha1 sha1)
const gchar * sha1_to_urn_string (const struct sha1 *sha1)
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 struct sha1base32_sha1 (const gchar *base32)
 Convert base32 string into binary SHA1.
int sha1_cmp (const struct sha1 *a, const struct sha1 *b)
const gchar * tth_base32 (const struct tth *tth)
 Convert binary TTH into a base32 string.
const struct tthbase32_tth (const gchar *base32)
 Convert base32 string into a binary TTH.
const gchar * bitprint_to_urn_string (const struct sha1 *, const struct tth *)
const gchar * guid_hex_str (const gchar *guid)
gboolean hex_to_guid (const gchar *hexguid, gchar *guid)
 Converts hexadecimal string into a GUID.
size_t guid_to_string_buf (const gchar *guid, gchar *dst, size_t size)
const gchar * guid_to_string (const gchar *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.
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.
gboolean file_exists (const gchar *pathname)
 Check for file existence.
gboolean file_does_not_exist (const gchar *pathname)
 Check for file non-existence.
guint32 next_pow2 (guint32 n)
G_GNUC_CONST gboolean is_pow2 (guint32 value)
 Checks whether the given value is a power of 2.
void random_init (void)
 Initialize random number generator.
guint32 random_value (guint32 max) WARN_UNUSED_RESULT
guint32 random_raw (void) WARN_UNUSED_RESULT
void guid_random_fill (gchar *xuid)
 Generate a new random GUID within given `xuid'.
void misc_init (void)
size_t str_chomp (gchar *str, size_t len)
 Remove antepenultimate char of string if it is a "\r" followed by "\n".
gint hex2int (guchar c)
 Converts a hexadecimal char (0-9, A-F, a-f) to an integer.
gboolean is_printable (const gchar *buf, gint len)
 Check whether buffer contains printable data, suitable for "%s" printing.
void dump_hex (FILE *, const gchar *, gconstpointer, gint)
 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 *, const gchar *)
 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 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.
size_t filename_shrink (const gchar *filename, gchar *buf, size_t size)
 Shrinks a filename so that it fits into the given buffer.
char * unique_filename (const gchar *path, const gchar *file, const gchar *ext, gboolean(*name_is_uniq)(const gchar *pathname))
 Determine unique filename for `file' in `path', with optional trailing extension `ext'.
gchar * hex_escape (const gchar *name, gboolean strict)
 Escape all non-printable chars into the hexadecimal "\xhh" form.
gchar * control_escape (const gchar *s)
 Escape all ASCII control chars except LF into the hexadecimal "\xhh" form.
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.
gint highest_bit_set (guint32 n) G_GNUC_CONST
 Determine the highest bit set in `n', -1 if value was 0.
gfloat force_range (gfloat value, gfloat min, gfloat max)
 Enforce range boundaries on a given floating point number.
gchar * absolute_pathname (const gchar *file)
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.
gchar * data_hex_str (const gchar *data, size_t len)
gint create_directory (const gchar *dir, mode_t mode)
 Creates the given directory including sub-directories if necessary.
gint compat_mkdir (const gchar *path, mode_t mode)
gboolean filepath_exists (const gchar *dir, const gchar *file)
 Check whether file given by its dirname and its basename exists.
const gchar * filepath_basename (const gchar *pathname)
 Returns a pointer to the basename of the given pathname.
gchar * filepath_directory (const gchar *pathname)
 Creates a copy with the given pathname with the basename cut off.
guint16 parse_uint16 (const gchar *, gchar const **, guint, gint *)
guint32 parse_uint32 (const gchar *, gchar const **, guint, gint *)
guint64 parse_uint64 (const gchar *, gchar const **, guint, gint *)
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 * off_t_to_string (off_t v)
const gchar * time_t_to_string (time_t v)
const gchar * filesize_to_string (filesize_t v)
gint parse_major_minor (const gchar *src, gchar const **endptr, guint *major, guint *minor)
gchar * is_strprefix (const gchar *s, const gchar *prefix) WARN_UNUSED_RESULT
 Checks whether ``prefix'' is a prefix of ``str''.
gchar * is_strcaseprefix (const gchar *s, const gchar *prefix) WARN_UNUSED_RESULT
 Checks whether ``prefix'' is a prefix of ``str'' performing an case-insensitive (ASCII only) check.
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)
void close_file_descriptors (const int first_fd)
 Closes all file descriptors greater or equal to ``first_fd''.
gboolean compat_is_superuser (void)
int compat_daemonize (const char *directory)
 Daemonizes the current process.
void set_close_on_exec (gint fd)
void compat_fadvise_sequential (int fd, off_t offset, off_t size)
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.
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.
signal_handler_t set_signal (gint signo, signal_handler_t handler)
 Installs a signal handler.
gchar * ascii_strcasestr (const gchar *haystack, const gchar *needle)
 Same as strstr() but case-insensitive with respect to ASCII characters.
gchar * normalize_dir_separators (const gchar *s)
 Creates a string copy with all directory separators replaced with the canonic path component separator '/' (a slash).
size_t memcmp_diff (const void *a, const void *b, size_t n)
 Counts the number of bytes that differ between two chunks of memory.
guint32 cpu_noise (void)
guint pointer_hash_func (const void *p)
guint str_case_hash_func (gconstpointer key)
gint str_case_eq_func (gconstpointer a, gconstpointer b)
size_t clamp_strlen (const gchar *src, size_t src_size)
 Determines the length of a NUL-terminated string looking only at the first "src_size" bytes.
const gchar * NULL_STRING (const gchar *s)
const gchar * EMPTY_STRING (const gchar *s)
G_GNUC_CONST guint32 swap_guint32 (guint32 i)
 Swap endianness of a guint32.
G_GNUC_CONST WARN_UNUSED_RESULT
guint8 
netmask_to_cidr (guint32 netmask)
 Converts the given IPv4 netmask in host byte order to a CIDR prefix length.
G_GNUC_CONST WARN_UNUSED_RESULT
guint32 
cidr_to_netmask (guint bits)
 Converts the CIDR prefix length to a IPv4 netmask in host byte order.
size_t round_size (size_t align, size_t n)
 Rounds ``n'' up so that it matches the given alignment ``align''.
gint do_stat (const gchar *path, struct stat *buf)
 Wrapper for the stat() system call.
gboolean is_temporary_error (gint error)
gint seek_to_filepos (gint fd, filesize_t pos)
 A wrapper around lseek() for handling filesize_t to off_t conversion.
guint filesize_per_100 (filesize_t size, filesize_t part)
guint filesize_per_1000 (filesize_t size, filesize_t part)
guint filesize_per_10000 (filesize_t size, filesize_t part)
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.
const char * print_number (char *dst, size_t size, unsigned long value)

Variables

gint do_errno


Define Documentation

#define BINARY_ARRAY_SORTED bs_array,
bs_type,
bs_field,
bs_cmp,
bs_field2str   ) 
 

Value:

G_STMT_START { \
    size_t bs_index; \
    size_t bs_size = G_N_ELEMENTS(bs_array); \
\
    for (bs_index = 1; bs_index < bs_size; bs_index++) { \
        const bs_type *prev = &bs_array[bs_index - 1]; \
        const bs_type *e = &bs_array[bs_index]; \
\
        if (bs_cmp(prev->bs_field, e->bs_field) >= 0) \
            g_error(STRINGIFY(bs_array) "[] unsorted (near item \"%s\")", \
                bs_field2str(e->bs_field)); \
    } \
} G_STMT_END
Ensure a table used for binary search is sorted.

bs_array is the (static) array to scan. bs_type is the type of bs_item bs_field is the field in the bs_item structure to compare. bs_cmp() is the comparison function to use between items bs_field2str is how one can stringify the bs_field.

Skip the first to have a previous element, tables with a single element are sorted anyway.

#define BINARY_SEARCH bs_type,
bs_key,
bs_size,
bs_cmp,
bs_get_key,
bs_found   ) 
 

Value:

G_STMT_START { \
    size_t bs_index, bs_j = 0, bs_k; \
    for (bs_k = (bs_size); bs_k != 0; bs_k >>= 1) { \
        bs_type bs_item; \
        gint bs_cmp_result; \
\
        bs_index = bs_j + (bs_k >> 1); \
        bs_item = bs_get_key(bs_index); \
        bs_cmp_result = bs_cmp(bs_item, bs_key); \
        if (0 == bs_cmp_result) {   \
            bs_found(bs_index); \
            break; \
        } else if (bs_cmp_result < 0) { \
            bs_j = bs_index + 1; \
            bs_k--; \
        } \
    } \
} G_STMT_END
Perform a binary search over an array.

bs_type is the type of bs_item bs_key is the key to lookup bs_size is the array length bs_cmp(bs_item, bs_key) is used to compare the key with the current item bs_get_key(bs_index) must return the key at bs_index bs_found(bs_index) is executed if bs_key is found

All local variables are prefixed with bs_ to prevent clashes with other visible variables.

#define clear_flags r,
 )     (r &= ~(f))
 

#define CONST_STRLEN  )     (sizeof(x) - 1)
 

#define DEFAULT_DIRECTORY_MODE   (S_IRWXU | S_IRGRP | S_IXGRP)
 

#define g_string_printf   g_string_sprintf
 

#define g_strlcat   strlcat
 

#define g_strlcpy   strlcpy
 

#define GUID_BASE32_SIZE   26
 

base32 GUID representation

#define GUID_HEX_SIZE   32
 

Hexadecimal GUID representation.

#define GUID_RAW_SIZE   16
 

Binary representation of 128 bits.

#define HOST_ADDR_BUFLEN   (MAX(IPV4_ADDR_BUFLEN, IPV6_ADDR_BUFLEN))
 

#define HOST_ADDR_PORT_BUFLEN   (HOST_ADDR_BUFLEN + sizeof ":[65535]")
 

#define IPV4_ADDR_BUFLEN   (sizeof "255.255.255.255")
 

#define IPV6_ADDR_BUFLEN   (sizeof "0001:0203:0405:0607:0809:1011:255.255.255.255")
 

#define IS_POWER_OF_2  )     ((x) && 0 == ((x) & ((x) - 1)))
 

#define OFF_T_DEC_BUFLEN   (sizeof(off_t) * CHAR_BIT)
 

#define port_is_valid port   )     (port != 0)
 

#define set_flags r,
 )     (r |= (f))
 

#define SIZE_FIELD_MAX   64
 

Max size of sprintf-ed size quantity.

#define TIME_T_DEC_BUFLEN   (sizeof(time_t) * CHAR_BIT)
 

#define TIMESTAMP_BUF_LEN   (sizeof "9999-12-31 23:59:61")
 

#define UINT16_DEC_BUFLEN   (sizeof "65535")
 

#define UINT16_HEX_BUFLEN   (sizeof "01234")
 

#define UINT32_DEC_BUFLEN   (sizeof "4294967295")
 

#define UINT32_HEX_BUFLEN   (sizeof "012345678")
 

#define UINT64_DEC_BUFLEN   (sizeof "18446744073709551615")
 

#define UINT64_HEX_BUFLEN   (sizeof "0123456789ABCDEF")
 

#define UINT8_DEC_BUFLEN   (sizeof "255")
 

#define UINT8_HEX_BUFLEN   (sizeof "FF")
 


Typedef Documentation

typedef void(* cidr_split_t)(guint32 ip, guint bits, gpointer udata)
 

typedef guint16 flag_t
 

typedef struct sha1 sha1_t
 

typedef struct short_string short_string_t
 

typedef void(* signal_handler_t)(gint signo)
 

typedef time_t time_delta_t
 

typedef struct tth tth_t
 


Function Documentation

gchar* absolute_pathname const gchar *  file  ) 
 

gint alnum2int_inline guchar  c  )  [inline, static]
 

Converts an alphanumeric char (0-9, A-Z, a-z) to an integer.

Parameters:
c the character to convert.
Returns:
0..9 for valid alphanumeric ASCII characters, -1 otherwise.

gint ascii_strcasecmp const gchar *  s1,
const gchar *  s2
 

Same as strcasecmp() but only case-insensitive for ASCII characters.

gint ascii_strcasecmp_delimit const gchar *  a,
const gchar *  b,
const gchar *  delimit
 

Compare two strings case-insensitive up to the specified delimiters.

gchar* ascii_strcasestr const gchar *  haystack,
const gchar *  needle
 

Same as strstr() but case-insensitive with respect to ASCII characters.

void ascii_strlower gchar *  dst,
const gchar *  src
 

Copies ``src'' to ``dst'', converting all ASCII upper-case characters to ASCII lower-case.

``dst'' and ``src'' may be identical but must not overlap otherwise.

gint ascii_strncasecmp const gchar *  s1,
const gchar *  s2,
size_t  len
 

Same as strncasecmp() but only case-insensitive for ASCII characters.

G_GNUC_CONST WARN_UNUSED_RESULT gint ascii_tolower gint  c  )  [inline, static]
 

G_GNUC_CONST WARN_UNUSED_RESULT gint ascii_toupper gint  c  )  [inline, static]
 

const struct sha1* base32_sha1 const gchar *  base32  ) 
 

Convert base32 string into binary SHA1.

Parameters:
base32 a buffer holding SHA1_BASE32_SIZE or more bytes.
Returns:
Returns pointer to static data or NULL if the input wasn't a validly base32 encoded SHA1.

gchar* base32_to_guid const gchar *  base32  ) 
 

Decode the base32 representation of a GUID.

Returns:
pointer to static data, or NULL if the input was not valid base32.

const struct tth* base32_tth const gchar *  base32  ) 
 

Convert base32 string into a binary TTH.

Parameters:
base32 a buffer holding TTH_BASE32_SIZE or more bytes.
Returns:
Returns pointer to static data or NULL if the input wasn't a validly base32 encoded TTH.

const gchar* bitprint_to_urn_string const struct sha1 ,
const struct tth
 

gint canonize_path gchar *  dst,
const gchar *  path
 

Creates the canonical representation of a path.

``dst'' and ``src'' may be identical but must not overlap otherwise.

Parameters:
dst the destination, must be sufficiently long.
path a NUL-terminated string representing the input path.
Returns:
zero on sucess, non-zero on failure.

TODO: Add overlap check.

G_GNUC_CONST WARN_UNUSED_RESULT guint32 cidr_to_netmask guint  bits  )  [inline, static]
 

Converts the CIDR prefix length to a IPv4 netmask in host byte order.

No checks are performed.

Parameters:
bits A value between 1..32.
Returns:
The equivalent netmask in host byte order.

size_t clamp_strlen const gchar *  src,
size_t  src_size
[inline, static]
 

Determines the length of a NUL-terminated string looking only at the first "src_size" bytes.

If src[0..size] contains no NUL byte, "src_size" is returned. Otherwise, the returned value is identical to strlen(str). Thus, it is safe to pass a possibly non-terminated buffer.

Returns:
The number of bytes in "src" before the first found NUL or src_size if there is no NUL.

void close_file_descriptors const int  first_fd  ) 
 

Closes all file descriptors greater or equal to ``first_fd''.

const gchar* compact_kb_size guint32  size,
gboolean  metric
 

Returns:
a number of Kbytes in a compact readable form

const gchar* compact_rate guint64  rate,
gboolean  metric
 

const gchar* compact_size guint64  size,
gboolean  metric
 

const gchar* compact_time time_delta_t  t  ) 
 

A variant of short_time_ascii() without whitespace.

Returns:
time spent in seconds in a consise short readable form.
Note:
The returned string is in English and ASCII encoded.

gchar* compact_value gchar *  buf,
size_t  size,
guint64  v,
gboolean  metric
 

int compat_daemonize const char *  directory  ) 
 

Daemonizes the current process.

Parameters:
directory We will chdir() to this directory. A value of NULL implies the root directory.

void compat_fadvise_sequential int  fd,
off_t  offset,
off_t  size
 

gboolean compat_is_superuser void   ) 
 

guint compat_max_fd void   ) 
 

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.

Parameters:
data The memory to scan.
data_size The length of data.
pattern The byte pattern to look for.
pattern_size The length of the pattern.
Returns:
NULL if not found. Otherwise, the start address of the first match is returned.

gint compat_mkdir const gchar *  path,
mode_t  mode
 

size_t concat_strings gchar *  dst,
size_t  size,
const gchar *  s,
  ...
 

Concatenates a variable number of NUL-terminated strings into ``dst''.

The resulting string will be NUL-terminated unless ``size'' is zero. The returned value is the length of the resulting string if ``dst'' had been large enough. If the returned value is equal to or greater than ``size'' the string is truncated. If ``size'' is zero, ``dst'' may be NULL to calculate the resulting string length.

The list of strings must be terminated by a NULL pointer. The first list element may be NULL in which case zero is returned.

Parameters:
dst the destination buffer.
size the number of bytes ``dst'' can hold.
s the first source string or NULL.
Returns:
the sum of the lengths of all passed strings.

gchar* control_escape const gchar *  s  ) 
 

Escape all ASCII control chars except LF into the hexadecimal "\xhh" form.

When a CR LF sequence is seen, the CR character is dropped.

Returns:
new escaped string, or the original string if no escaping occurred.

guint32 cpu_noise void   ) 
 

gint create_directory const gchar *  dir,
mode_t  mode
 

Creates the given directory including sub-directories if necessary.

The path must be absolute.

Parameters:
dir the pathname of the directory to create.
Returns:
On success, zero is returned. On failure, -1 is returned and errno indicates the reason.

gchar* data_hex_str const gchar *  data,
size_t  len
 

Returns:
hexadecimal string representation of "small" binary buffer.
Note:
Buffer must be less than 40 chars, or only the first 40 chars are represented with a trailing "..." added to show it is incomplete.

gint dec2int_inline guchar  c  )  [inline, static]
 

Converts a decimal char (0-9) to an integer.

Parameters:
c the character to convert.
Returns:
0..9 for valid decimal ASCII characters, -1 otherwise.

time_delta_t delta_time time_t  t1,
time_t  t0
[inline, static]
 

gint do_stat const gchar *  path,
struct stat *  buf
 

Wrapper for the stat() system call.

void dump_hex FILE *  ,
const gchar *  ,
gconstpointer  ,
gint 
 

Displays hex & ascii lines to the terminal (for debug) Displays the "title" then the characters in "s", # of bytes to print in "b".

const gchar* EMPTY_STRING const gchar *  s  )  [inline, static]
 

gboolean file_does_not_exist const gchar *  pathname  ) 
 

Check for file non-existence.

gboolean file_exists const gchar *  pathname  ) 
 

Check for file existence.

size_t filename_shrink const gchar *  filename,
gchar *  buf,
size_t  size
 

Shrinks a filename so that it fits into the given buffer.

The function tries to preserve the filename extension if there is any. The UTF-8 encoding is also preserved.

Returns:
The length of the resulting filename.

const gchar* filepath_basename const gchar *  pathname  ) 
 

Returns a pointer to the basename of the given pathname.

A slash is always considered a separator but G_DIR_SEPARATOR is considered as well. Thus "/whatever/blah\\yadda" returns a pointer to yadda iff G_DIR_SEPARATOR is a backslash and otherwise points to "blah[...]".

Parameters:
pathname A pathname to extract basename from. This may be a relative path or just a basename.
Returns:
A pointer to the basename of "pathname". The pointer points into the buffer holding pathname.

gchar* filepath_directory const gchar *  pathname  ) 
 

Creates a copy with the given pathname with the basename cut off.

A slash is always considered a separator but G_DIR_SEPARATOR is considered as well. Thus "/whatever/blah\\yadda" returns "/whatever/blah" if G_DIR_SEPARATOR is a backslash, otherwise "/whatever" is returned.

Returns:
A newly allocated string holding the given pathname with the basename cut off. If the string contained no directory separator, NULL is returned.

gboolean filepath_exists const gchar *  dir,
const gchar *  file
 

Check whether file given by its dirname and its basename exists.

guint filesize_per_100 filesize_t  size,
filesize_t  part
 

guint filesize_per_1000 filesize_t  size,
filesize_t  part
 

guint filesize_per_10000 filesize_t  size,
filesize_t  part
 

const gchar* filesize_to_string filesize_t  v  ) 
 

gfloat force_range gfloat  val,
gfloat  min,
gfloat  max
 

Enforce range boundaries on a given floating point number.

Parameters:
val The value to force within the range.
min The minimum value which val can be.
max The maximum value with val can be.
Returns:
The new value of val which will be between min and max.

WARN_UNUSED_RESULT const gchar* g_strip_context const gchar *  id,
const gchar *  val
[inline, static]
 

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.

File descriptors below 3 or above 255 are returned as-is. The original file descriptor is closed if it was reassigned. On systems which do not need this workaround, the original file descriptor is returned.

Note:
The FD_CLOEXEC flag set will be cleared on the new file descriptor if the file descriptor is successfully reassigned.
Returns:
On success a new file descriptor above 255 is returned. On failure or if reassigning was not necessary the original file descriptor is returned.

gchar* guid_base32_str const gchar *  guid  ) 
 

Converts GUID into its base32 representation, without the trailing padding.

Returns:
pointer to static data.

const gchar* guid_hex_str const gchar *  guid  ) 
 

Returns:
hexadecimal string representing given GUID.

void guid_random_fill gchar *  xuid  ) 
 

Generate a new random GUID within given `xuid'.

const gchar* guid_to_string const gchar *  guid  ) 
 

size_t guid_to_string_buf const gchar *  guid,
gchar *  dst,
size_t  size
 

gint hex2int guchar  c  ) 
 

Converts a hexadecimal char (0-9, A-F, a-f) to an integer.

Passing a character which is not a hexadecimal ASCII character causes an assertion failure.

Parameters:
c the hexadecimal ASCII character to convert.
Returns:
"0..15" for valid hexadecimal ASCII characters.

gint hex2int_inline guchar  c  )  [inline, static]
 

Converts a hexadecimal char (0-9, A-F, a-f) to an integer.

Parameters:
c the character to convert.
Returns:
0..15 for valid hexadecimal ASCII characters, -1 otherwise.

guchar hex_digit guchar  x  )  [inline, static]
 

Converts an integer to a single hexadecimal ASCII digit.

The are no checks, this is just a convenience function.

Parameters:
x An integer between 0 and 15.
Returns:
The ASCII character corresponding to the hex digit [0-9a-f].

gchar* hex_escape const gchar *  name,
gboolean  strict
 

Escape all non-printable chars into the hexadecimal "\xhh" form.

Returns:
new escaped string, or the original string if no escaping occurred.

gboolean hex_to_guid const gchar *  hexguid,
gchar *  guid
 

Converts hexadecimal string into a GUID.

Parameters:
hexguid the hexadecimal representation to convert
guid the 16-byte array into which the decoded GUID is written to
Returns:
TRUE if OK.

gint highest_bit_set guint32  n  ) 
 

Determine the highest bit set in `n', -1 if value was 0.

const gchar* hostname_port_to_string const gchar *  hostname,
guint16  port
 

guint32 html_decode_entity const gchar *  src,
const gchar **  endptr
 

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.

Parameters:
src a NUL-terminated string.
dst the destination buffer, may be NULL if ``size'' is zero.
dst_size the size in bytes of the destination buffer.
Returns:
the length in bytes of resulting string assuming size was sufficiently large.

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.

For instance, for the range 2.0.0.0 - 2.138.24.150, we have:

2.0.0.0/9, 2.128.0.0/13, 2.136.0.0/15, 2.138.0.0/20, 2.138.16.0/21, 2.138.24.0/25, 2.138.24.128/28, 2.138.24.144/30, 2.138.24.148, 2.138.24.149 and 2.138.24.150.

For each identified CIDR range, invoke the supplied callback, along with the trailing user-supplied `udata' pointer.

Parameters:
lower_ip the lower-bound IP
upper_ip the upper-bound IP
cb the callback, invoked as callback(ip, bits, udata)
udata the trailing parameter passed as-is to the callbacks

const gchar* ip_to_string guint32   ) 
 

size_t ipv4_to_string_buf guint32  ipv4,
gchar *  dst,
size_t  size
 

Converts an IPv4 address in host-endian order to a string.

Parameters:
ipv4 An 32-bit integer holding an IPv4 address in host-endian order.
dst The destination buffer to hold the resulting string.
size The size of the `dst' buffer in bytes. This should be IPV4_ADDR_BUFLEN or larger, otherwise the string will be truncated.
Returns:
The length of the resulting string assuming `size' was sufficiently large.

const gchar* ipv6_to_string const guint8 *  ipv6  ) 
 

Prints the IPv6 address ``ipv6'' to a static buffer.

Parameters:
ipv6 the IPv6 address; must point to a buffer of 16 bytes.
Returns:
a pointer to a static buffer holding a NUL-terminated string representing the given IPv6 address.

size_t ipv6_to_string_buf const guint8 *  ipv6,
gchar *  dst,
size_t  size
 

gboolean is_absolute_path const char *  pathname  ) 
 

Check whether path is an absolute path.

G_GNUC_CONST WARN_UNUSED_RESULT gboolean is_ascii_alnum gint  c  )  [inline, static]
 

G_GNUC_CONST WARN_UNUSED_RESULT gboolean is_ascii_alpha gint  c  )  [inline, static]
 

G_GNUC_CONST WARN_UNUSED_RESULT gboolean is_ascii_blank gint  c  )  [inline, static]
 

ctype-like functions that allow only ASCII characters whereas the locale would allow others.

The parameter doesn't have to be casted to (unsigned char) because these functions return false for everything out of [0..127].

GLib 2.x has similar macros/functions but defines only a subset.

G_GNUC_CONST WARN_UNUSED_RESULT gboolean is_ascii_cntrl gint  c  )  [inline, static]
 

G_GNUC_CONST WARN_UNUSED_RESULT gboolean is_ascii_digit gint  c  )  [inline, static]
 

G_GNUC_CONST WARN_UNUSED_RESULT gboolean is_ascii_graph gint  c  )  [inline, static]
 

G_GNUC_CONST WARN_UNUSED_RESULT gboolean is_ascii_lower gint  c  )  [inline, static]
 

G_GNUC_CONST WARN_UNUSED_RESULT gboolean is_ascii_print gint  c  )  [inline, static]
 

G_GNUC_CONST WARN_UNUSED_RESULT gboolean is_ascii_punct gint  c  )  [inline, static]
 

G_GNUC_CONST WARN_UNUSED_RESULT gboolean is_ascii_space gint  c  )  [inline, static]
 

G_GNUC_CONST WARN_UNUSED_RESULT gboolean is_ascii_upper gint  c  )  [inline, static]
 

G_GNUC_CONST WARN_UNUSED_RESULT gboolean is_ascii_xdigit gint  c  )  [inline, static]
 

gboolean is_directory const gchar *  pathname  ) 
 

Check whether path is a directory.

G_GNUC_CONST gboolean is_pow2 guint32  value  )  [inline, static]
 

Checks whether the given value is a power of 2.

Parameters:
value a 32-bit integer
Returns:
TRUE if ``value'' is a power of 2. Otherwise FALSE.

gboolean is_printable const gchar *  buf,
gint  len
 

Check whether buffer contains printable data, suitable for "%s" printing.

If not, consider dump_hex().

gboolean is_regular const gchar *  pathname  ) 
 

Check whether path points to a regular file.

gchar* is_strcaseprefix const gchar *  str,
const gchar *  prefix
 

Checks whether ``prefix'' is a prefix of ``str'' performing an case-insensitive (ASCII only) check.

Maybe skip_caseprefix() would be a better name.

Parameters:
str a NUL-terminated string
prefix a NUL-terminated string
Returns:
NULL, if ``prefix'' is not a prefix of ``str''. Otherwise, a pointer to the first character in ``str'' after the prefix.

gchar* is_strprefix const gchar *  str,
const gchar *  prefix
 

Checks whether ``prefix'' is a prefix of ``str''.

Maybe skip_prefix() would be a better name.

Parameters:
str a NUL-terminated string
prefix a NUL-terminated string
Returns:
NULL, if ``prefix'' is not a prefix of ``str''. Otherwise, a pointer to the first character in ``str'' after the prefix.

gboolean is_symlink const gchar *  pathname  ) 
 

Check whether path is a symbolic link.

gboolean is_temporary_error gint  error  )  [inline, static]
 

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.

Therefore it's absolutely paranoid and escapes everything but ASCII alphanumerics, dots, hyphen and underscores.

Note:
Hex sequences are always two digits long, so "\xAAA" is the same as "\xAA" "A". In C this not necessarily true and could be understood as a wide-char sequence.
Parameters:
src The string to escape.
Returns:
The escaped string. MUST NOT be freed.

const gchar* local_hostname void   ) 
 

Returns:
local host name, as pointer to static data.

void locale_strlower gchar *  dst,
const gchar *  src
 

Copies ``src'' to ``dst'', converting all upper-case characters to lower-case.

``dst'' and ``src'' may point to the same object. The conversion depends on the current locale.

gchar* make_pathname const gchar *  dir,
const gchar *  file
 

Create new pathname from the concatenation of the dirname and the basename of the file.

A directory separator is insert, unless "dir" already ends with one or "filename" starts with one.

Parameters:
dir The directory path.
file The filename.
Returns:
A newly allocated string.

size_t memcmp_diff const void *  a,
const void *  b,
size_t  n
 

Counts the number of bytes that differ between two chunks of memory.

void misc_init void   ) 
 

G_GNUC_CONST WARN_UNUSED_RESULT guint8 netmask_to_cidr guint32  netmask  )  [inline, static]
 

Converts the given IPv4 netmask in host byte order to a CIDR prefix length.

No checks are performed whether the netmask is proper and if it's not the result is unspecified.

Parameters:
netmask an IPv4 netmask in host byte order.
Returns:
The CIDR prefix length (0..32).

guint32 next_pow2 guint32  n  ) 
 

Returns:
the closest power of two greater or equal to `n'. next_pow2(0) and next_pow2(0x8.......) return 0.

gchar* normalize_dir_separators const gchar *  s  ) 
 

Creates a string copy with all directory separators replaced with the canonic path component separator '/' (a slash).

Parameters:
s a pathname.
Returns:
a newly allocated string.

const gchar* NULL_STRING const gchar *  s  )  [inline, static]
 

const gchar* off_t_to_string off_t  v  ) 
 

size_t off_t_to_string_buf off_t  v,
gchar *  dst,
size_t  size
 

gboolean parse_ipv6_addr const gchar *  s,
uint8_t *  dst,
const gchar **  endptr
 

gint parse_major_minor const gchar *  src,
gchar const **  endptr,
guint *  major,
guint *  minor
 

guint16 parse_uint16 const gchar *  ,
gchar const **  ,
guint  ,
gint * 
 

guint32 parse_uint32 const gchar *  ,
gchar const **  ,
guint  ,
gint * 
 

guint64 parse_uint64 const gchar *  ,
gchar const **  ,
guint  ,
gint * 
 

guint pointer_hash_func const void *  p  )  [inline, static]
 

const char* print_number char *  dst,
size_t  size,
unsigned long  value
[inline, static]
 

void random_init void   ) 
 

Initialize random number generator.

guint32 random_raw void   ) 
 

Returns:
random value between (0..RAND_MAX).

guint32 random_value guint32  max  ) 
 

Returns:
random value between (0..max).

size_t round_size size_t  align,
size_t  n
[inline, static]
 

Rounds ``n'' up so that it matches the given alignment ``align''.

gint seek_to_filepos gint  fd,
filesize_t  pos
 

A wrapper around lseek() for handling filesize_t to off_t conversion.

Parameters:
fd A valid file descriptor.
pos The position to seek to.
Returns:
0 on success and -1 on failure.

void set_close_on_exec gint  fd  ) 
 

signal_handler_t set_signal gint  signo,
signal_handler_t  handler
 

Installs a signal handler.

The signal handler is not reset to the default handler after delivery. If the signal is SIGALRM, the handler is installed so that interrupted system calls fail with EINTR. Handlers for other all signals are installed so that interrupted system calls are restarted instead.

Parameters:
signo the signal number.
handler the signal handler to install.
Returns:
the previous signal handler or SIG_ERR on failure.

const gchar* sha1_base32 const struct sha1 sha1  ) 
 

Convert binary SHA1 into a base32 string.

Returns:
pointer to static data.

int sha1_cmp const struct sha1 a,
const struct sha1 b
[inline, static]
 

gchar* sha1_to_base32_buf const struct sha1 sha1,
gchar *  dst,
size_t  size
 

Convert binary SHA1 into a base32 string.

Parameters:
dst The destination buffer for the string.
size The size of "dst" in bytes; should be larger than SHA1_BASE32_SIZE, otherwise the resulting string will be truncated.
Returns:
dst.

const gchar* sha1_to_string const struct sha1  sha1  ) 
 

const gchar* sha1_to_urn_string const struct sha1 sha1  ) 
 

gchar* short_filename gchar *  fullname  ) 
 

Determine stripped down path, removing SRC_PREFIX if present.

Returns:
pointer within supplied string.

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* short_rate guint64  rate,
gboolean  metric
 

short_string_t short_rate_get_string guint64  rate,
gboolean  metric
 

const gchar* short_size guint64  size,
gboolean  metric
 

const gchar* short_time time_delta_t  t  ) 
 

Returns:
time spent in seconds in a consise short readable form.
Note:
The returned string may be translated and non-ASCII.

const gchar* short_time_ascii time_delta_t  t  ) 
 

Returns:
time spent in seconds in a consise short readable form.
Note:
The returned string is in English and ASCII encoded.

const gchar* short_uptime time_delta_t  s  ) 
 

Alternate time formatter for uptime.

gchar* short_value gchar *  buf,
size_t  size,
guint64  v,
gboolean  metric
 

WARN_UNUSED_RESULT gchar* skip_ascii_alnum const gchar *  s  )  [inline, static]
 

Skips over all characters which are ASCII alphanumerical characters starting at ``s''.

Returns:
a pointer to the first space or NUL character starting from s.

WARN_UNUSED_RESULT gchar* skip_ascii_blanks const gchar *  s  )  [inline, static]
 

Skips over all ASCII blank characters starting at ``s''.

Returns:
A pointer to the first non-blank character starting from s.

WARN_UNUSED_RESULT gchar* skip_ascii_non_spaces const gchar *  s  )  [inline, static]
 

Skips over all characters which are not ASCII spaces starting at ``s''.

Returns:
a pointer to the first space or NUL character starting from s.

WARN_UNUSED_RESULT gchar* skip_ascii_spaces const gchar *  s  )  [inline, static]
 

Skips over all ASCII space characters starting at ``s''.

Returns:
a pointer to the first non-space character starting from s.

WARN_UNUSED_RESULT gchar* skip_dir_separators const gchar *  s  )  [inline, static]
 

gint str_case_eq_func gconstpointer  a,
gconstpointer  b
[inline, static]
 

guint str_case_hash_func gconstpointer  key  )  [inline, static]
 

size_t str_chomp gchar *  str,
size_t  len
 

Remove antepenultimate char of string if it is a "\r" followed by "\n".

Remove final char of string if it is a "\n" or "\r". If len is 0, compute it.

Returns:
new string length.

gint strcmp_delimit const gchar *  a,
const gchar *  b,
const gchar *  delimit
 

Compare two strings case-senstive up to the specified delimiters.

guint32 string_to_ip const gchar *  s  ) 
 

Returns:
0 if ``s'' is not a valid IPv4 address. Otherwise, the parsed IPv4 address in host byte order.

gboolean string_to_ip_and_mask const gchar *  str,
guint32 *  ip,
guint32 *  netmask
 

Extracts the IP address into `ip' and the netmask into `netmask'.

Returns:
whether the supplied string represents a valid ip/mask combination.
Accepted forms: "a.b.c.d" implies /32 "a.b.c.d/e" whereas e [1..32] "a.b.c.d/w.x.y.z"

If the IP address or the netmask is zero, the function will return FALSE.

gboolean string_to_ip_port const gchar *  s,
guint32 *  ip_ptr,
guint16 *  port_ptr
 

Decompiles ip:port into ip and port.

Leading spaces are ignored.

Returns:
TRUE if it parsed correctly, FALSE otherwise.

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.

Returns:
TRUE if ``s'' pointed to a string representation of an IPv4 address, otherwise FALSE.
If successful, ``*addr'' will be set to the IPv4 address in NATIVE byte order and ``*endptr'' will point to the character after the IPv4 address. ``addr'' and ``endptr'' may be NULL.

size_t strlcat gchar *  dst,
const gchar *  src,
size_t  dst_size
 

size_t strlcpy gchar *  dst,
const gchar *  src,
size_t  dst_size
 

Needs to be defined if we are not using Glib 2.

G_GNUC_CONST guint32 swap_guint32 guint32  i  )  [inline, static]
 

Swap endianness of a guint32.

Parameters:
i the guint32 to swap
Returns:
the value of i after swapping its byte order.

time_t time_advance time_t  t,
gulong  delta
[inline, static]
 

Advances the given timestamp by delta using saturation arithmetic.

Parameters:
t the timestamp to advance.
delta the amount of seconds to advance.
Returns:
the advanced timestamp or TIME_T_MAX.

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.

Parameters:
t time to convert.
dst buffer to hold the resulting string.
size the size of the dst buffer.
Returns:
length of the created string.

void time_t_check void   )  [inline, static]
 

const gchar* time_t_to_string time_t  v  ) 
 

size_t time_t_to_string_buf time_t  v,
gchar *  dst,
size_t  size
 

short_string_t timestamp_get_string time_t  date  ) 
 

const gchar* timestamp_rfc1123_to_string time_t  date  ) 
 

Convert time to RFC-1123 style date.

Returns:
pointer to static data.

const gchar* timestamp_rfc822_to_string time_t  date  ) 
 

Convert time to RFC-822 style date.

Returns:
pointer to static data.

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.

const gchar* timestamp_to_string time_t  date  ) 
 

Convert time to ISO 8601 date plus time, e.g.

"2005-11-10 20:21:57".

Returns:
pointer to static data.

size_t timestamp_to_string_buf time_t  date,
gchar *  dst,
size_t  size
 

Convert time to ISO 8601 date plus time, e.g.

"2002-06-09 14:54:42".

Returns:
The length of the created string.

const gchar* timestamp_utc_to_string time_t  date  ) 
 

Convert time to an ISO 8601 timestamp, e.g.

"2002-06-09T14:54:42Z".

Returns:
pointer to static data.

const gchar* tth_base32 const struct tth tth  ) 
 

Convert binary TTH into a base32 string.

Returns:
pointer to static data.

const gchar* uint32_to_string guint32  v  ) 
 

size_t uint32_to_string_buf guint32  v,
gchar *  dst,
size_t  size
 

const gchar* uint64_to_string guint64  v  ) 
 

const gchar* uint64_to_string2 guint64  v  ) 
 

size_t uint64_to_string_buf guint64  v,
gchar *  dst,
size_t  size
 

char* unique_filename const gchar *  path,
const gchar *  name,
const gchar *  ext,
gboolean(*)(const gchar *pathname name_is_uniq
 

Determine unique filename for `file' in `path', with optional trailing extension `ext'.

If no `ext' is wanted, one must supply an empty string.

Parameters:
path A directory path.
file The basename for the resulting pathname.
ext An optional filename extension to be appended to the basename.
name_is_uniq An optional callback to decide whether a created pathname is uniq. If omitted, the default is file_does_not_exist().
Returns:
the chosen unique complete filename as a pointer which must be freed.

NOTE: The generated filename must not exceed FILENAME_MAXBYTES because such a file cannot be created. In reality, it depends on the filesystem as well and the limit might be even smaller. In any case, we don't want to cut-off arbitrary bytes but at least preserve the filename extension and the (potential) UTF-8 encoding.

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

The list of strings must be terminated by a NULL pointer. The first list element may be NULL in which case 1 is returned.

Parameters:
dst_ptr if not NULL, it will point to the allocated buffer.
first the first source string or NULL.
Returns:
The sum of the lengths of all passed strings plus 1 for the the trailing NUL. Use this as size argument for wfree() to release the allocated buffer.


Variable Documentation

gint do_errno
 


Generated on Sat Jun 30 17:53:28 2007 for gtk-gnutella by  doxygen 1.3.9.1