libwget-utils(3)
π libwget-utils(3) β General utility functions π
okay bestie, welcome to the libwget-utils(3) page from the Library Functions Manual. This is your one-stop glow-up for general utility functions. Let's get into it. β¨
πΈ NAME πΈ
libwget-utils β General utility functions
β¨ SYNOPSIS β¨
π§ Functions π§
size_t wget_strlcpy (char *dst, const char *src, size_t size)
ssize_t wget_strscpy (char *dst, const char *src, size_t size)
int wget_strcmp (const char *s1, const char *s2)
int wget_strcasecmp (const char *s1, const char *s2)
int wget_strcasecmp_ascii (const char *s1, const char *s2)
int wget_strncasecmp_ascii (const char *s1, const char *s2, size_t n)
char * wget_strtolower (char *s)
int wget_strncmp (const char *s1, const char *s2, size_t n)
int wget_strncasecmp (const char *s1, const char *s2, size_t n)
void wget_memtohex (const unsigned char *src, size_t src_len, char *dst, size_t dst_size)
void wget_millisleep (int ms)
long long wget_get_timemillis (void)
int wget_percent_unescape (char *src)
int wget_match_tail (const char *s, const char *tail)
int wget_match_tail_nocase (const char *s, const char *tail)
char * wget_strnglob (const char *str, size_t n, int flags)
char * wget_human_readable (char *buf, size_t bufsize, uint64_t n)
int wget_get_screen_size (int *width, int *height)
π Detailed Description π
okay so this is a collections of short routines that are used with libwget and/or Wget code. They may be useful to other developers, that is why they are exported. fr fr. π«Ά
π₯ Function Documentation π₯
size_t wget_strlcpy (char * dst, const char * src, size_t size)
Parameters
dstβ Output string buffersrcβ Input stringsizeβ Size ofdst
Returns
Length of src
Copy string src into dst with overflow checking.
This is the same as snprintf(dst,size,"%s",src) but faster and more elegant.
If src is NULL, the return value is 0 and nothing is written. If \ dst is NULL, the return value is the length of src and nothing is written.
ssize_t wget_strscpy (char * dst, const char * src, size_t size)
Parameters
dstβ Output string buffersrcβ Input stringsizeβ Size ofdst
Returns
Number of copied bytes (excluding trailing 0) or -1 when src doesn't fit into dst
Copy string src into dst with overflow checking.
If either dst is NULL or size is 0, the return value is -1 and nothing is written. If src is NULL and size is 0, the return value is -1. If src is NULL and size is >0, the return value is 0 and dst is an empty string.
Else the return value is the number of bytes copied to dst excluding the terminating 0.
int wget_strcmp (const char * s1, const char * s2)
Parameters
s1β Strings2β String
Returns
0if boths1ands2areNULL-1ifs1isNULLands2is notNULL1ifs1is notNULLands2isNULLelse it returnsstrcmp(s1, s2)
This functions compares s1 and s2 in the same way as strcmp() does, except that it also handles NULL values.
int wget_strcasecmp (const char * s1, const char * s2)
Parameters
s1β Strings2β String
Returns
0if boths1ands2areNULL-1ifs1isNULLands2is notNULL1ifs1is notNULLands2isNULLelse it returnsstrcasecmp(s1, s2)
This functions compares s1 and s2 in the same way as strcasecmp() does, except that it also handles NULL values.
int wget_strcasecmp_ascii (const char * s1, const char * s2)
Parameters
s1β Strings2β String
Returns
0if boths1ands2are the same disregarding case for ASCII lettersa-z0if boths1ands2areNULL<0ifs1isNULLands2is notNULLors1is smaller thans2>0ifs2isNULLands1is notNULLors1is greater thans2.
This functions compares s1 and s2 as ASCII strings, case insensitive. It also accepts NULL values.
int wget_strncasecmp_ascii (const char * s1, const char * s2, size_t n)
Parameters
s1β Strings2β Stringnβ Max. number of chars to compare
Returns
0if boths1ands2are the same disregarding case for ASCII lettersa-z0if boths1ands2areNULL<0ifs1isNULLands2is notNULLors1is smaller thans2>0ifs2isNULLands1is notNULLors1is greater thans2.
This functions compares s1 and s2 as ASCII strings, case insensitive, up to a max number of n chars. It also accepts NULL values.
char * wget_strtolower (char * s)
Parameters
sβ String to convert
Returns
Value of s
Converts ASCII string s to lowercase in place.
int wget_strncmp (const char * s1, const char * s2, size_t n)
Parameters
s1β Strings2β Stringnβ Max. number of chars to compare
Returns
0if boths1ands2are the same or if boths1ands2areNULL<0ifs1isNULLands2is notNULLors1is smaller thans2>0ifs2isNULLands1is notNULLors1is greater thans2.
This functions compares s1 and s2 in the same way as strncmp() does, except that it also handles NULL values.
int wget_strncasecmp (const char * s1, const char * s2, size_t n)
Parameters
s1β Strings2β Stringnβ Max. number of chars to compare
Returns
0if boths1ands2are the same disregarding case or if boths1ands2areNULL<0ifs1isNULLands2is notNULLors1is smaller thans2>0ifs2isNULLands1is notNULLors1is greater thans2.
This functions compares s1 and s2 in the same way as strncasecmp() does, except that it also handles NULL values.
void wget_memtohex (const unsigned char * src, size_t src_len, char * dst, size_t dst_size)
Parameters
srcβ Pointer to input buffersrc_lenβ Number of bytes to encodedstβ Buffer to hold the encoded stringdst_sizeβ Size ofdstin bytes
Encodes a number of bytes into a lowercase hexadecimal C string.
void wget_millisleep (int ms)
Parameters
msβ Number of milliseconds to sleep
Pause for ms milliseconds.
long long wget_get_timemillis (void )
Return the current milliseconds since the epoch.
int wget_percent_unescape (char * src)
Parameters
srcβ String to unescape
Returns
0if the string did not change1if unescaping took place
Does an inline percent unescape. Each occurrence of xx (x = hex digit) will converted into it's byte representation.
int wget_match_tail (const char * s, const char * tail)
Parameters
sβ Stringtailβ String
Returns
1 if tail matches the end of s, 0 if not
Checks if tail matches the end of the string s.
int wget_match_tail_nocase (const char * s, const char * tail)
Parameters
sβ Stringtailβ String
Returns
1 if tail matches the end of s, 0 if not
Checks if tail matches the end of the string s, disregarding the case, ASCII only.
char * wget_strnglob (const char * str, size_t n, int flags)
Parameters
strβ String to runglob()againstnβ Length of stringflagsβ Flags to pass toglob()
Returns
Expanded string after running glob
Finds a pathname by running glob(3) on the pattern in the first n bytes of globstr. Returns a newly allocated string with the first n bytes replaced with the matching pattern obtained via glob(3) if one was found. Otherwise it returns NULL.
char * wget_human_readable (char * buf, size_t bufsize, uint64_t n)
Parameters
bufβ Result bufferbufsizeβ Size of/p bufnβ Number to convert
Returns
Pointer to printable representation of n
Returns a human readable representation of n. n, a byte quantity, is converted to a human-readable abbreviated form a la sizes printed by ls -lh. The result is written into the provided buffer.
Unlike with_thousand_seps', this approximates to the nearest unit. Quoting GNU libit: "Most people visually process strings of 3-4digits effectively, but longer strings of digits are more prone tomisinterpretation. Hence, converting to an abbreviated formusually improves readability."
This intentionally uses kilobyte (KB), megabyte (MB), etc. in their original computer-related meaning of "powers of 1024". We don't use the "*bibyte" names invented in 1998, and seldom used in practice. Wikipedia's entry on "binary prefix" discusses this in some detail.
int wget_get_screen_size (int * width, int * height)
Parameters
widthβ Number of columns in terminalheightβ Number of rows in terminal
Returns
Upon successful completion, wget_get_screen_size will return 0, and the values of width and height will be set accordingly. If an error was encountered, the function will return -1 without touching the values of width and height.
Get the size of the terminal to which the output is currently printed (stderr). This function accepts two int pointers and will set their values to the width and height of the active terminal in number of columns. If either of the parameter is NULL, its value will not be set by the function.
π Author π
Generated automatically by Doxygen for wget2 from the source code.
okay bestie, that's the whole libwget-utils(3) page. It came from wget2, Version 2.3.0, and there's no date in the footer β just vibes. Mwah! πβ¨
π¦ where this page comes from
- fedora 43: wget2-devel 2.3.0-2.fc43 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND GFDL-1.3-or-later
- fedora 43: wget2-devel 2.3.0-2.fc43 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND GFDL-1.3-or-later
- fedora 44: wget2-devel 2.3.0-1.fc44
- fedora 44: wget2-devel 2.3.0-1.fc44
- fedora 44: wget2-devel 2.3.0-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND GFDL-1.3-or-later
- fedora 44: wget2-devel 2.3.0-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND GFDL-1.3-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms