From 4da2cb5a3065a98a42c06ffee071b6dd39232b7c Mon Sep 17 00:00:00 2001
From: Andreas Gattringer <andreas.gattringer@univie.ac.at>
Date: Tue, 30 Jan 2024 17:10:58 +0100
Subject: [PATCH] refactoring: added libbdc/bdc_cross_platform

---
 libbdc/CMakeLists.txt                         |  2 +
 libbdc/bdc_cross_platform/CMakeLists.txt      |  9 +++
 .../bdc_cross_platform/bdc_cross_platform.c   | 21 +++++++
 .../bdc_cross_platform/bdc_cross_platform.h   | 58 +++++++++++++++++++
 4 files changed, 90 insertions(+)
 create mode 100644 libbdc/bdc_cross_platform/CMakeLists.txt
 create mode 100644 libbdc/bdc_cross_platform/bdc_cross_platform.c
 create mode 100644 libbdc/bdc_cross_platform/bdc_cross_platform.h

diff --git a/libbdc/CMakeLists.txt b/libbdc/CMakeLists.txt
index 4ae0edc..71a01ac 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 0000000..55110c1
--- /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 0000000..5896033
--- /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 0000000..e025225
--- /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
-- 
GitLab