Artsize still not quite right in CURRENT

James Ralston qralston+ml.inn-workers at andrew.cmu.edu
Thu Apr 19 04:47:36 UTC 2001


On 18 Apr 2001, Alex Kiernan wrote:

> I found a RedHat 7 box to play on here, and whilst it needs a
> #include <stdint.h> to get the uint32_t type, when run it gives:
>
> pread broken - wrote badc0de, read deadbeef
>
> [BTW someone who knows Linux better than me - should this build line
> do the right thing:
>
> gcc -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 checkpread.c]

Close, but not quite.  You're getting bitten because without at least
"-D_XOPEN_SOURCE=500" (as per the pread man page), the definitions of
the pread/pwrite functions are essentially commented out of unistd.h.
You can see what's happening if you turn on warnings:

    $ gcc -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 checkpread.c
    checkpread.c: In function `main':
    checkpread.c:38: warning: implicit declaration of function `pread'

Because pread isn't declared, the -D_FILE_OFFSET_BITS=64 doesn't have
a chance to apply to it, so when you link you wind up with the 32-bit
version of pread.

Since defining _XOPEN_SOURCE to 500 or greater automatically triggers
_LARGEFILE_SOURCE, this is the compilation command you want:

    $ gcc -Wall -D_XOPEN_SOURCE=500 -D_FILE_OFFSET_BITS=64 checkpread.c

I compiled checkpread.c on a Red Hat 7.1 system using the above
compilation command, and when run it does the correct thing (that is,
it produces no output).

Really, I don't see any reason why INN shouldn't be compiled with the
_GNU_SOURCE feature test macro on any system where the GNU C Library
is detected.  This is what glibc recommends.  To quote glibc:

     - Macro: _GNU_SOURCE
         If you define this macro, everything is included: ISO C89,
         ISO C99, POSIX.1, POSIX.2, BSD, SVID, X/Open, LFS, and GNU
         extensions.  In the cases where POSIX.1 conflicts with BSD,
         the POSIX definitions take precedence.

    [...]

       We recommend you use `_GNU_SOURCE' in new programs.  If you
    don't specify the `-ansi' option to GCC and don't define any of
    these macros explicitly, the effect is the same as defining
    `_POSIX_C_SOURCE' to 2 and `_POSIX_SOURCE', `_SVID_SOURCE', and
    `_BSD_SOURCE' to 1.

You'll still need -D_FILE_OFFSET_BITS=64, though; _GNU_SOURCE doesn't
automatically trigger that.

-- 
James Ralston, Information Technology
Software Engineering Institute
Carnegie Mellon University, Pittsburgh, PA, USA



More information about the inn-workers mailing list