More work on cross long long
[ntpsec.git] / wafhelpers / check_strerror.py
blobd7c6b330c30dbb09891e8bde46a616f45d91fa98
1 # Copyright the NTPsec project contributors
3 # SPDX-License-Identifier: BSD-2-Clause
5 # check to see if strerror_r has type char*
7 # streror_r() has 2 APIs.
8 # our environment doesn't make a clean choice.
10 # There is code for mystrerror() in the bottom of msyslog.c
11 # This code tried to setup a #define for STRERROR_CHAR
12 # if strerror_r() returns char* rather than int
14 # Unfortunately, this test code compiles in the other case.
15 # It generates a warning on the type conversion from char* to int,
16 # but that's only a warning, so it "works".
18 # This uses -Werror which may not be portable.
20 # Another possibility is to run the test code,
21 # and have it check for 0/NULL which the int mode should return.
24 STRERROR_FRAG = """
25 #include <string.h>
26 int main(void) {
27 char buf [100];
28 const char *foo = strerror_r(6, buf, sizeof(buf));
29 return foo == NULL;
31 """
34 def check_strerror(ctx):
35 old_CFLAGS = ctx.env.CFLAGS
36 ctx.env.CFLAGS = ["-Werror"] + ctx.env.CFLAGS
37 ctx.check_cc(
38 fragment=STRERROR_FRAG,
39 define_name="STRERROR_CHAR",
40 features="c",
41 msg="Checking if strerror_r returns char*",
42 mandatory=False,
43 comment="Whether strerror_r returns char*"
45 ctx.env.CFLAGS = old_CFLAGS