Remove more legacy C code
authorHannah von Reth <hannah.vonreth@owncloud.com>
Thu, 16 Jul 2020 12:21:38 +0000 (14:21 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:59:15 +0000 (10:59 +0100)
20 files changed:
src/csync/CMakeLists.txt
src/csync/ConfigureChecks.cmake
src/csync/config_csync.h.cmake
src/csync/std/asprintf.c [deleted file]
src/csync/std/asprintf.h [deleted file]
src/csync/std/c_alloc.c [deleted file]
src/csync/std/c_alloc.h [deleted file]
src/csync/std/c_lib.h
src/csync/std/c_macro.h [deleted file]
src/csync/std/c_private.h
src/csync/std/c_string.c [deleted file]
src/csync/std/c_string.h [deleted file]
src/csync/std/c_time.cpp
src/csync/vio/csync_vio_local_unix.cpp
src/libsync/filesystem.cpp
test/csync/CMakeLists.txt
test/csync/encoding_tests/check_encoding.cpp
test/csync/std_tests/check_std_c_alloc.c [deleted file]
test/csync/std_tests/check_std_c_str.c [deleted file]
test/csync/vio_tests/check_vio_ext.cpp

index cbb8f73d6d09cbe1a3b24617ccd5f8f8ad95bdc0..0fa5f3320469262dd173418b39917421d85dc22f 100644 (file)
@@ -34,8 +34,6 @@ set(csync_SRCS
   csync_exclude.cpp
   csync_util.cpp
 
-  std/c_alloc.c
-  std/c_string.c
   std/c_time.cpp
 
 )
index d6a028ce804568bc8c60423efb548eab03b1261d..022ff14c231697f19b59e4bbeccc03ebc57bb006 100644 (file)
@@ -25,25 +25,12 @@ if (NOT LINUX)
     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} )
 endif (NOT LINUX)
 
-check_function_exists(asprintf HAVE_ASPRINTF)
-
 if(WIN32)
   set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} psapi kernel32)
 endif()
 
 check_function_exists(timegm HAVE_TIMEGM)
-check_function_exists(strerror_r HAVE_STRERROR_R)
 check_function_exists(utimes HAVE_UTIMES)
 check_function_exists(lstat HAVE_LSTAT)
-check_function_exists(asprintf HAVE_ASPRINTF)
-if (WIN32)
-       check_function_exists(__mingw_asprintf HAVE___MINGW_ASPRINTF)
-endif(WIN32)
-if (UNIX AND HAVE_ASPRINTF)
-  add_definitions(-D_GNU_SOURCE)
-endif (UNIX AND HAVE_ASPRINTF)
-if (WIN32)
-  check_function_exists(__mingw_asprintf HAVE___MINGW_ASPRINTF)
-endif(WIN32)
 
 set(CSYNC_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CACHE INTERNAL "csync required system libraries")
index aff1bb74457d6c2124db5705056d7ce5d7685f9a..855ecd33e3ec5966c1d290c1ade144128be3c37f 100644 (file)
@@ -9,10 +9,7 @@
 #cmakedefine HAVE_ARGP_H 1
 
 #cmakedefine HAVE_TIMEGM 1
-#cmakedefine HAVE_STRERROR_R 1
 #cmakedefine HAVE_UTIMES 1
 #cmakedefine HAVE_LSTAT 1
 
-#cmakedefine HAVE___MINGW_ASPRINTF 1
-#cmakedefine HAVE_ASPRINTF 1
 
