All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions
Utilities

Collection of verious utilities that do not have a place of their own, yet. More...

Functions

size_t util_strlcpy (char *dst, const char *src, size_t dst_size)
 
size_t util_strlncat (char *dst, const char *src, size_t dst_size, size_t nchars)
 
size_t util_strlcat (char *dst, const char *src, size_t dst_size)
 
void util_strrep (char *out, size_t outsz, char *in, char *findstr, char *replacestr)
 
char * util_strsep (char **pinputstr, const char *delim)
 
void util_chomp (char *str)
 
void util_cp1252_to_utf8 (char *utf8, ssize_t utf8_sz, char *cp1252)
 
bool clipboard_set_text (char *text)
 
bool clipboard_get_text (char *text, size_t text_sz)
 
bool sys_is_admin (bool *isadmin)
 
bool sys_runas_admin (char *path)
 
bool sys_self_exe (char *path, size_t pathsz)
 
bool sys_self_elevate (void)
 
bool sys_perm_grant (char *path)
 
FILE * sys_fopen_force (char *path, char *mode)
 
bool sys_appdata_path (char *path, size_t pathsz)
 
uint64_t sys_monotime (void)
 
bool reg_read_key (char *key, char *val, void *buf, size_t buflen)
 
#define UTIL_MAX_PATH   PATH_MAX
 

Detailed Description

Collection of verious utilities that do not have a place of their own, yet.

Note
Only Windows specific functions are documented

Macro Definition Documentation

#define UTIL_MAX_PATH   PATH_MAX

Max path on Unix

Function Documentation

void util_chomp ( char *  str)

This function this function removes new-lines characters and blanks from the end of the string

Parameters
[in]strString to be chomped
void util_cp1252_to_utf8 ( char *  utf8,
ssize_t  utf8_sz,
char *  cp1252 
)

Convert a string from the CP-1252(aka Windows-1252, Latin1) codeset to UTF8, yay!

Parameters
[in]cp1252Input string in the CP-1252 encoding
[out]utf8Output UTF8 string
[out]utf8_szMaximum size of the UTF8 string
size_t util_strlcat ( char *  dst,
const char *  src,
size_t  dst_size 
)

Equivalent of the strlcat() function from the *BSD world. See util_strlcpy() for the rant.

Note
This function is just a wrapper for util_strlncat()
Parameters
[in,out]dstString that we're appending to
[in]srcString that will be appended
[in]dst_sizeMaximum size of dst
Returns
Number of bytes stored to dst
size_t util_strlcpy ( char *  dst,
const char *  src,
size_t  dst_size 
)

This is a safe string copy function, it never overflows. In the *BSD world it's know as strlcpy().

Thansk to Ulrich Drepper, these two functions probably get the re-inventing-the-wheel-over-and-over-again award.

Note
If dst is too small to hold src, it is safely truncated.
Parameters
[out]dstBuffer that will receive the string from src
[in]srcInput string
[in]dst_sizeMaximum size of dst; if a larger string is copied it is truncated and padded with '\0'
Returns
Number of bytes stored to dst (not counting the ending null char)
size_t util_strlncat ( char *  dst,
const char *  src,
size_t  dst_size,
size_t  nchars 
)

Equivalent of the strncat() except it copies the string safely while padding it with '\0'

Parameters
[in,out]dstString that we're appending to
[in]srcString that will be appended
[in]dst_sizeMaximum size of dst
[in]ncharsMaximum number of characters to copy from src
Returns
Number of bytes stored to dst
void util_strrep ( char *  out,
size_t  outsz,
char *  in,
char *  findstr,
char *  replacestr 
)

Stirng replace: Find all occurences of string findstr in string in and replace them with the string replacestr. Store the result to out

Parameters
[out]outOutput buffer where the result will be stored
[in]outszMaximum size of the output buffer
[in]inInput string, this string will be searched for findstr
[in]findstrString to find
[in]replacestrString to replace findstr with
char* util_strsep ( char **  pinputstr,
const char *  delim 
)

There's no strsep() on MinGW, so we have to implement our own

Note
This function should be equivalent to a POSIX strsep()
Parameters
[in,out]pinputstrString to scan for delim
[in]delimDelimiters