bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sys/types.h on Android includes stdint.h before defining time_t


From: Hans-Christoph Steiner
Subject: Re: sys/types.h on Android includes stdint.h before defining time_t
Date: Fri, 20 Jan 2012 10:09:43 -0500

> I'm looking at porting gnulib to Android (using the NDK), and there
> seems to be a fundamental incompatibility between the system sys/types.h
> header file and several of gnulib's header file replacements.  I get
> build errors for the following gnulib test directory:
> 
> ./gnulib-tool --create-testdir --dir m --with-tests vasprintf
> 
> I'm building it like this:
> 
> address@hidden:~/dummy-0$ ./configure CC="arm-linux-androideabi-gcc --sysroot 
> /home/jas/android-ndk-r7/platforms/android-8/arch-arm" 
> --host=arm-linux-androideabi --build=i686-pc-linux-gnu
> 
> and the error is:
> 
> arm-linux-androideabi-gcc --sysroot 
> /home/jas/android-ndk-r7/platforms/android-8/arch-arm -DHAVE_CONFIG_H -I. 
> -I.. 
> -DGNULIB_STRICT_CHECKING=1   -g -O2 -MT printf-args.o -MD -MP -MF 
> .deps/printf-args.Tpo -c -o printf-args.o printf-args.c
> In file included from 
> /home/jas/android-ndk-r7/platforms/android-8/arch-arm/usr/include/sys/time.h:33,
>                 from 
> /home/jas/android-ndk-r7/platforms/android-8/arch-arm/usr/include/time.h:32,
>                 from ./stdint.h:527,
>                 from 
> /home/jas/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/include-fixed/sys/types.h:43,
>                 from 
> /home/jas/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/include-fixed/stdio.h:64,
>                 from ./stdio.h:44,
>                 from ./wchar.h:72,
>                 from printf-args.h:42,
>                 from printf-args.c:30:
> /home/jas/android-ndk-r7/platforms/android-8/arch-arm/usr/include/linux/time.h:20:
> error: expected specifier-qualifier-list before 'time_t'
> /home/jas/android-ndk-r7/platforms/android-8/arch-arm/usr/include/linux/time.h:26:
> error: expected specifier-qualifier-list before 'time_t'
> 
> The reason is that printf-args.c includes some header files that in turn
> includes the system sys/types.h.  So far great.  However, the system
> sys/types.h start like this:
> 
> #ifndef _SYS_TYPES_H_
> #define _SYS_TYPES_H_
> 
> #define __need_size_t
> #define __need_ptrdiff_t
> #include <stddef.h>
> #include <stdint.h>
> 
> later down in the system sys/types.h file there is the definition of
> time_t:
> 
> typedef __kernel_time_t       time_t;
> 
> Thus gnulib's stdint.h file gets included from the system sys/types.h
> before time_t is declared.  Further down in gnulib's stdint.h there is:
> 
> #if @HAVE_WCHAR_H@ && ! (defined WCHAR_MIN && defined WCHAR_MAX)
>  /* BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
>     included before <wchar.h>.  */
> # include <stddef.h>
> # include <stdio.h>
> # include <time.h>
> 
> Thus the system time.h gets included, and it includes the system
> sys/time.h which first includes sys/types.h and then linux/time.h.
> However, including sys/types.h here is a no-op since _SYS_TYPES_H is
> already defined.  So back to the system sys/time.h which includes
> linux/time.h.  And then the system linux/time.h contains:
> 
> struct timespec {
> time_t tv_sec;
> long tv_nsec;
> };
> 
> This doesn't work because time_t is not yet defined.
> 
> Does anyone see a clean way out of this?
> 
> /Simon

I don't have an answer to this really, but I can provide a little context on 
Android, which might be helpful.  Its the Linux kernel using bionic libc, which 
is a very minimal libc.  Sometimes, when useful things that are not in the 
bionic libc, the official Android advice is to get them from libstdc++, which I 
believe is the GNU one.

The headers are a bit of a mix.  It seems that many of them come from NetBSD 
and OpenBSD, while some seem to be written for Android specifically.  The 
headers in linux/* contain this interesting note:

***   This header was automatically generated from a Linux kernel header
***   of the same name, to make information necessary for userspace to
***   call into the kernel available to libc.  It contains only constants,
***   structures, and macros generated from the original header, and thus,
***   contains no copyrightable information.

.hc




reply via email to

[Prev in Thread] Current Thread [Next in Thread]