Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 1 | Upstream-Status: Backport [fc88e56bfc2b09a8fb2b350e76f6425ab0a056d7] |
| 2 | Signed-off-by: Ross Burton <ross.burton@intel.com> |
| 3 | |
| 4 | From 141acf6a2f3b21d63c9cfe620b8e20a506e78493 Mon Sep 17 00:00:00 2001 |
| 5 | From: Ross Burton <ross.burton@intel.com> |
| 6 | Date: Wed, 13 Mar 2019 16:22:09 +0000 |
| 7 | Subject: [PATCH] meson: do a build-time check for strlcpy before attempting |
| 8 | runtime check |
| 9 | |
| 10 | In cross-compilation environments the runtime check isn't possible so it is up |
| 11 | to the builder to seed the cross file, but we can definitely state that strlcpy |
| 12 | doesn't exist with a build test. |
| 13 | --- |
| 14 | meson.build | 30 ++++++++++++++++-------------- |
| 15 | 1 file changed, 16 insertions(+), 14 deletions(-) |
| 16 | |
| 17 | diff --git a/meson.build b/meson.build |
| 18 | index 15039e448..414f2d9b1 100644 |
| 19 | --- a/meson.build |
| 20 | +++ b/meson.build |
| 21 | @@ -1860,22 +1860,24 @@ endif |
| 22 | |
| 23 | # Test if we have strlcpy/strlcat with a compatible implementation: |
| 24 | # https://bugzilla.gnome.org/show_bug.cgi?id=53933 |
| 25 | -if cc_can_run |
| 26 | - rres = cc.run('''#include <stdlib.h> |
| 27 | - #include <string.h> |
| 28 | - int main() { |
| 29 | - char p[10]; |
| 30 | - (void) strlcpy (p, "hi", 10); |
| 31 | - if (strlcat (p, "bye", 0) != 3) |
| 32 | - return 1; |
| 33 | - return 0; |
| 34 | - }''', |
| 35 | - name : 'OpenBSD strlcpy/strlcat') |
| 36 | - if rres.compiled() and rres.returncode() == 0 |
| 37 | +if cc.has_function('strlcpy') |
| 38 | + if cc_can_run |
| 39 | + rres = cc.run('''#include <stdlib.h> |
| 40 | + #include <string.h> |
| 41 | + int main() { |
| 42 | + char p[10]; |
| 43 | + (void) strlcpy (p, "hi", 10); |
| 44 | + if (strlcat (p, "bye", 0) != 3) |
| 45 | + return 1; |
| 46 | + return 0; |
| 47 | + }''', |
| 48 | + name : 'OpenBSD strlcpy/strlcat') |
| 49 | + if rres.compiled() and rres.returncode() == 0 |
| 50 | + glib_conf.set('HAVE_STRLCPY', 1) |
| 51 | + endif |
| 52 | + elif meson.get_cross_property('have_strlcpy', false) |
| 53 | glib_conf.set('HAVE_STRLCPY', 1) |
| 54 | endif |
| 55 | -elif meson.get_cross_property('have_strlcpy', false) |
| 56 | - glib_conf.set('HAVE_STRLCPY', 1) |
| 57 | endif |
| 58 | |
| 59 | python = import('python').find_installation('python3') |
| 60 | -- |
| 61 | 2.11.0 |
| 62 | |