NetSurf
|
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "utils/messages.h"
#include "utils/dirent.h"
#include "utils/inet.h"
#include "utils/utils.h"
#include <stdlib.h>
#include "utils/utsname.h"
#include "utils/regex.h"
Go to the source code of this file.
Macros | |
#define | BYTESIZE_BUFFER_SIZE 32 |
The size of buffers within human_friendly_bytesize. More... | |
Functions | |
char * | squash_whitespace (const char *s) |
Replace consecutive whitespace with a single space. More... | |
char * | cnv_space2nbsp (const char *s) |
Converts NUL terminated UTF-8 encoded string s containing zero or more spaces (char 32) or TABs (char 9) to non-breaking spaces (0xC2 + 0xA0 in UTF-8 encoding). More... | |
bool | is_dir (const char *path) |
Check if a directory exists. More... | |
nserror | vsnstrjoin (char **str, size_t *size, char sep, size_t nelm, va_list ap) |
Generate a string from one or more component elements separated with a single value. More... | |
nserror | snstrjoin (char **str, size_t *size, char sep, size_t nelm,...) |
Generate a string from one or more component elements separated with a single value. More... | |
char * | human_friendly_bytesize (unsigned long long int bsize) |
Create a human readable representation of a size in bytes. More... | |
unsigned long long int | strtoull (const char *nptr, char **endptr, int base) |
string to unsigned long long More... | |
char * | strcasestr (const char *haystack, const char *needle) |
Case insensitive strstr implementation. More... | |
char * | strndup (const char *s, size_t n) |
Duplicate up to n characters of a string. More... | |
int | alphasort (const struct dirent **d1, const struct dirent **d2) |
int | scandir (const char *dir, struct dirent ***namelist, int(*sel)(const struct dirent *), int(*compar)(const struct dirent **, const struct dirent **)) |
char * | strchrnul (const char *s, int c_in) |
Find the first occurrence of C in S or the final NUL byte. More... | |
int | uname (struct utsname *buf) |
Get the system information. More... | |
char * | realpath (const char *path, char *resolved_path) |
int | inet_aton (const char *cp, struct in_addr *inp) |
int | inet_pton (int af, const char *src, void *dst) |
int | regcomp (regex_t *restrict preg, const char *restrictregex, int cflags) |
size_t | regerror (int errorcode, const regex_t *restrict preg, char *restrict errbuf, size_t errbuf_size) |
int | regexec (const regex_t *restrict preg, const char *restrict string, size_t nmatch, regmatch_t pmatch[restrict], int eflags) |
void | regfree (regex_t *preg) |
#define BYTESIZE_BUFFER_SIZE 32 |
The size of buffers within human_friendly_bytesize.
We can have a fairly good estimate of the output buffers maximum length.
The unsigned long long int can store a value representing a maximum size of 16 EiB (exibytes). Therefore the greatest space required is to represent 1023 PiB. Currently that would be represented as "1023.00PiBytes" in english giving a 15 byte length including a null terminator. Ideally we would be able to accurately know this length for other languages, in the mean time a largeish buffer size is selected and should suffice.
int alphasort | ( | const struct dirent ** | d1, |
const struct dirent ** | d2 | ||
) |
char * cnv_space2nbsp | ( | const char * | s | ) |
Converts NUL terminated UTF-8 encoded string s containing zero or more spaces (char 32) or TABs (char 9) to non-breaking spaces (0xC2 + 0xA0 in UTF-8 encoding).
Caller needs to free() result. Returns NULL in case of error. No checking is done on validness of the UTF-8 input string.
Definition at line 67 of file utils.c.
Referenced by box_select_add_option(), and ro_gui_window_prepare_form_select_menu().
char * human_friendly_bytesize | ( | unsigned long long int | bytesize | ) |
Create a human readable representation of a size in bytes.
Does a simple conversion which assumes the user speaks English. The buffer returned is one of three static ones so may change each time this call is made. Don't store the buffer for later use. It's done this way for convenience and to fight possible memory leaks, it is not necessarily pretty.
bytesize | The size in bytes. |
Definition at line 209 of file utils.c.
References BYTESIZE_BUFFER_SIZE, and messages_get().
Referenced by ami_download_check_overwrite(), fetch_curl_progress(), gui_download_window_create(), gui_download_window_data(), gui_download_window_done(), NSDownloadWindow::NSDownloadWindow(), nsgtk_download_info_to_string(), nsgtk_download_store_update_item(), nsws_download_update_label(), NSDownloadWindow::Progress(), and ro_gui_download_update_status().
int inet_aton | ( | const char * | cp, |
struct in_addr * | inp | ||
) |
Definition at line 489 of file utils.c.
Referenced by inet_pton(), and urldb__host_is_ip_address().
int inet_pton | ( | int | af, |
const char * | src, | ||
void * | dst | ||
) |
Definition at line 512 of file utils.c.
References EAFNOSUPPORT, and inet_aton().
Referenced by urldb__host_is_ip_address().
bool is_dir | ( | const char * | path | ) |
Check if a directory exists.
Definition at line 94 of file utils.c.
References path().
Referenced by filename_create_directory(), handle_filesystem_select_button(), menu_save_page(), ro_gui_choose_language(), and ro_gui_default_language().
char * realpath | ( | const char * | path, |
char * | resolved_path | ||
) |
int regcomp | ( | regex_t *restrict | preg, |
const char * | restrictregex, | ||
int | cflags | ||
) |
Definition at line 542 of file utils.c.
Referenced by regcomp_wrapper().
size_t regerror | ( | int | errorcode, |
const regex_t *restrict | preg, | ||
char *restrict | errbuf, | ||
size_t | errbuf_size | ||
) |
Definition at line 548 of file utils.c.
Referenced by regcomp_wrapper().
int regexec | ( | const regex_t *restrict | preg, |
const char *restrict | string, | ||
size_t | nmatch, | ||
regmatch_t | pmatch[restrict], | ||
int | eflags | ||
) |
Definition at line 560 of file utils.c.
References REG_NOMATCH.
Referenced by snregexec().
void regfree | ( | regex_t * | preg | ) |
Definition at line 569 of file utils.c.
Referenced by save_complete_finalise().
int scandir | ( | const char * | dir, |
struct dirent *** | namelist, | ||
int(*)(const struct dirent *) | sel, | ||
int(*)(const struct dirent **, const struct dirent **) | compar | ||
) |
nserror snstrjoin | ( | char ** | str, |
size_t * | size, | ||
char | sep, | ||
size_t | nelm, | ||
... | |||
) |
Generate a string from one or more component elements separated with a single value.
This is similar in intent to the Perl join function creating a single delimited string from an array of several.
[in,out] | str | pointer to string pointer if this is NULL enough storage will be allocated for the complete path. |
[in,out] | size | The size of the space available if str not NULL on input and if not NULL set to the total output length on output. |
[in] | sep | The character to separate the elements with. |
[in] | nelm | The number of elements up to a maximum of 16. |
[in] | ... | The elements of the path as string pointers. |
Definition at line 179 of file utils.c.
References vsnstrjoin().
char * squash_whitespace | ( | const char * | s | ) |
Replace consecutive whitespace with a single space.
s | source string |
Definition at line 38 of file utils.c.
Referenced by box_construct_element(), box_construct_text(), box_image(), box_select_add_option(), and html_process_title().
char * strcasestr | ( | const char * | haystack, |
const char * | needle | ||
) |
Case insensitive strstr implementation.
haystack | String to search in |
needle | String to look for |
Definition at line 310 of file utils.c.
Referenced by html_create_style_element(), html_css_process_link(), html_css_process_style(), ro_gui_wimp_desktop_font(), and treeview__search_walk_cb().
char * strchrnul | ( | const char * | s, |
int | c_in | ||
) |
char * strndup | ( | const char * | s, |
size_t | n | ||
) |
Duplicate up to n characters of a string.
Definition at line 332 of file utils.c.
Referenced by box_textarea_callback(), fetch_data_process(), form_acceptable_charset(), form_gadget_sync_with_dom(), gui_default_utf8(), html_process_inserted_meta(), llcache_fetch_split_header(), parse_button_element(), parse_form_element(), parse_input_element(), parse_select_element(), parse_textarea_element(), ro_url_message_received(), save_complete_rewrite_stylesheet_urls(), urldb_parse_cookie(), utf8_convert(), utf8_from_local_encoding(), and utf8_to_local_encoding().
unsigned long long int strtoull | ( | const char * | nptr, |
char ** | endptr, | ||
int | base | ||
) |
string to unsigned long long
Definition at line 293 of file utils.c.
References base.
Referenced by download_context_process_headers().
int uname | ( | struct utsname * | buf | ) |
Get the system information.
buf | the buffer to fill with the information. |
Definition at line 459 of file utils.c.
References utsname::machine, utsname::nodename, utsname::release, utsname::sysname, and utsname::version.
Referenced by nslog_init(), and user_agent_build_string().
nserror vsnstrjoin | ( | char ** | str, |
size_t * | size, | ||
char | sep, | ||
size_t | nelm, | ||
va_list | ap | ||
) |
Generate a string from one or more component elements separated with a single value.
This is similar in intent to the perl join function creating a single delimited string from an array of several.
[in,out] | str | pointer to string pointer if this is NULL enough storage will be allocated for the complete path. |
[in,out] | size | The size of the space available if str not NULL on input and if not NULL set to the total output length on output. |
[in] | sep | The character to separate the elements with. |
[in] | nelm | The number of elements up to a maximum of 16. |
[in] | ap | The elements of the path as string pointers. |
Definition at line 107 of file utils.c.
References NSERROR_BAD_PARAMETER, NSERROR_NOMEM, NSERROR_NOSPACE, and NSERROR_OK.
Referenced by atari_mkpath(), posix_vmkpath(), snstrjoin(), and windows_mkpath().