summaryrefslogtreecommitdiffstats
path: root/meta/recipes-support/p11-kit/files/strerror-1.patch
blob: 6af4fee7249907adb5a18c0a550c0205ae170546 (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
From 3ba2c55dfdc8ff20de369f07f6c57d08718d3add Mon Sep 17 00:00:00 2001
From: Adam Sampson <ats@offog.org>
Date: Sun, 2 Jul 2023 15:22:49 +0100
Subject: [PATCH] Check for GNU strerror_r using the compiler only

The new test that was added to distinguish GNU/XSI strerror_r ran a
compiled program, which doesn't work when cross-compiling. The only
difference at compile time is that the GNU version returns char * and
the XSI version returns int, so detect it by compiling a program that
dereferences the return value.

Signed-off-by: Adam Sampson <ats@offog.org>

Upstream-Status: Backport
Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 configure.ac | 19 +++++++------------
 meson.build  | 10 +++++-----
 2 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/configure.ac b/configure.ac
index 40f5a583..29890622 100644
--- a/configure.ac
+++ b/configure.ac
@@ -146,19 +146,14 @@ if test "$os_unix" = "yes"; then
 
 	AC_CHECK_FUNC(
 		[strerror_r],
-		[AC_RUN_IFELSE(
-			[AC_LANG_SOURCE([[
-				#include <errno.h>
-				#include <string.h>
-
-				int main (void)
-				{
-					char buf[32];
-					return strerror_r (EINVAL, buf, 32);
-				}
-			]])],
-                        [AC_DEFINE([HAVE_XSI_STRERROR_R], 1, [Whether XSI-compliant strerror_r() is available])],
+		[AC_COMPILE_IFELSE(
+			[AC_LANG_PROGRAM([[#include <errno.h>
+					   #include <string.h>]],
+					 [[/* GNU strerror_r returns char *, XSI returns int */
+					    char buf[32];
+					    return *strerror_r (EINVAL, buf, 32);]])],
 			[AC_DEFINE([HAVE_GNU_STRERROR_R], 1, [Whether GNU-specific strerror_r() is available])],
+                        [AC_DEFINE([HAVE_XSI_STRERROR_R], 1, [Whether XSI-compliant strerror_r() is available])],
 			[])],
 		[])
 
diff --git a/meson.build b/meson.build
index 0f8c8da0..4cc3f89a 100644
--- a/meson.build
+++ b/meson.build
@@ -306,15 +306,15 @@ if cc.has_function('strerror_r', prefix: '#include <string.h>')
 
 int main (void)
 {
+    /* GNU strerror_r returns char *, XSI returns int */
     char buf[32];
-    return strerror_r (EINVAL, buf, 32);
+    return *strerror_r (EINVAL, buf, 32);
 }
 '''
-  strerror_r_check = cc.run(strerror_r_code, name : 'strerror_r check')
-  if strerror_r_check.returncode() == 0
-    conf.set('HAVE_XSI_STRERROR_R', 1)
-  else
+  if cc.compiles(strerror_r_code, name : 'GNU strerror_r check')
     conf.set('HAVE_GNU_STRERROR_R', 1)
+  else
+    conf.set('HAVE_XSI_STRERROR_R', 1)
   endif
 endif