Bug 12037

Summary: Feature test macros incorrect for ftruncate() (and probably also truncate())
Product: glibc Reporter: Michael Kerrisk <mtk.manpages>
Component: libcAssignee: Ulrich Drepper <drepper.fsp>
Status: RESOLVED FIXED    
Severity: normal CC: glibc-bugs
Priority: P2 Flags: fweimer: security-
Version: 2.12   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Michael Kerrisk 2010-09-18 12:35:51 UTC
I've just been documenting the new feature test macro requirements for
truncate() and ftruncate() in glibc 2.12, and it appears that the FTMs for
ftruncate() are incorrect.

Some background. In POSIX, these functions are marked as follows:

POSIX.1-2001/SUSv3
ftruncate() no markings
truncate() marked XSI

POSIX.1-2008/SUSv4
ftruncate() no markings
truncate() no markings

Here's the history of feature test macro requirements for these two functions as
defined in <unistd.h>:

       truncate():
           Since glibc 2.12
               _BSD_SOURCE || _XOPEN_SOURCE >= 500 ||
               _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED ||
               _POSIX_C_SOURCE >= 200809L
           Before glibc 2.12:
               _BSD_SOURCE || _XOPEN_SOURCE >= 500 ||
               _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED

       ftruncate():
           Since glibc 2.12:
               _BSD_SOURCE || _XOPEN_SOURCE >= 500 ||
               _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED ||
               _POSIX_C_SOURCE >= 200809L
           Between glibc 2.3.5 and 2.11
               _BSD_SOURCE || _XOPEN_SOURCE >= 500 ||
               _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED ||
               _POSIX_C_SOURCE >= 200112L
           Before glibc 2.3.5:
               _BSD_SOURCE || _XOPEN_SOURCE >= 500 ||
               _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED

From the above, ftruncate() is no longer exposed in glibc 2.12 if
_POSIX_C_SOURCE >= 200112. This seems pretty clearly incorrect. I belive the
FTMs governing the declaration should have remained as they were pre 2.12:

#if defined __USE_BSD || defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K
Comment 1 Ulrich Drepper 2010-09-21 18:03:52 UTC
Fixed in git.