diff --git a/src/csync/std/asprintf.c b/src/csync/std/asprintf.c
deleted file mode 100644 (file)
index 8738df9..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
-  https://raw.githubusercontent.com/littlstar/asprintf.c/20ce5207a4ecb24017b5a17e6cd7d006e3047146/asprintf.c
-
-  The MIT License (MIT)
-
-  Copyright (c) 2014 Little Star Media, Inc.
-
-  Permission is hereby granted, free of charge, to any person obtaining a copy
-  of this software and associated documentation files (the "Software"), to deal
-  in the Software without restriction, including without limitation the rights
-  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-  copies of the Software, and to permit persons to whom the Software is
-  furnished to do so, subject to the following conditions:
-
-  The above copyright notice and this permission notice shall be included in all
-  copies or substantial portions of the Software.
-
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-  SOFTWARE.
-*/
-
-/**
- * `asprintf.c' - asprintf
- *
- * copyright (c) 2014 joseph werle <joseph.werle@gmail.com>
- */
-
-#ifndef HAVE_ASPRINTF
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
-
-#include "asprintf.h"
-
-int
-asprintf (char **str, const char *fmt, ...) {
-  int size = 0;
-  va_list args;
-
-  // init variadic argumens
-  va_start(args, fmt);
-
-  // format and get size
-  size = vasprintf(str, fmt, args);
-
-  // toss args
-  va_end(args);
-
-  return size;
-}
-
-int
-vasprintf (char **str, const char *fmt, va_list args) {
-  int size = 0;
-  va_list tmpa;
-
-  // copy
-  va_copy(tmpa, args);
-
-  // apply variadic arguments to
-  // sprintf with format to get size
-  size = vsnprintf(NULL, size, fmt, tmpa);
-
-  // toss args
-  va_end(tmpa);
-
-  // return -1 to be compliant if
-  // size is less than 0
-  if (size < 0) { return -1; }
-
-  // alloc with size plus 1 for `\0'
-  *str = (char *) malloc(size + 1);
-
-  // return -1 to be compliant
-  // if pointer is `NULL'
-  if (NULL == *str) { return -1; }
-
-  // format string with original
-  // variadic arguments and set new size
-  size = vsprintf(*str, fmt, args);
-  return size;
-}
-
-#endif
diff --git a/src/csync/std/asprintf.h b/src/csync/std/asprintf.h
deleted file mode 100644 (file)
index 21693ca..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
-  https://raw.githubusercontent.com/littlstar/asprintf.c/20ce5207a4ecb24017b5a17e6cd7d006e3047146/asprintf.h
-
-  The MIT License (MIT)
-
-  Copyright (c) 2014 Little Star Media, Inc.
-
-  Permission is hereby granted, free of charge, to any person obtaining a copy
-  of this software and associated documentation files (the "Software"), to deal
-  in the Software without restriction, including without limitation the rights
-  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-  copies of the Software, and to permit persons to whom the Software is
-  furnished to do so, subject to the following conditions:
-
-  The above copyright notice and this permission notice shall be included in all
-  copies or substantial portions of the Software.
-
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-  SOFTWARE.
-*/
-
-/**
- * `asprintf.h' - asprintf.c
- *
- * copyright (c) 2014 joseph werle <joseph.werle@gmail.com>
- */
-
-#ifndef HAVE_ASPRINTF
-#ifndef ASPRINTF_H
-#define ASPRINTF_H 1
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdarg.h>
-
-/**
- * Sets `char **' pointer to be a buffer
- * large enough to hold the formatted string
- * accepting a `va_list' args of variadic
- * arguments.
- */
-
-int
-vasprintf (char **, const char *, va_list);
-
-/**
- * Sets `char **' pointer to be a buffer
- * large enough to hold the formatted
- * string accepting `n' arguments of
- * variadic arguments.
- */
-
-int
-asprintf (char **, const char *, ...);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-#endif
diff --git a/src/csync/std/c_alloc.c b/src/csync/std/c_alloc.c
deleted file mode 100644 (file)
index ab2f2a4..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * cynapses libc functions
- *
- * Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
- *
- * 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 <string.h>
-
-#include "c_macro.h"
-#include "c_alloc.h"
-
-void *c_calloc(size_t count, size_t size) {
-  if (size == 0 || count == 0) {
-    return NULL;
-  }
-
-#ifdef CSYNC_MEM_NULL_TESTS
-  if (getenv("CSYNC_NOMEMORY")) {
-    return NULL;
-  }
-#endif /* CSYNC_MEM_NULL_TESTS */
-
-#undef calloc
-  return calloc(count, size);
-#define calloc(x,y) DO_NOT_CALL_CALLOC__USE_XCALLOC_INSTEAD
-}
-
-void *c_malloc(size_t size) {
-  if (size == 0) {
-    return NULL;
-  }
-#undef malloc
-  return c_calloc(1, size);
-#define malloc(x) DO_NOT_CALL_MALLOC__USE_XMALLOC_INSTEAD
-}
-
-void *c_realloc(void *ptr, size_t size) {
-
-#ifdef CSYNC_MEM_NULL_TESTS
-  if (getenv("CSYNC_NOMEMORY")) {
-    return NULL;
-  }
-#endif /* CSYNC_MEM_NULL_TESTS */
-
-#undef realloc
-  return realloc(ptr, size);
-#define realloc(x,y) DO_NOT_CALL_REALLOC__USE_XREALLOC_INSTEAD
-}
-
-char *c_strdup(const char *str) {
-  char *ret = NULL;
-  ret = (char *) c_malloc(strlen(str) + 1);
-  if (ret == NULL) {
-    return NULL;
-  }
-  strcpy(ret, str);
-  return ret;
-}
-
-char *c_strndup(const char *str, size_t size) {
-  char *ret = NULL;
-  size_t len = 0;
-  len = strlen(str);
-  if (len > size) {
-    len = size;
-  }
-  ret = (char *) c_malloc(len + 1);
-  if (ret == NULL) {
-    return NULL;
-  }
-  strncpy(ret, str, len);
-  ret[size] = '\0';
-  return ret;
-}
-
diff --git a/src/csync/std/c_alloc.h b/src/csync/std/c_alloc.h
deleted file mode 100644 (file)
index 166c5c8..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * cynapses libc functions
- *
- * Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
- *
- * 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
- */
-
-/**
- * @file c_alloc.h
- *
- * @brief Interface of the cynapses libc alloc function
- *
- * @defgroup cynLibraryAPI cynapses libc API (internal)
- *
- * @defgroup cynAllocInternals cynapses libc alloc functions
- * @ingroup cynLibraryAPI
- *
- * @{
- */
-
-#ifndef _C_ALLOC_H
-#define _C_ALLOC_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdlib.h> // NOLINT this is sometimes compiled in C mode
-
-#include "c_macro.h"
-
-/**
- * @brief Allocates memory for an array.
- *
- * Allocates memory for an array of <count> elements of <size> bytes each and
- * returns a pointer to the allocated memory. The memory is set to zero.
- *
- * @param count   Amount of elements to allocate
- * @param size    Size in bytes of each element to allocate.
- *
- * @return A unique pointer value that can later be successfully passed to
- *         free(). If size or count is 0, NULL will be returned.
- */
-void *c_calloc(size_t count, size_t size);
-
-/**
- * @brief Allocates memory for an array.
- *
- * Allocates <size> bytes of memory. The memory is set to zero.
- *
- * @param size    Size in bytes to allocate.
- *
- * @return A unique pointer value that can later be successfully passed to
- *         free(). If size or count is 0, NULL will be returned.
- */
-void *c_malloc(size_t size);
-
-/**
- * @brief Changes the size of the memory block pointed to.
- *
- * Newly allocated memory will be uninitialized.
- *
- * @param ptr   Pointer to the memory which should be resized.
- * @param size  Value to resize.
- *
- * @return If ptr is NULL, the call is equivalent to c_malloc(size); if size
- *         is equal to zero, the call is equivalent to free(ptr). Unless ptr
- *         is NULL, it must have been returned by an earlier call to
- *         c_malloc(), c_calloc() or c_realloc(). If the area pointed to was
- *         moved, a free(ptr) is done.
- */
-void *c_realloc(void *ptr, size_t size);
-
-/**
- * @brief Duplicate a string.
- *
- * The function returns a pointer to a newly allocated string which is a
- * duplicate of the string str.
- *
- * @param str   String to duplicate.
- *
- * @return Returns a pointer to the duplicated string, or NULL if insufficient
- * memory was available.
- *
- */
-char *c_strdup(const char *str);
-
-/**
- * @brief Duplicate a string.
- *
- * The function returns a pointer to a newly allocated string which is a
- * duplicate of the string str of size bytes.
- *
- * @param str   String to duplicate.
- *
- * @param size  Size of the string to duplicate.
- *
- * @return Returns a pointer to the duplicated string, or NULL if insufficient
- * memory was available. A terminating null byte '\0' is added.
- *
- */
-char *c_strndup(const char *str, size_t size);
-
-/**
- * }@
- */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _C_ALLOC_H */
index f6092a9538273aca335f8575723db0ff2d03dfac..13b9f158725845d17608024bfa90e486a8baeeb5 100644 (file)
@@ -21,7 +21,4 @@
 #include <stdlib.h> // NOLINT this is sometimes compiled in C mode
 #include <string.h> // NOLINT this is sometimes compiled in C mode
 
