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

Bug#331064: Compilation fails with sys/mman.h mmap with -std=c89 on GCC 4.0.1

Package: libc6-dev
Version: 2.3.5-6


I'm trying to compile this:

/* #define __USE_MISC */

#include <sys/mman.h>
#include <unistd.h>

static int pageCount(size_t len)
	unsigned long ps = getpagesize();
	return ((len + (ps - 1)) / ps) * ps;

static void* execMalloc(size_t requested_length)
	const int MMAP_BASE_ADDRESS = 1024*1024;
	void* addr = (mmap (((void *) MMAP_BASE_ADDRESS),
						/* Ignored by GNU/Linux, required by FreeBSD and Solaris. */
	return ((addr == MAP_FAILED) ? 0 : addr);

with gcc 4.0.1.  The above fails to compile with -std=c89:

janne@nurbian:~/dev$ gcc -std=c89 -c mmap.c
mmap.c: In function 'execMalloc':
mmap.c:14: error: 'MAP_ANONYMOUS' undeclared (first use in this function)
mmap.c:14: error: (Each undeclared identifier is reported only once
mmap.c:14: error: for each function it appears in.)

If I don't specify -std=c89, it works nicely.  If I define __USE_MISC,
then it compiles again.

Is this the way it should work?

I am using Debian GNU/Linux 2.6.

janne@nurbian:~/dev$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib --enable-nls
--without-included-gettext --enable-threads=posix
--program-suffix=-4.0 --enable-__cxa_atexit
--enable-libstdcxx-allocator=mt --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk
--enable-mpfr --disable-werror --enable-checking=release
Thread model: posix
gcc version 4.0.1 (Debian 4.0.1-2)

Reply to: