From: Hannah von Reth Date: Thu, 16 Jul 2020 12:21:38 +0000 (+0200) Subject: Remove more legacy C code X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~81 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=458977239375b086ae9b0743955ab8ef4219f472;p=nextcloud-desktop.git Remove more legacy C code --- diff --git a/src/csync/CMakeLists.txt b/src/csync/CMakeLists.txt index cbb8f73d6..0fa5f3320 100644 --- a/src/csync/CMakeLists.txt +++ b/src/csync/CMakeLists.txt @@ -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 ) diff --git a/src/csync/ConfigureChecks.cmake b/src/csync/ConfigureChecks.cmake index d6a028ce8..022ff14c2 100644 --- a/src/csync/ConfigureChecks.cmake +++ b/src/csync/ConfigureChecks.cmake @@ -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") diff --git a/src/csync/config_csync.h.cmake b/src/csync/config_csync.h.cmake index aff1bb744..855ecd33e 100644 --- a/src/csync/config_csync.h.cmake +++ b/src/csync/config_csync.h.cmake @@ -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 index 8738df973..000000000 --- a/src/csync/std/asprintf.c +++ /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 - */ - -#ifndef HAVE_ASPRINTF - -#include -#include -#include - -#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 index 21693ca89..000000000 --- a/src/csync/std/asprintf.h +++ /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 - */ - -#ifndef HAVE_ASPRINTF -#ifndef ASPRINTF_H -#define ASPRINTF_H 1 - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -/** - * 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 index ab2f2a47a..000000000 --- a/src/csync/std/c_alloc.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * cynapses libc functions - * - * Copyright (c) 2008-2013 by Andreas Schneider - * - * 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 - -#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 index 166c5c8cd..000000000 --- a/src/csync/std/c_alloc.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - * cynapses libc functions - * - * Copyright (c) 2008-2013 by Andreas Schneider - * - * 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 // NOLINT this is sometimes compiled in C mode - -#include "c_macro.h" - -/** - * @brief Allocates memory for an array. - * - * Allocates memory for an array of elements of 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 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 */ diff --git a/src/csync/std/c_lib.h b/src/csync/std/c_lib.h index f6092a953..13b9f1587 100644 --- a/src/csync/std/c_lib.h +++ b/src/csync/std/c_lib.h @@ -21,7 +21,4 @@ #include // NOLINT this is sometimes compiled in C mode #include // 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 index 6e9cafb08..000000000 --- a/src/csync/std/c_macro.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * cynapses libc functions - * - * Copyright (c) 2008-2013 by Andreas Schneider - * - * 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 // NOLINT this is sometimes compiled in C mode -#include // 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 */ - diff --git a/src/csync/std/c_private.h b/src/csync/std/c_private.h index 9b1ee2502..bfad3b1b9 100644 --- a/src/csync/std/c_private.h +++ b/src/csync/std/c_private.h @@ -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 index 553b97cb9..000000000 --- a/src/csync/std/c_string.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - * cynapses libc functions - * - * Copyright (c) 2008-2013 by Andreas Schneider - * Copyright (c) 2012-2013 by Klaas Freitag - * - * 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 -#include -#include -#include -#include - -#include -#include -#include - -#include "c_string.h" -#include "c_alloc.h" -#include "c_macro.h" - -#ifdef _WIN32 -#include -#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 index 9c8b557d4..000000000 --- a/src/csync/std/c_string.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * cynapses libc functions - * - * Copyright (c) 2008-2013 by Andreas Schneider - * Copyright (c) 2012-2013 by Klaas Freitag - * - * 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 // 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 */ - diff --git a/src/csync/std/c_time.cpp b/src/csync/std/c_time.cpp index 616255313..846f5b7d2 100644 --- a/src/csync/std/c_time.cpp +++ b/src/csync/std/c_time.cpp @@ -20,8 +20,6 @@ #include "config_csync.h" #include "c_private.h" -#include "c_string.h" - #include "c_time.h" #include diff --git a/src/csync/vio/csync_vio_local_unix.cpp b/src/csync/vio/csync_vio_local_unix.cpp index fae033b9d..9f035422b 100644 --- a/src/csync/vio/csync_vio_local_unix.cpp +++ b/src/csync/vio/csync_vio_local_unix.cpp @@ -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" diff --git a/src/libsync/filesystem.cpp b/src/libsync/filesystem.cpp index eb6b498f0..4b68e6728 100644 --- a/src/libsync/filesystem.cpp +++ b/src/libsync/filesystem.cpp @@ -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 { diff --git a/test/csync/CMakeLists.txt b/test/csync/CMakeLists.txt index 8e0b3c54d..224ecb606 100644 --- a/test/csync/CMakeLists.txt +++ b/test/csync/CMakeLists.txt @@ -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}) diff --git a/test/csync/encoding_tests/check_encoding.cpp b/test/csync/encoding_tests/check_encoding.cpp index d5a5b819a..8881ace39 100644 --- a/test/csync/encoding_tests/check_encoding.cpp +++ b/test/csync/encoding_tests/check_encoding.cpp @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include -#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 index bf9a31538..000000000 --- a/test/csync/std_tests/check_std_c_alloc.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * libcsync -- a library to sync a directory with another - * - * Copyright (c) 2008-2013 by Andreas Schneider - * - * 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 index e815958c2..000000000 --- a/test/csync/std_tests/check_std_c_str.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * libcsync -- a library to sync a directory with another - * - * Copyright (c) 2008-2013 by Andreas Schneider - * - * 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 -#include -#include -#include - -#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); -} - diff --git a/test/csync/vio_tests/check_vio_ext.cpp b/test/csync/vio_tests/check_vio_ext.cpp index 32b173e7f..52db78f6e 100644 --- a/test/csync/vio_tests/check_vio_ext.cpp +++ b/test/csync/vio_tests/check_vio_ext.cpp @@ -25,8 +25,6 @@ #include #include "csync.h" -#include "std/c_alloc.h" -#include "std/c_string.h" #include "vio/csync_vio_local.h" #include @@ -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(*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 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 ? "":" ", - subdir), -1 ); + subdir = dir.toUtf8() + "/" + dirent->path; + subdir_out = (is_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);