csync_exclude.cpp
csync_util.cpp
- std/c_alloc.c
- std/c_string.c
std/c_time.cpp
)
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")
#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
+++ /dev/null
-/*
- 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
+++ /dev/null
-/*
- 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
+++ /dev/null
-/*
- * 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;
-}
-
+++ /dev/null
-/*
- * 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 */
#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"
+++ /dev/null
-/*
- * 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 */
-
#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
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- * 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 */
-
#include "config_csync.h"
#include "c_private.h"
-#include "c_string.h"
-
#include "c_time.h"
#include <QFile>
#include "c_private.h"
#include "c_lib.h"
-#include "c_string.h"
#include "csync_util.h"
#include "vio/csync_vio_local.h"
#include "csync.h"
#include "vio/csync_vio_local.h"
-#include "std/c_string.h"
#include "std/c_time.h"
namespace OCC {
# 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})
* 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"
+++ /dev/null
-/*
- * 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);
-}
-
+++ /dev/null
-/*
- * 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);
-}
-
#include <cstdio>
#include "csync.h"
-#include "std/c_alloc.h"
-#include "std/c_string.h"
#include "vio/csync_vio_local.h"
#include <QDir>
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 */
assert_int_equal(rc, 0);
/* --- initialize csync */
- statevar *mystate = (statevar*)malloc( sizeof(statevar) );
- mystate->result = NULL;
-
+ statevar *mystate = new statevar;
*state = mystate;
return 0;
}
rc = wipe_testdir();
assert_int_equal(rc, 0);
- SAFE_FREE(((statevar*)*state)->result);
- SAFE_FREE(*state);
+ delete reinterpret_cast<statevar*>(*state);
return 0;
}
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);
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;
if( is_dir ) {
traverse_dir( state, subdir, cnt);
}
-
- SAFE_FREE(subdir);
- SAFE_FREE(subdir_out);
}
rc = csync_vio_local_closedir(dh);