45 c = malloc(strlen(s) + 1);
60 }
while (s[i - 1] != 0);
73 for (numNBS = 0, srcP = (
const char *)s; *srcP !=
'\0'; ++srcP) {
74 if (*srcP ==
' ' || *srcP ==
'\t') {
78 if ((d = (
char *)malloc((srcP - s) + numNBS + 1)) == NULL) {
81 for (d0 = d, srcP = (
const char *)s; *srcP !=
'\0'; ++srcP) {
82 if (*srcP ==
' ' || *srcP ==
'\t') {
102 return S_ISDIR(s.st_mode) ? true :
false;
113 size_t fname_len = 0;
117 if ((nelm == 0) || (nelm > 16)) {
120 if ((*str != NULL) && (size == NULL)) {
130 for (elm_idx = 0; elm_idx < nelm; elm_idx++) {
131 elm[elm_idx] = va_arg(ap,
const char *);
133 if (elm[elm_idx] == NULL) {
136 elm_len[elm_idx] = strlen(elm[elm_idx]);
137 fname_len += elm_len[elm_idx];
144 if (fname_len > *size) {
148 fname = malloc(fname_len);
156 for (elm_idx = 0; elm_idx < nelm; elm_idx++) {
157 memmove(curp, elm[elm_idx], elm_len[elm_idx]);
158 curp += elm_len[elm_idx];
160 if (curp[-1] != sep) {
167 assert((curp - fname) <= (
int)fname_len);
206#define BYTESIZE_BUFFER_SIZE 32
213 static char *curbuffer = buffer3;
221 exbibytes } unit = bytes;
222 static const char *
const units[] = {
230 double bytesize = (double)bsize;
233 if (curbuffer == buffer1)
235 else if (curbuffer == buffer2)
240 if (bytesize > 1024) {
245 if (bytesize > 1024) {
250 if (bytesize > 1024) {
255 if (bytesize > 1024) {
260 if (bytesize > 1024) {
265 if (bytesize > 1024) {
293unsigned long long int strtoull(
const char *nptr,
char **endptr,
int base)
295 return (
unsigned long long int)strtoul(nptr, endptr,
base);
301#ifndef HAVE_STRCASESTR
312 size_t needle_len = strlen(needle);
313 const char * last_start = haystack + (strlen(haystack) - needle_len);
315 while (haystack <= last_start) {
316 if (strncasecmp(haystack, needle, needle_len) == 0)
317 return (
char *)haystack;
337 for (len = 0; len != n && s[len]; len++)
340 s2 = malloc(len + 1);
355int alphasort(
const struct dirent **d1,
const struct dirent **d2)
357 return strcasecmp((*d1)->d_name, (*d2)->d_name);
361int scandir(
const char *dir,
struct dirent ***namelist,
362 int (*sel)(
const struct dirent *),
363 int (*
compar)(
const struct dirent **,
const struct dirent **))
365 struct dirent **entlist = NULL;
366 struct dirent **entlist_temp = NULL;
367 struct dirent *ent = NULL, *new_ent;
377 while ((ent = readdir(d)) != NULL) {
379 if (sel && (*sel)(ent) == 0)
388 entlist_temp = realloc(entlist,
389 sizeof(*entlist) * alloc_n);
390 if (entlist_temp == NULL) {
393 entlist = entlist_temp;
397 new_ent = malloc(
sizeof(*new_ent));
398 if (new_ent == NULL) {
401 memcpy(new_ent, ent,
sizeof(
struct dirent));
404 entlist[n] = new_ent;
412 if (
compar != NULL && n > 1)
413 qsort(entlist, n,
sizeof(*entlist),
414 (
int (*)(
const void *,
const void *))
compar);
420 if (entlist != NULL) {
422 for (i = 0; i < n; i++) {
438#ifndef HAVE_STRCHRNUL
445 const unsigned char *us = (
const unsigned char *) s;
447 while (*us != c_in && *us !=
'\0')
460 strcpy(buf->
sysname,
"windows");
462 strcpy(buf->
release,
"release");
463 strcpy(buf->
version,
"version");
476 if (resolved_path == NULL) {
480 strcpy(resolved_path,
path);
491 unsigned int b1, b2, b3, b4;
494 if (strspn(cp,
"0123456789.") < strlen(cp))
497 if (sscanf(cp,
"%3u.%3u.%3u.%3u%c", &b1, &b2, &b3, &b4, &c) != 4)
500 if ((b1 > 255) || (b2 > 255) || (b3 > 255) || (b4 > 255))
503 inp->s_addr = b4 << 24 | b3 << 16 | b2 << 8 | b1;
520 else if (af == AF_INET6) {
550 char *restrict errbuf,
553 if ((errbuf != NULL) && (errbuf_size != 0)) {
561 const char *restrict
string,
directory traversal and entry
nserror
Enumeration of error codes.
@ NSERROR_NOSPACE
Insufficient space.
@ NSERROR_BAD_PARAMETER
Bad Parameter.
@ NSERROR_NOMEM
Memory exhaustion.
static int compar(const void *va, const void *vb)
Quick sort comparison.
internet structures and defines
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Localised message support (interface).
Interface to utility string handling.
system information filled in by uname derived from posix spec.
char release[65]
OS release (e.g., "2.6.28")
char nodename[65]
Name within "some implementation-defined network".
char version[65]
OS version.
char machine[65]
Hardware identifier.
char sysname[65]
Operating system name (e.g., "Linux")
Interface to a number of general purpose functionality.
char * realpath(const char *path, char *resolved_path)
char * cnv_space2nbsp(const char *s)
Converts NUL terminated UTF-8 encoded string s containing zero or more spaces (char 32) or TABs (char...
bool is_dir(const char *path)
Check if a directory exists.
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.
int inet_aton(const char *cp, struct in_addr *inp)
char * squash_whitespace(const char *s)
Replace consecutive whitespace with a single space.
int alphasort(const struct dirent **d1, const struct dirent **d2)
#define BYTESIZE_BUFFER_SIZE
The size of buffers within human_friendly_bytesize.
char * human_friendly_bytesize(unsigned long long int bsize)
Create a human readable representation of a size in bytes.
char * strchrnul(const char *s, int c_in)
Find the first occurrence of C in S or the final NUL byte.
int uname(struct utsname *buf)
Get the system information.
size_t regerror(int errorcode, const regex_t *restrict preg, char *restrict errbuf, size_t errbuf_size)
unsigned long long int strtoull(const char *nptr, char **endptr, int base)
string to unsigned long long
int regexec(const regex_t *restrict preg, const char *restrict string, size_t nmatch, regmatch_t pmatch[restrict], int eflags)
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.
char * strcasestr(const char *haystack, const char *needle)
Case insensitive strstr implementation.
int scandir(const char *dir, struct dirent ***namelist, int(*sel)(const struct dirent *), int(*compar)(const struct dirent **, const struct dirent **))
int inet_pton(int af, const char *src, void *dst)
void regfree(regex_t *preg)
char * strndup(const char *s, size_t n)
Duplicate up to n characters of a string.
int regcomp(regex_t *restrict preg, const char *restrictregex, int cflags)
Interface to uts API to get name and information about current kernel.
static nserror path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.