#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>Include dependency graph for strutil.c:

Go to the source code of this file.
Functions | |
| char ** | split (char *sep, char *string) |
| char * | ltrim (char *s) |
| char * | rtrim (char *s) |
| char * | trim (char *s) |
| int | count (char **a) |
| int | strpos (char *haystack, char *needle) |
|
|
count returns the count of strings in an array split with split Definition at line 76 of file strutil.c. Referenced by dropIp(), loadModule(), and undropIp().
|
|
|
trim leading whitespace of a string, returning a pointer to the first non-space character. Definition at line 44 of file strutil.c. Referenced by trim(). 00044 { 00045 char *p = s; 00046 if(s == NULL || *s == '\0') 00047 return s; 00048 while(isspace(*p)) 00049 p++; 00050 return p; 00051 }
|
|
|
trim trailing whitespace from a string returning a pointer to the string. Definition at line 55 of file strutil.c. Referenced by trim(). 00055 { 00056 char *p; 00057 if(s == NULL || *s == '\0') 00058 return s; 00059 p = s; 00060 p = ((char *)&s[strlen(s)-1]); 00061 while(isspace(*p)) 00062 p--; 00063 *++p = '\0'; 00064 return s; 00065 }
|
|
||||||||||||
|
split a string into an array of strings delimited by sep. Returns pointer-to-pointer-char on success and NULL on failure. Definition at line 17 of file strutil.c. Referenced by loadModule(), main(), and readConfig(). 00017 { 00018 char **array = NULL; 00019 int ap, cnt = 0; 00020 char *p, *s; 00021 00022 if((s = strdup(string)) == NULL) 00023 return NULL; 00024 00025 p = strtok(s,sep); 00026 00027 while(p != NULL) { 00028 ap = cnt++; 00029 if((array = realloc(array,((sizeof(char *))*cnt+1))) == NULL) { 00030 free(s); 00031 return NULL; 00032 } 00033 array[ap] = p; 00034 array[cnt] = NULL; 00035 p = strtok(NULL,sep); 00036 } 00037 return array; 00038 }
|
|
||||||||||||
|
strpos returns the position of the string needle in haystack Definition at line 85 of file strutil.c. Referenced by replaceIp(). 00085 { 00086 int i; 00087 int nlen = strlen(needle); 00088 for(i = 0; i < strlen(haystack); i++) 00089 if(strncmp(&haystack[i],needle,nlen) == 0) 00090 return i; 00091 return -1; 00092 }
|
|
|
trim leading and trailing whitespace from a string returning a pointer to the trimmed string Definition at line 70 of file strutil.c. References ltrim(), and rtrim(). Referenced by loadPatterns(), main(), readConfig(), and secwatch().
Here is the call graph for this function: ![]() |
1.4.6