Bug 15312 - SEEK_HOLE and SEEK_DATA not exported as expected
Summary: SEEK_HOLE and SEEK_DATA not exported as expected
Status: RESOLVED INVALID
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.17
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-27 14:28 UTC by Jan Schmidt
Modified: 2014-06-13 18:35 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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