From 208714be01cbccd2b850c50146bf18369579d6cb Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 26 Mar 2008 21:29:17 +0000 Subject: [PATCH] add strcasestr util --- include/sigar_util.h | 5 +++++ src/sigar_util.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/sigar_util.h b/include/sigar_util.h index 5e2079cb..967bd6c6 100644 --- a/include/sigar_util.h +++ b/include/sigar_util.h @@ -44,6 +44,9 @@ #define sigar_isupper(c) \ (isupper(((unsigned char)(c)))) +#define sigar_tolower(c) \ + (tolower(((unsigned char)(c)))) + #ifdef WIN32 #define sigar_fileno _fileno #define sigar_isatty _isatty @@ -81,6 +84,8 @@ SIGAR_INLINE char *sigar_skip_multiple_token(char *p, int count); char *sigar_getword(char **line, char stop); +char *sigar_strcasestr(const char *s1, const char *s2); + int sigar_file2str(const char *fname, char *buffer, int buflen); int sigar_proc_file2str(char *buffer, int buflen, diff --git a/src/sigar_util.c b/src/sigar_util.c index 0d29115c..5626b3dd 100644 --- a/src/sigar_util.c +++ b/src/sigar_util.c @@ -290,6 +290,38 @@ int sigar_procfs_args_get(sigar_t *sigar, sigar_pid_t pid, #endif /* WIN32 */ +/* from httpd/server/util.c */ +char *sigar_strcasestr(const char *s1, const char *s2) +{ + char *p1, *p2; + if (*s2 == '\0') { + /* an empty s2 */ + return((char *)s1); + } + while(1) { + for ( ; (*s1 != '\0') && (sigar_tolower(*s1) != sigar_tolower(*s2)); s1++); + if (*s1 == '\0') { + return(NULL); + } + /* found first character of s2, see if the rest matches */ + p1 = (char *)s1; + p2 = (char *)s2; + for (++p1, ++p2; sigar_tolower(*p1) == sigar_tolower(*p2); ++p1, ++p2) { + if (*p1 == '\0') { + /* both strings ended together */ + return((char *)s1); + } + } + if (*p2 == '\0') { + /* second string ended, a match */ + break; + } + /* didn't find a match here, try starting at next character in s1 */ + s1++; + } + return((char *)s1); +} + int sigar_mem_calc_ram(sigar_t *sigar, sigar_mem_t *mem) { sigar_uint64_t lram = (mem->total / (1024 * 1024));