diff options
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 29 |
1 files changed, 28 insertions, 1 deletions
@@ -110,7 +110,7 @@ void strlower(char *dest, size_t destlen, const char *src) int isempty(const char *string) { - return string && string[0] == '\0'; + return !string || string[0] == '\0'; } const char * strncpy_omit(char* dest, const char* src, size_t n, int (*omit_func)(int)) @@ -137,6 +137,30 @@ int omit_unprintables(int c) { return c>= '\x00' && c <= '\x1f'; } int omit_shellescapes(int c) { return strchr(shellescapes, c) != NULL; } int omit_specialchars(int c) { return omit_unprintables(c) || omit_shellescapes(c); } int omit_whitespace(int c) { return c == ' ' || c == '\t'; } +int omit_whitespace_newline(int c) { return omit_whitespace(c) || c == '\n'; } + +#ifndef HAVE_STRCASESTR +char * +strcasestr (const char *haystack, const char *needle) +{ + char *p, *startn = 0, *np = 0; + + for (p = haystack; *p; p++) { + if (np) { + if (toupper(*p) == toupper(*np)) { + if (!*++np) + return startn; + } else + np = 0; + } else if (toupper(*p) == toupper(*needle)) { + np = needle + 1; + startn = p; + } + } + + return 0; +} +#endif size_t strlcpy(char *dest, const char *src, size_t size) { @@ -248,6 +272,9 @@ const char * strncpy_tochar(char *dest, const char *src, size_t max, const char { const char *psrc = src; char *pdest = dest; + if (!*psrc) { + return NULL; + } while (*psrc && --max > 0 && !strchr(stopchars, *psrc)) { *pdest = *psrc; pdest++; |