[PATCH 3/3] build: find FILE_OFFSET_BITS via array

Gustavo Zacarias gustavo at zacarias.com.ar
Thu Jan 30 14:59:05 MST 2014


On 01/30/2014 06:51 PM, Andrew Bartlett wrote:

> On Thu, 2014-01-30 at 17:59 -0300, Gustavo Zacarias wrote:
>> This makes cross-compiling happy, use a trick similar to autoconf's
>> AC_CHECK_SIZEOF macro.
>>
>> Signed-off-by: Gustavo Zacarias <gustavo at zacarias.com.ar>
>> ---
>>  lib/ccan/wscript | 8 ++++----
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/lib/ccan/wscript b/lib/ccan/wscript
>> index 59b8205..626fde3 100644
>> --- a/lib/ccan/wscript
>> +++ b/lib/ccan/wscript
>> @@ -128,14 +128,14 @@ def configure(conf):
>>      # use raw routines because wrappers include previous _GNU_SOURCE
>>      # or _FILE_OFFSET_BITS defines.
>>      conf.check(fragment="""#include <sys/types.h>
>> -               int main(void) { return !(sizeof(off_t) < 8); }""",
>> -               execute=True, msg='Checking for small off_t',
>> +               int main(void) { static int test_array[1 - 2 * !(((long int)(sizeof(off_t))) < 8)]; }""",
>> +               msg='Checking for small off_t',
>>                 define_name='SMALL_OFF_T')
>>      # Unreliable return value above, hence use define.
>>      if conf.CONFIG_SET('SMALL_OFF_T'):
>>          conf.check(fragment="""#include <sys/types.h>
>> -                   int main(void) { return !(sizeof(off_t) >= 8); }""",
>> -                   execute=True, msg='Checking for -D_FILE_OFFSET_BITS=64',
>> +		   int main(void) { static int test_array[1 - 2 * !(((long int)(sizeof(off_t))) >= 8)]; }""",
>> +                   msg='Checking for -D_FILE_OFFSET_BITS=64',
>>                     ccflags='-D_FILE_OFFSET_BITS=64',
>>                     define_name='HAVE_FILE_OFFSET_BITS')
>>  
> 
> This looks insane, but I see how it works.  WOW.
> 
> I'll double-check this, and then get this in soon.  Thanks for all your
> hard work on this. 
> 
> Andrew Bartlett
> 

Hehe :)

1-2 = -1
-1 * (int)true(1) = -1
-1 * (int)false(0) = 0

So you get a valid or invalid array based on the condition.
This can also be used to get rid of all the sizeof() cache answers in an
iterative fashion, possibly only when cross-compiling to avoid the speed
penalty, if you're OK with this kind of solution.
Thanks.
Regards.



More information about the samba-technical mailing list