From e7afdd81ba949ad4c3ab2c50c2ac4c8c51cfaabc Mon Sep 17 00:00:00 2001
From: Alex Crichton <alex@alexcrichton.com>
Date: Thu, 10 Sep 2015 17:15:20 -0700
Subject: [PATCH] Handle when constants aren't defined

---
 libc-test/build.rs | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/libc-test/build.rs b/libc-test/build.rs
index d6d58bb9..c62dbe06 100644
--- a/libc-test/build.rs
+++ b/libc-test/build.rs
@@ -298,16 +298,28 @@ impl<'a> TestGenerator<'a> {
                           iter::repeat("*").take(ptrs).collect::<String>());
         let cast = if name == "SIG_IGN" {"(size_t)"} else {""};
         t!(writeln!(self.c, r#"
-            {cty} __test_const_{name}() {{ return {cast}({name}); }}
+            int __test_const_{name}({cty} *out) {{
+                int ret = 0;
+                #if defined({name})
+                    *out = {cast}({name});
+                    ret = 1;
+                #endif
+                return ret;
+            }}
         "#, name = name, cast = cast, cty = cty));
         t!(writeln!(self.rust, r#"
             #[test]
             fn const_{name}() {{
                 extern {{
-                    fn __test_const_{name}() -> {ty};
+                    fn __test_const_{name}(out: *mut {ty}) -> c_int;
                 }}
                 unsafe {{
-                    same({name}, __test_const_{name}(), "value");
+                    let mut o = mem::zeroed();
+                    if __test_const_{name}(&mut o) == 0 {{
+                        panic!("not defined");
+                    }} else {{
+                        same({name}, o, "value");
+                    }}
                 }}
             }}
         "#, ty = rust_ty, name = name));
-- 
GitLab