Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2002 - 2006 Pekka Riikonen
+ Copyright (C) 2002 - 2007 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
return data;
}
+#ifndef HAVE_SNPRINTF
+/* Outputs string according to the `format'. */
+
+int silc_snprintf(char *str, SilcUInt32 size, const char *format, ...)
+{
+
+}
+#endif /* HAVE_SNPRINTF */
+
/* Concatenates the `src' into `dest'. If `src_len' is more than the
size of the `dest' (minus NULL at the end) the `src' will be
truncated to fit. */
silc_free(tmpstr2);
return FALSE;
}
+
+/* Splits a string containing separator `ch' and returns an array of the
+ splitted strings. */
+
+char **silc_string_split(const char *string, char ch, int *ret_count)
+{
+ char **splitted = NULL, sep[1], *item, *cp;
+ int i = 0, len;
+
+ if (!string)
+ return NULL;
+ if (!ret_count)
+ return NULL;
+
+ splitted = silc_calloc(1, sizeof(*splitted));
+ if (!splitted)
+ return NULL;
+
+ if (!strchr(string, ch)) {
+ splitted[0] = silc_memdup(string, strlen(string));
+ *ret_count = 1;
+ return splitted;
+ }
+
+ sep[0] = ch;
+ cp = (char *)string;
+ while(cp) {
+ len = strcspn(cp, sep);
+ item = silc_memdup(cp, len);
+ if (!item) {
+ silc_free(splitted);
+ return NULL;
+ }
+
+ cp += len;
+ if (strlen(cp) == 0)
+ cp = NULL;
+ else
+ cp++;
+
+ splitted = silc_realloc(splitted, (i + 1) * sizeof(*splitted));
+ if (!splitted)
+ return NULL;
+ splitted[i++] = item;
+ }
+ *ret_count = i;
+
+ return splitted;
+}