-#include "c_macro.h"
-#include "c_alloc.h"
-#include "c_string.h"
 #include "c_private.h"
diff --git a/src/csync/std/c_macro.h b/src/csync/std/c_macro.h
deleted file mode 100644 (file)
index 6e9cafb..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * cynapses libc functions
- *
- * Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
- *
- * 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
- */
-
-/**
- * @file c_macro.h
- *
- * @brief cynapses libc macro definitions
- *
- * @defgroup cynMacroInternals cynapses libc macro definitions
- * @ingroup cynLibraryAPI
- *
- * @{
- */
-#ifndef _C_MACRO_H
-#define _C_MACRO_H
-
-#include <stdint.h> // NOLINT this is sometimes compiled in C mode
-#include <string.h> // NOLINT this is sometimes compiled in C mode
-
-#define INT_TO_POINTER(i) (void *) i
-#define POINTER_TO_INT(p) *((int *) (p))
-
-/** Zero a structure */
-#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
-
-/** Zero a structure given a pointer to the structure */
-#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
-
-/** Free memory and zero the pointer */
-#define SAFE_FREE(x) do { if ((x) != NULL) {free((void*)(x)); (x)=NULL;} } while(0)
-
-/** Get the smaller value */
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-
-/** Get the bigger value */
-#define MAX(a,b) ((a) < (b) ? (b) : (a))
-
-/** Get the size of an array */
-#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
-
-/**
- * This is a hack to fix warnings. The idea is to use this everywhere that we
- * get the "discarding const" warning by the compiler. That doesn't actually
- * fix the real issue, but marks the place and you can search the code for
- * discard_const.
- *
- * Please use this macro only when there is no other way to fix the warning.
- * We should use this function in only in a very few places.
- *
- * Also, please call this via the discard_const_p() macro interface, as that
- * makes the return type safe.
- */
-#define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
-
-/**
- * Type-safe version of discard_const
- */
-#define discard_const_p(type, ptr) ((type *)discard_const(ptr))
-
-#if (__GNUC__ >= 3)
-# ifndef likely
-#  define likely(x)   __builtin_expect(!!(x), 1)
-# endif
-# ifndef unlikely
-#  define unlikely(x) __builtin_expect(!!(x), 0)
-# endif
-#else /* __GNUC__ */
-# ifndef likely
-#  define likely(x) (x)
-# endif
-# ifndef unlikely
-#  define unlikely(x) (x)
-# endif
-#endif /* __GNUC__ */
-
-/**
- * }@
- */
-
-#ifdef _WIN32
-/* missing errno codes on mingw */
-#ifndef ENOTBLK
-#define        ENOTBLK                15
-#endif
-#ifndef ETXTBSY
-#define        ETXTBSY                26
-#endif
-#ifndef ENOBUFS
-#define        ENOBUFS                WSAENOBUFS
-#endif
-#endif /* _WIN32 */
-
-#endif /* _C_MACRO_H */
-
index 9b1ee25026a0834f00e3d888485f17f23d65104b..bfad3b1b995dbd87d7953432e52b51d0f201cc31 100644 (file)
@@ -84,14 +84,6 @@ typedef struct stat csync_stat_t; // NOLINT this is sometimes compiled in C mode
 #define O_NOATIME 0
 #endif
 
