Bug 15312

Summary: SEEK_HOLE and SEEK_DATA not exported as expected
Product: glibc Reporter: Jan Schmidt <sourceware.org>
Component: libcAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED INVALID    
Severity: normal CC: aj, drepper.fsp, mtk.manpages
Priority: P2 Flags: fweimer: security-
Version: 2.17   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Jan Schmidt 2013-03-27 14:28:10 UTC
The man pages for lseek(2) state one should include <sys/types.h> and <unistd.h>. Doing so does not export SEEK_HOLE and SEEK_DATA.

Freshly built from git version 2.17.90, top commit 28831a9a671b109e49d0a4ddce00a08d734bfc97.

The following dummy source should build but doesn't:

--
#include <sys/types.h>
#include <unistd.h>

void
main(void)
{
        lseek(0, 0, SEEK_DATA);
        lseek(0, 0, SEEK_HOLE);
}
--

Errors:
/tmp/test.c: In function 'main':
/tmp/test.c:7: error: 'SEEK_DATA' undeclared (first use in this function)
/tmp/test.c:7: error: (Each undeclared identifier is reported only once
/tmp/test.c:7: error: for each function it appears in.)
/tmp/test.c:8: error: 'SEEK_HOLE' undeclared (first use in this function)

Including <linux/fs.h> is a work-around, but that should really be included internally.
Comment 1 Andreas Jaeger 2013-03-27 14:50:43 UTC
Please report this to the man pages project, I've added the man pages maintainer to this report as well.

For details on reporting man-pages bugs: https://www.kernel.org/doc/man-pages/reporting_bugs.html

marking as INVALID since it's not a bug in glibc itself but in the man-pages.
Comment 2 Jan Schmidt 2013-03-27 15:04:55 UTC
So you really want a user space app to include <linux/fs.h> directly!?
Comment 3 Andreas Jaeger 2013-03-27 15:12:27 UTC
No, I want the man pages clear enough that you know to add a define for _GNU_SOURCE.

Try the following
#define _GNU_SOURCE 1
#include <sys/types.h>
#include <unistd.h>

void
main(void)
{
        lseek(0, 0, SEEK_DATA);
        lseek(0, 0, SEEK_HOLE);
}

have a look at /usr/include/unistd.h and read the glibc info pages about feature test macros to learn about _GNU_SOURCE.
Comment 4 Jan Schmidt 2013-03-27 17:55:05 UTC
Ok, thanks.
Comment 5 Michael Kerrisk 2013-03-27 20:50:59 UTC
(In reply to comment #3)
> No, I want the man pages clear enough that you know to add a define for

Thanks, Andreas, for adding me. I've added this text to the lseek(2) page:

       The _GNU_SOURCE feature test macro must be defined in order  to
       obtain   the   definitions  of  SEEK_DATA  and  SEEK_HOLE  from
       <unistd.h>.

> have a look at /usr/include/unistd.h and read the glibc info pages about
> feature test macros to learn about _GNU_SOURCE.

Or, for even more detail:

http://man7.org/linux/man-pages/man7/feature_test_macros.7.html