diff --git a/libbdc/CMakeLists.txt b/libbdc/CMakeLists.txt index 4ae0edc6c57bfea0d607ec91c7daa91119af14c4..71a01ac02100100db3c113b2c65d98f7209f1df6 100644 --- a/libbdc/CMakeLists.txt +++ b/libbdc/CMakeLists.txt @@ -30,6 +30,8 @@ else () MESSAGE("Unknown compiler: ${CMAKE_C_COMPILER_ID}") endif () + +add_subdirectory(bdc_cross_platform) add_subdirectory(bdc_memory) add_library(bdc STATIC "") diff --git a/libbdc/bdc_cross_platform/CMakeLists.txt b/libbdc/bdc_cross_platform/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..55110c10a795a2c5be4e961eabdc68d1af7bf142 --- /dev/null +++ b/libbdc/bdc_cross_platform/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library(bdc_cross_platform STATIC) +target_sources(bdc_cross_platform + PRIVATE + bdc_cross_platform.c + PUBLIC + bdc_cross_platform.h) + + +set_property(TARGET bdc_cross_platform PROPERTY POSITION_INDEPENDENT_CODE ON) \ No newline at end of file diff --git a/libbdc/bdc_cross_platform/bdc_cross_platform.c b/libbdc/bdc_cross_platform/bdc_cross_platform.c new file mode 100644 index 0000000000000000000000000000000000000000..58960331cd91dfcc5a9b8075e1194f4b624d3ea2 --- /dev/null +++ b/libbdc/bdc_cross_platform/bdc_cross_platform.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// +// bdc_cross_platform.c +// +// Copyright (C) 2011-2024, University of Vienna and Vienna Institute for Nature Conservation & Analyses, Andreas Gattringer. +// +// 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 +// the Free Software Foundation; either version 3 of the License, or (at +// your option) any later version. +// +// This program 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 +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// + diff --git a/libbdc/bdc_cross_platform/bdc_cross_platform.h b/libbdc/bdc_cross_platform/bdc_cross_platform.h new file mode 100644 index 0000000000000000000000000000000000000000..e0252259dcf421383b2f5c409c1bd42e1b7057af --- /dev/null +++ b/libbdc/bdc_cross_platform/bdc_cross_platform.h @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// +// bdc_cross_platform.h +// +// Copyright (C) 2011-2024, University of Vienna and Vienna Institute for Nature Conservation & Analyses, Andreas Gattringer. +// +// 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 +// the Free Software Foundation; either version 3 of the License, or (at +// your option) any later version. +// +// This program 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 +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// + +#ifndef BDC_WINDOWS_H +#define BDC_WINDOWS_H + +#ifdef WIN32 +#define BDC_ON_WINDOWS +#endif + +#if defined(__MINGW64__) || defined(__MINGW32__) +#define __USE_MINGW_ANSI_STDIO 1 +#endif + +#ifdef BDC_ON_WINDOWS +#define strncasecmp strnicmp +#define strcasecmp stricmp +#define strtok_r strtok_s +#define access _access +#define F_OK 0 + +#include <string.h> +#include <bdc_memory/bdc_memory.h> + +static inline char *strndup(const char *s, size_t n) +{ + char *end_pointer = memchr(s, '\0', n); + if (end_pointer != NULL) { + n = end_pointer - s; + } + + char *result = malloc_or_die(n + 1); + memcpy(result, s, n); + result[n] = '\0'; + return result; +} + +#endif + +#endif //BDC_WINDOWS_H