diff options
author | Jocelyn Turcotte <jturcotte@woboq.com> | 2017-08-14 20:19:52 +0300 |
---|---|---|
committer | Jocelyn Turcotte <jturcotte@woboq.com> | 2017-08-22 12:18:22 +0300 |
commit | 28a0971cdfbb3fcb77c49df078062d8b3d756fcb (patch) | |
tree | 868937b9c7e6f4341a43cfa88e326e7223d9d9d0 /csync/src/std/c_string.c | |
parent | 5c9827a33c92dbf14b16a22e1cac3d1b324492ed (diff) |
Move csync to src/csync
Diffstat (limited to 'csync/src/std/c_string.c')
-rw-r--r-- | csync/src/std/c_string.c | 169 |
1 files changed, 0 insertions, 169 deletions
diff --git a/csync/src/std/c_string.c b/csync/src/std/c_string.c deleted file mode 100644 index 8929f2458..000000000 --- a/csync/src/std/c_string.c +++ /dev/null @@ -1,169 +0,0 @@ -/* - * cynapses libc functions - * - * Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org> - * Copyright (c) 2012-2013 by Klaas Freitag <freitag@owncloud.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "config_csync.h" - -#include <assert.h> -#include <errno.h> -#include <ctype.h> -#include <string.h> -#include <stdlib.h> - -#include <limits.h> -#include <sys/types.h> -#include <wchar.h> - -#include "c_string.h" -#include "c_path.h" -#include "c_alloc.h" -#include "c_macro.h" - -#ifdef _WIN32 -#include <windows.h> -#endif - -int c_strncasecmp(const char *a, const char *b, size_t n) { -#ifdef _WIN32 - return _strnicmp(a, b, n); -#else - return strncasecmp(a, b, n); -#endif -} - -int c_streq(const char *a, const char *b) { - register const char *s1 = a; - register const char *s2 = b; - - if (s1 == NULL || s2 == NULL) { - return 0; - } - - while (*s1 == *s2++) { - if (*s1++ == '\0') { - return 1; - } - } - - return 0; -} - -c_strlist_t *c_strlist_new(size_t size) { - c_strlist_t *strlist = NULL; - - if (size == 0) { - errno = EINVAL; - return NULL; - } - - strlist = c_malloc(sizeof(c_strlist_t)); - if (strlist == NULL) { - return NULL; - } - - strlist->vector = (char **) c_malloc(size * sizeof(char *)); - strlist->count = 0; - strlist->size = size; - - return strlist; -} - -c_strlist_t *c_strlist_expand(c_strlist_t *strlist, size_t size) { - if (strlist == NULL || size == 0) { - errno = EINVAL; - return NULL; - } - - if (strlist->size >= size) { - return strlist; - } - - strlist->vector = (char **) c_realloc(strlist->vector, size * sizeof(char *)); - if (strlist->vector == NULL) { - return NULL; - } - - strlist->size = size; - - return strlist; -} - -int c_strlist_add(c_strlist_t *strlist, const char *string) { - if (strlist == NULL || string == NULL) { - return -1; - } - - if (strlist->count < strlist->size) { - strlist->vector[strlist->count] = c_strdup(string); - if (strlist->vector[strlist->count] == NULL) { - return -1; - } - strlist->count++; - } else { - errno = ENOBUFS; - return -1; - } - - return 0; -} - -int c_strlist_add_grow(c_strlist_t **strlist, const char *string) { - if (*strlist == NULL) { - *strlist = c_strlist_new(32); - if (*strlist == NULL) { - return -1; - } - } - - if ((*strlist)->count == (*strlist)->size) { - c_strlist_t *list = c_strlist_expand(*strlist, 2 * (*strlist)->size); - if (list == NULL) { - return -1; - } - *strlist = list; - } - - return c_strlist_add(*strlist, string); -} - -void c_strlist_clear(c_strlist_t *strlist) { - size_t i = 0; - - if (strlist == NULL) { - return; - } - - for (i = 0; i < strlist->count; i++) { - SAFE_FREE(strlist->vector[i]); - } - - strlist->count = 0; -} - -void c_strlist_destroy(c_strlist_t *strlist) { - - if (strlist == NULL) { - return; - } - - c_strlist_clear(strlist); - SAFE_FREE(strlist->vector); - SAFE_FREE(strlist); -} |