Bug 164787 - dirfd() function not available when _POSIX_C_SOURCE is defined
Summary: dirfd() function not available when _POSIX_C_SOURCE is defined
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: standards (show other bugs)
Version: 8.2-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: Jilles Tjoelker
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-05 07:30 UTC by Eric Wong
Modified: 2015-02-01 21:14 UTC (History)
1 user (show)

See Also:
jilles: mfc-stable10+
jilles: mfc-stable9-
jilles: mfc-stable8-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Wong 2012-02-05 07:30:09 UTC
dirfd(3) is now specified in POSIX.1-2008, so it should be available
when the _POSIX_C_SOURCE macro is defined to >= 200809L

However, /usr/include/dirent.h only exposes the dirfd() macro if
__BSD_VISIBLE is defined.  However, __BSD_VISIBLE appears to be false
if _POSIX_C_SOURCE is defined.

Fix: 

It's probably best to add dirfd() as a function to libc, allowing the opacity
of the struct _dir_desc to be preserved.
How-To-Repeat: /*
 * To build + link:
 *   gcc -o dirfdtest dirfdtest.c
 * having _POSIX_C_SOURCE defined will cause this to fail link
 */
#define _POSIX_C_SOURCE 200809L
#include <dirent.h>
int main(void)
{
        DIR *dir = opendir(".");

        dirfd(dir);

        return 0;
}
Comment 1 Jilles Tjoelker freebsd_committer freebsd_triage 2013-05-09 21:25:57 UTC
State Changed
From-To: open->patched

This is fixed in 10-current (with a function version of dirfd(), not by 
me) but not in older branches.
Comment 2 Jilles Tjoelker freebsd_committer freebsd_triage 2015-02-01 21:14:23 UTC
Fixed in 10-current, no MFC planned to older branches.