-#if !defined(HAVE_ASPRINTF)
-#if defined(HAVE___MINGW_ASPRINTF)
-#define asprintf __mingw_asprintf
-#else
-#include "asprintf.h"
-#endif
-#endif
-
 #ifndef HAVE_LSTAT
 #define lstat _stat
 #endif
diff --git a/src/csync/std/c_string.c b/src/csync/std/c_string.c
deleted file mode 100644 (file)
index 553b97c..0000000
+++ /dev/null
@@ -1,65 +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_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;
-}
diff --git a/src/csync/std/c_string.h b/src/csync/std/c_string.h
deleted file mode 100644 (file)
index 9c8b557..0000000
+++ /dev/null
@@ -1,75 +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
- */
-
-/**
- * @file c_string.h
- *
- * @brief Interface of the cynapses string implementations
- *
- * @defgroup cynStringInternals cynapses libc string functions
- * @ingroup cynLibraryAPI
- *
- * @{
- */
-#ifndef _C_STR_H
-#define _C_STR_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "c_private.h"
-#include "c_macro.h"
-
-#include <stdlib.h> // NOLINT this is sometimes compiled in C mode
-
-/**
- * @brief Compare to strings case insensitively.
- *
- * @param a  First string to compare.
- * @param b  Second string to compare.
- * @param n  Max comparison length.
- *
- * @return see strncasecmp
- */
-int c_strncasecmp(const char *a, const char *b, size_t n);
-
-/**
- * @brief Compare to strings if they are equal.
- *
- * @param a  First string to compare.
- * @param b  Second string to compare.
- *
- * @return  1 if they are equal, 0 if not.
- */
-int c_streq(const char *a, const char *b);
-
-
-/**
- * }@
- */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _C_STR_H */
-
index 6162553138ecec88556646dc47b45f62ba964146..846f5b7d2a845ba85d283061f77502b4b9134660 100644 (file)
@@ -20,8 +20,6 @@
 
 #include "config_csync.h"
 #include "c_private.h"
