summaryrefslogtreecommitdiff
blob: e0ca4185617f9bbceb503396a868bc8cb7a5eaf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
https://bugs.gentoo.org/830231
https://github.com/nih-at/libzip/issues/253
https://github.com/nih-at/libzip/commit/e29f28b4fe66ef24e205678dc29f65d693c649eb

From e29f28b4fe66ef24e205678dc29f65d693c649eb Mon Sep 17 00:00:00 2001
From: Dieter Baron <dillo@nih.at>
Date: Fri, 22 Nov 2024 11:32:32 +0100
Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20hardcode=20=5FNullable=20suppor?=
 =?UTF-8?q?t=20in=20zip.h.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Based on and closes #253.
---
 CMakeLists.txt | 11 -----------
 config.h.in    |  1 -
 lib/zip.h      |  9 +++++++++
 zipconf.h.in   |  2 --
 6 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 23e0f0fd8..3d5fa1bc8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -192,10 +192,6 @@ check_c_source_compiles("#include <sys/ioctl.h>
 #include <linux/fs.h>
 int main(int argc, char *argv[]) { unsigned long x = FICLONERANGE; }" HAVE_FICLONERANGE)
 
-check_c_source_compiles("
-int foo(char * _Nullable bar);
-int main(int argc, char *argv[]) { }" HAVE_NULLABLE)
-
 test_big_endian(WORDS_BIGENDIAN)
 
 find_package(ZLIB 1.1.2 REQUIRED)
@@ -458,13 +454,6 @@ elseif(LONG_LONG_LIBZIP EQUAL 8)
   set(ZIP_UINT64_T "unsigned long long")
 endif()
 
-if(HAVE_NULLABLE)
-  set(ZIP_NULLABLE_DEFINES)
-else()
-  set(ZIP_NULLABLE_DEFINES "#define _Nullable
-#define _Nonnull")
-endif()
-
 # write out config file
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${PROJECT_BINARY_DIR}/config.h)
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zipconf.h.in ${PROJECT_BINARY_DIR}/zipconf.h)
diff --git a/config.h.in b/config.h.in
index 90a324285..09d42384d 100644
--- a/config.h.in
+++ b/config.h.in
@@ -41,7 +41,6 @@
 #cmakedefine HAVE_MEMCPY_S
 #cmakedefine HAVE_MBEDTLS
 #cmakedefine HAVE_MKSTEMP
-#cmakedefine HAVE_NULLABLE
 #cmakedefine HAVE_OPENSSL
 #cmakedefine HAVE_SETMODE
 #cmakedefine HAVE_SNPRINTF
diff --git a/lib/zip.h b/lib/zip.h
index 14064062f..c2a8a8b46 100644
--- a/lib/zip.h
+++ b/lib/zip.h
@@ -34,6 +34,15 @@
   IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
+#if defined(__has_feature)
+  #if !__has_feature(nullability)
+    #define _Nullable
+    #define _Nonnull
+  #endif
+#else
+  #define _Nullable
+  #define _Nonnull
+#endif
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/zipconf.h.in b/zipconf.h.in
index b88ed267f..04dce7184 100644
--- a/zipconf.h.in
+++ b/zipconf.h.in
@@ -15,8 +15,6 @@
 
 #cmakedefine ZIP_STATIC
 
-${ZIP_NULLABLE_DEFINES}
-
 ${LIBZIP_TYPES_INCLUDE}
 
 typedef ${ZIP_INT8_T} zip_int8_t;