samba4-0003-build-find-FILE_OFFSET_BITS-via-array.patch 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. From 16d88e7813a7739c070a7a1cf6388fd4f236fd99 Mon Sep 17 00:00:00 2001
  2. From: Gustavo Zacarias <gustavo@zacarias.com.ar>
  3. Date: Fri, 31 Jan 2014 06:45:18 -0300
  4. Subject: [PATCHv2] build: find FILE_OFFSET_BITS via array
  5. This makes cross-compiling happy, use a trick similar to autoconf's
  6. AC_CHECK_SIZEOF macro.
  7. Basically we make an array:
  8. static int array[1 - 2 * !(((long int)(sizeof(off_t))) < 8)];
  9. This gives -1 multiplied by the negation of the condition
  10. (sizeof(off_t) < 8) cast to a long int.
  11. So if the condition is true it gives array[(-1 * 0)] (remember the
  12. condition is cast and negated) thus passing a build test with a 0-sized
  13. array.
  14. If it's false it gives array[(-1 * 1)] thus failing with a
  15. negative-sized array.
  16. Status: Upstream.
  17. Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
  18. ---
  19. lib/ccan/wscript | 11 +++++++----
  20. 1 file changed, 7 insertions(+), 4 deletions(-)
  21. diff --git a/lib/ccan/wscript b/lib/ccan/wscript
  22. index 59b8205..81039d0 100644
  23. --- a/lib/ccan/wscript
  24. +++ b/lib/ccan/wscript
  25. @@ -127,15 +127,18 @@ def configure(conf):
  26. # Only check for FILE_OFFSET_BITS=64 if off_t is normally small:
  27. # use raw routines because wrappers include previous _GNU_SOURCE
  28. # or _FILE_OFFSET_BITS defines.
  29. + # The math for these tests is:
  30. + # array[-1 * !((int)(condition)) ] (condition is true) = array[0] = builds
  31. + # array[-1 * !((int)(condition)) ] (condition is false) = array[-1] = fails
  32. conf.check(fragment="""#include <sys/types.h>
  33. - int main(void) { return !(sizeof(off_t) < 8); }""",
  34. - execute=True, msg='Checking for small off_t',
  35. + int main(void) { static int test_array[1 - 2 * !(((long int)(sizeof(off_t))) < 8)]; }""",
  36. + msg='Checking for small off_t',
  37. define_name='SMALL_OFF_T')
  38. # Unreliable return value above, hence use define.
  39. if conf.CONFIG_SET('SMALL_OFF_T'):
  40. conf.check(fragment="""#include <sys/types.h>
  41. - int main(void) { return !(sizeof(off_t) >= 8); }""",
  42. - execute=True, msg='Checking for -D_FILE_OFFSET_BITS=64',
  43. + int main(void) { static int test_array[1 - 2 * !(((long int)(sizeof(off_t))) >= 8)]; }""",
  44. + msg='Checking for -D_FILE_OFFSET_BITS=64',
  45. ccflags='-D_FILE_OFFSET_BITS=64',
  46. define_name='HAVE_FILE_OFFSET_BITS')
  47. --
  48. 1.8.3.2