add strcasestr util
This commit is contained in:
parent
bf4507f341
commit
208714be01
@ -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,
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user