char **silc_string_split(const char *string, char ch, int *ret_count)
{
- char **splitted = NULL, sep[1], *item, *cp;
+ char **splitted = NULL, sep[2], *item, *cp;
int i = 0, len;
- if (!string)
- return NULL;
- if (!ret_count)
+ if (!string || !ret_count) {
+ silc_set_errno(SILC_ERR_INVALID_ARGUMENT);
return NULL;
+ }
splitted = silc_calloc(1, sizeof(*splitted));
if (!splitted)
}
sep[0] = ch;
+ sep[1] = '\0';
cp = (char *)string;
- while(cp) {
+ while (cp) {
len = strcspn(cp, sep);
+ if (!len)
+ break;
+
item = silc_memdup(cp, len);
if (!item) {
silc_free(splitted);
else
cp++;
- splitted = silc_realloc(splitted, (i + 1) * sizeof(*splitted));
- if (!splitted)
- return NULL;
splitted[i++] = item;
+
+ if (cp) {
+ splitted = silc_realloc(splitted, (i + 1) * sizeof(*splitted));
+ if (!splitted)
+ return NULL;
+ }
}
*ret_count = i;
int i, len, count;
char *regex;
- if (!string)
+ if (!string) {
+ silc_set_errno(SILC_ERR_INVALID_ARGUMENT);
return NULL;
+ }
len = strlen(string);
count = 4;
char *tmp;
int len1, len2;
- if (!string1 || !string2)
+ if (!string1 || !string2) {
+ silc_set_errno(SILC_ERR_INVALID_ARGUMENT);
return NULL;
+ }
len1 = strlen(string1);
len2 = strlen(string2);
return tmp;
}
-/* Matches the two strings and returns TRUE if the strings match. */
-
-int silc_string_regex_match(const char *regex, const char *string)
-{
- regex_t preg;
- int ret = FALSE;
-
- if (regcomp(&preg, regex, REG_NOSUB | REG_EXTENDED) != 0)
- return FALSE;
-
- if (regexec(&preg, string, 0, NULL, 0) == 0)
- ret = TRUE;
-
- regfree(&preg);
-
- return ret;
-}
-
/* Do regex match to the two strings `string1' and `string2'. If the
`string2' matches the `string1' this returns TRUE. */
char *s1;
int ret = FALSE;
- if (!string1 || !string2)
+ if (!string1 || !string2) {
+ silc_set_errno(SILC_ERR_INVALID_ARGUMENT);
return ret;
+ }
s1 = silc_string_regexify(string1);
ret = silc_string_regex_match(s1, string2);