-#include "c_string.h"
-
 #include "c_time.h"
 
 #include <QFile>
index fae033b9d07521d734c92fedbe6cf2e34c24b189..9f035422b7612cc05da8efcd29ebd39f50a8caef 100644 (file)
@@ -30,7 +30,6 @@
 
 #include "c_private.h"
 #include "c_lib.h"
-#include "c_string.h"
 #include "csync_util.h"
 
 #include "vio/csync_vio_local.h"
index eb6b498f0b132eebc4142d3d48e5e2628a20019a..4b68e6728b9ac7c2e4f8a4fa02f510a0af402178 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "csync.h"
 #include "vio/csync_vio_local.h"
-#include "std/c_string.h"
 #include "std/c_time.h"
 
 namespace OCC {
index 8e0b3c54d4057e567ee09b7d1c22120823841ab0..224ecb6067db9e05349a7bb64b5b2c13e457cfab 100644 (file)
@@ -18,17 +18,12 @@ set(TEST_TARGET_LIBRARIES ${TORTURE_LIBRARY} Qt5::Core "${csync_NAME}")
 # create tests
 
 # std
-add_cmocka_test(check_std_c_alloc std_tests/check_std_c_alloc.c ${TEST_TARGET_LIBRARIES})
+
 add_cmocka_test(check_std_c_jhash std_tests/check_std_c_jhash.c ${TEST_TARGET_LIBRARIES})
-add_cmocka_test(check_std_c_str std_tests/check_std_c_str.c ${TEST_TARGET_LIBRARIES})
 
 # vio
 add_cmocka_test(check_vio_ext vio_tests/check_vio_ext.cpp ${TEST_TARGET_LIBRARIES})
 
-if(NOT HAVE_ASPRINTF AND NOT HAVE___MINGW_ASPRINTF)
-    target_sources(check_vio_ext PRIVATE ${PROJECT_SOURCE_DIR}/src/csync/std/asprintf.c)
-endif()
-
 # encoding
 add_cmocka_test(check_encoding_functions encoding_tests/check_encoding.cpp ${TEST_TARGET_LIBRARIES})
 
index d5a5b819ac50a37887980e00ca62dd8d6f3ebfbc..8881ace39221316b53962420dc106780147c48db 100644 (file)
@@ -18,7 +18,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 #include <cstdio>
-#include "c_string.h"
 #include "common/filesystembase.h"
 #include "torture.h"
 
diff --git a/test/csync/std_tests/check_std_c_alloc.c b/test/csync/std_tests/check_std_c_alloc.c
deleted file mode 100644 (file)
index bf9a315..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * libcsync -- a library to sync a directory with another
- *
- * Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
- *
- * 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 "torture.h"
-
-#include "std/c_alloc.h"
-
-struct test_s {
-  int answer;
-};
-
-static void check_c_malloc(void **state)
-{
-  struct test_s *p = NULL;
-
-  (void) state; /* unused */
-
-  p = c_malloc(sizeof(struct test_s));
-  assert_non_null(p);
-  assert_int_equal(p->answer, 0);
-  p->answer = 42;
-  assert_int_equal(p->answer, 42);
-  free(p);
-}
-
-static void check_c_malloc_zero(void **state)
-{
-  void *p = NULL;
-
-  (void) state; /* unused */
-
-  p = c_malloc((size_t) 0);
-  assert_null(p);
-}
-
-static void check_c_strdup(void **state)
-{
-  const char *str = "test";
-  char *tdup = NULL;
-
-  (void) state; /* unused */
-
-  tdup = c_strdup(str);
-  assert_string_equal(tdup, str);
-
-  free(tdup);
-}
-
-static void check_c_strndup(void **state)
-{
-  const char *str = "test";
-  char *tdup = NULL;
-
-  (void) state; /* unused */
-
-  tdup = c_strndup(str, 3);
-  assert_memory_equal(tdup, "tes", 3);
-
-  free(tdup);
-}
-
-int torture_run_tests(void)
-{
-  const struct CMUnitTest tests[] = {
-      cmocka_unit_test(check_c_malloc),
-      cmocka_unit_test(check_c_malloc_zero),
-      cmocka_unit_test(check_c_strdup),
-      cmocka_unit_test(check_c_strndup),
-  };
-
-  return cmocka_run_group_tests(tests, NULL, NULL);
-}
-
diff --git a/test/csync/std_tests/check_std_c_str.c b/test/csync/std_tests/check_std_c_str.c
deleted file mode 100644 (file)
index e815958..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * libcsync -- a library to sync a directory with another
- *
- * Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
- *
- * 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 <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "torture.h"
-
-#include "std/c_string.h"
-
-static void check_c_streq_equal(void **state)
-{
-    (void) state; /* unused */
-
-    assert_true(c_streq("test", "test"));
-}
-
-static void check_c_streq_not_equal(void **state)
-{
-    (void) state; /* unused */
-
-    assert_false(c_streq("test", "test2"));
-}
-
-static void check_c_streq_null(void **state)
-{
-    (void) state; /* unused */
-
-    assert_false(c_streq(NULL, "test"));
-    assert_false(c_streq("test", NULL));
-    assert_false(c_streq(NULL, NULL));
-}
-
-
-
-int torture_run_tests(void)
-{
-    const struct CMUnitTest tests[] = {
-        cmocka_unit_test(check_c_streq_equal),
-        cmocka_unit_test(check_c_streq_not_equal),
-        cmocka_unit_test(check_c_streq_null),
-    };
-
-    return cmocka_run_group_tests(tests, NULL, NULL);
-}
-
index 32b173e7fdc4bf12a6763f292bdb2de81d822051..52db78f6e408b7f88f02bb9d2bba215fd2e5c306 100644 (file)
@@ -25,8 +25,6 @@
 #include <cstdio>
 
 #include "csync.h"
-#include "std/c_alloc.h"
-#include "std/c_string.h"
 #include "vio/csync_vio_local.h"
 
 #include <QDir>
@@ -47,8 +45,8 @@ int oc_mkdir(const QString &path)
 static mbchar_t wd_buffer[WD_BUFFER_SIZE];
 
 typedef struct {
-    char  *result;
-    char *ignored_dir;
+    QByteArray result;
+    QByteArray ignored_dir;
 } statevar;
 
 /* remove the complete test dir */
@@ -82,9 +80,7 @@ static int setup_testenv(void **state) {
     assert_int_equal(rc, 0);
 
     /* --- initialize csync */
-    statevar *mystate = (statevar*)malloc( sizeof(statevar) );
-    mystate->result = NULL;
-
+    statevar *mystate = new statevar;
     *state = mystate;
     return 0;
 }
@@ -105,8 +101,7 @@ static int teardown(void **state) {
     rc = wipe_testdir();
     assert_int_equal(rc, 0);
 
-    SAFE_FREE(((statevar*)*state)->result);
-    SAFE_FREE(*state);
+    delete reinterpret_cast<statevar*>(*state);
     return 0;
 }
 
@@ -157,13 +152,11 @@ static void traverse_dir(void **state, const QString &dir, int *cnt)
     csync_vio_handle_t *dh;
     std::unique_ptr<csync_file_stat_t> dirent;
     statevar *sv = (statevar*) *state;
-    char *subdir;
-    char *subdir_out;
+    QByteArray subdir;
+    QByteArray subdir_out;
     int rc;
     int is_dir;
 
-    const char *format_str = "%s %s";
-
     dh = csync_vio_local_opendir(dir);
     assert_non_null(dh);
 
@@ -171,35 +164,26 @@ static void traverse_dir(void **state, const QString &dir, int *cnt)
     while( (dirent = csync_vio_local_readdir(dh, vfs)) ) {
         assert_non_null(dirent.get());
         if (!dirent->original_path.isEmpty()) {
-            sv->ignored_dir = c_strdup(dirent->original_path);
+            sv->ignored_dir = dirent->original_path;
             continue;
         }
 
         assert_false(dirent->path.isEmpty());
 
-        if( c_streq( dirent->path, "..") || c_streq( dirent->path, "." )) {
+        if( dirent->path == ".." || dirent->path == "." ) {
           continue;
         }
 
         is_dir = (dirent->type == ItemTypeDirectory) ? 1:0;
 
-        assert_int_not_equal( asprintf( &subdir, "%s/%s", dir.toUtf8().constData(), dirent->path.constData() ), -1 );
-
-        assert_int_not_equal( asprintf( &subdir_out, format_str,
-                                        is_dir ? "<DIR>":"     ",
-                                        subdir), -1 );
+        subdir = dir.toUtf8() + "/" + dirent->path;
+        subdir_out = (is_dir ? "<DIR> ":"      ") + subdir;
 
         if( is_dir ) {
-            if( !sv->result ) {
-                sv->result = c_strdup( subdir_out);
+            if( sv->result.isNull() ) {
+               sv->result = subdir_out;
             } else {
-                int newlen = 1+strlen(sv->result)+strlen(subdir_out);
-                char *tmp = sv->result;
-                sv->result = (char*)c_malloc(newlen);
-                strcpy( sv->result, tmp);
-                SAFE_FREE(tmp);
-
-                strcat( sv->result, subdir_out );
+               sv->result += subdir_out;
             }
         } else {
             *cnt = *cnt +1;
@@ -208,9 +192,6 @@ static void traverse_dir(void **state, const QString &dir, int *cnt)
         if( is_dir ) {
           traverse_dir( state, subdir, cnt);
         }
-
-        SAFE_FREE(subdir);
-        SAFE_FREE(subdir_out);
     }
 
     rc = csync_vio_local_closedir(dh);