45 #ifdef HAVE_SYSEXITS_H 60 { 0xff & EX_USAGE,
"Bad usage." },
63 { 0xff & EX_DATAERR,
"Data format error." },
66 { 0xff & EX_NOINPUT,
"Can't open input." },
69 { 0xff & EX_NOUSER,
"User unknown." },
72 { 0xff & EX_NOHOST,
"Host unknown." },
75 { 0xff & EX_UNAVAILABLE,
"Service unavailable." },
78 { 0xff & EX_SOFTWARE,
"Internal error." },
81 { 0xff & EX_OSERR,
"Operating system error." },
84 { 0xff & EX_OSFILE,
"System file missing." },
87 { 0xff & EX_CANTCREAT,
"Can't create output." },
90 { 0xff & EX_IOERR,
"I/O error." },
93 { 0xff & EX_TEMPFAIL,
"Deferred." },
96 { 0xff & EX_PROTOCOL,
"Remote protocol error." },
99 { 0xff & EX_NOPERM,
"Insufficient permission." },
102 { 0xff & EX_NOPERM,
"Local configuration error." },
104 {
S_ERR,
"Exec error." },
116 if (err_num == sysexits[i].err_num)
131 static size_t startswith(
const char *str,
const char *prefix,
bool match_case)
133 if (!str || (str[0] ==
'\0') || !prefix || (prefix[0] ==
'\0'))
138 const char *saved_prefix = prefix;
139 for (; *str && *prefix; str++, prefix++)
144 if (!match_case && tolower(*str) == tolower(*prefix))
150 return (*prefix ==
'\0') ? (prefix - saved_prefix) : 0;
193 if (!str || (*str ==
'\0'))
199 long res = strtol(str, &e, 10);
202 if (((res == LONG_MIN) || (res == LONG_MAX)) && (errno == ERANGE))
204 if (e && (*e !=
'\0'))
231 if ((res < SHRT_MIN) || (res > SHRT_MAX))
261 if ((res < INT_MIN) || (res > INT_MAX))
287 unsigned long res = 0;
295 *dst = (
unsigned int) res;
316 if (!str || (*str ==
'\0'))
322 unsigned long res = strtoul(str, &e, 10);
325 if ((res == ULONG_MAX) && (errno == ERANGE))
327 if (e && (*e !=
'\0'))
348 if (!str || (*str ==
'\0'))
354 unsigned long long res = strtoull(str, &e, 10);
357 if ((res == ULLONG_MAX) && (errno == ERANGE))
359 if (e && (*e !=
'\0'))
372 if (!str || (*str ==
'\0'))
387 if (!buf || (buflen == 0) || !s)
394 for (; (*buf !=
'\0') && buflen; buflen--)
396 for (; *s && buflen; buflen--)
416 if (!d || (l == 0) || !s)
425 for (; *s && l && sl; l--, sl--)
450 const char *tmp = *p;
474 mutt_mem_realloc(str, ssz + (((ssz > 0) && (sep !=
'\0')) ? 1 : 0) + sz + 1);
475 char *p = *str + ssz;
476 if ((ssz > 0) && (sep !=
'\0'))
478 memcpy(p, item, sz + 1);
513 *p = tolower((
unsigned char) *p);
530 if (!src || !dest || (len == 0) || (dsize == 0))
533 if (len > (dsize - 1))
535 memcpy(dest, src, len);
554 memcpy(p, begin, len);
633 return a ? strlen(a) : 0;
663 const char *p = NULL, *q = NULL;
665 while (*(p = haystack))
668 *p && *q && (tolower((
unsigned char) *p) == tolower((
unsigned char) *q));
718 if (!dest || (dsize == 0))
727 while ((--dsize > 0) && (*src !=
'\0'))
761 return c && strchr(
" \t\r\n", c);
784 for (; p < (s + n); p++)
786 if (!strchr(
" \t\r\n", *p))
793 if ((len != 0) && strchr(
"\r\n", *(p - 1)))
812 const char *p = s + n - 1;
818 if (strchr(
"\r\n", *p))
823 if (!strchr(
" \t\r\n", *p))
920 const char *
mutt_strn_rfind(
const char *haystack,
size_t haystack_length,
const char *needle)
922 if (!haystack || (haystack_length == 0) || !needle)
925 int needle_length = strlen(needle);
926 const char *haystack_end = haystack + haystack_length - needle_length;
928 for (
const char *p = haystack_end; p >= haystack; --p)
930 for (
size_t i = 0; i < needle_length; i++)
932 if (p[i] != needle[i])
953 for (; (*str !=
'\0') && (len > 0); str++, len--)
954 if ((*str & 0x80) != 0)
976 while (*src && strchr(
" \t\n", *src))
978 while (*src && !strchr(
" \t\n", *src))
996 const char *val = getenv(name);
997 if (val && (val[0] !=
'\0'))
1015 if (!buf || !rstr || (xlen >= buflen))
1021 if ((slen + rlen) >= buflen)
1024 memmove(buf + rlen, buf + xlen, slen + 1);
1025 memmove(buf, rstr, rlen);
1040 if (!str || !target)
1044 while ((str = (
char *) strcasestr(str, target)))
1047 memmove(str, str + target_len, 1 + strlen(str + target_len));
1054 #ifdef HAVE_VASPRINTF 1072 n = vasprintf(strp, fmt, ap);
1107 const int n = vsnprintf(*strp, rlen, fmt, ap);
1121 else if (n != rlen - 1)
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
char * mutt_str_skip_whitespace(const char *p)
Find the first non-whitespace character in a string.
static size_t startswith(const char *str, const char *prefix, bool match_case)
Check whether a string starts with a prefix.
int mutt_str_atoi(const char *str, int *dst)
Convert ASCII string to an integer.
Memory management wrappers.
char * mutt_strn_cat(char *d, size_t l, const char *s, size_t sl)
Concatenate two strings.
char * mutt_str_dup(const char *str)
Copy a string, safely.
void mutt_str_adjust(char **p)
Shrink-to-fit a string.
int mutt_str_atol(const char *str, long *dst)
Convert ASCII string to a long.
size_t mutt_str_lws_len(const char *s, size_t n)
Measure the linear-white-space at the beginning of a string.
int mutt_str_atos(const char *str, short *dst)
Convert ASCII string to a short.
int mutt_str_coll(const char *a, const char *b)
Collate two strings (compare using locale), safely.
String manipulation functions.
const char * mutt_str_getenv(const char *name)
Get an environment variable.
bool mutt_istrn_equal(const char *a, const char *b, size_t l)
Check for equality of two strings ignoring case (to a maximum), safely.
#define mutt_array_size(x)
Lookup table of error messages.
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
int mutt_istrn_cmp(const char *a, const char *b, size_t l)
Compare two strings ignoring case (to a maximum), safely.
char * mutt_strn_copy(char *dest, const char *src, size_t len, size_t dsize)
Copy a sub-string into a buffer.
char * mutt_str_lower(char *s)
Convert all characters in the string to lowercase.
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
const char * mutt_str_sysexit(int err_num)
Return a string matching an error code.
void mutt_str_remove_trailing_ws(char *s)
Trim trailing whitespace from a string.
bool mutt_str_is_ascii(const char *str, size_t len)
Is a string ASCII (7-bit)?
bool mutt_str_is_email_wsp(char c)
Is this a whitespace character (for an email header)
int mutt_istr_remall(char *str, const char *target)
Remove all occurrences of substring, ignoring case.
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
int mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
int mutt_str_atoull(const char *str, unsigned long long *dst)
Convert ASCII string to an unsigned long long.
char * mutt_str_skip_email_wsp(const char *s)
Skip over whitespace as defined by RFC5322.
void mutt_str_dequote_comment(char *s)
Un-escape characters in an email address comment.
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
bool mutt_strn_equal(const char *a, const char *b, size_t l)
Check for equality of two strings (to a maximum), safely.
char * mutt_str_cat(char *buf, size_t buflen, const char *s)
Concatenate two strings.
void mutt_exit(int code)
Leave NeoMutt NOW.
size_t mutt_str_lws_rlen(const char *s, size_t n)
Measure the linear-white-space at the end of a string.
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
const char * mutt_istr_find(const char *haystack, const char *needle)
Find first occurrence of string (ignoring case)
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
int mutt_str_atoul(const char *str, unsigned long *dst)
Convert ASCII string to an unsigned long.
bool mutt_str_inline_replace(char *buf, size_t buflen, size_t xlen, const char *rstr)
Replace the beginning of a string.
const char * mutt_strn_rfind(const char *haystack, size_t haystack_length, const char *needle)
Find last instance of a substring.
int mutt_str_asprintf(char **strp, const char *fmt,...)
void mutt_str_append_item(char **str, const char *item, char sep)
Add string to another separated by sep.
const char * mutt_str_next_word(const char *s)
Find the next word in a string.
const char * mutt_str_find_word(const char *src)
Find the end of a word (non-space)