xref: /illumos-gate/usr/src/man/man3c/dirfd.3c (revision 3c30f56df862431210f98c7c8f13cf1362b9c574)
te
Copyright (c) 2007, Sun Microsystems Inc. All Rights Reserved.
Portions of this manual page are derived from documentation obtained from linuxmanpages.com
The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
DIRFD 3C "Oct 24, 2007"
NAME
dirfd - get directory stream file descriptor
SYNOPSIS

#include <dirent.h>

int dirfd(DIR *dir);
DESCRIPTION

The dirfd() function returns the file descriptor associated with the directory stream dir.

This file descriptor is the one used internally by the directory stream operations. See opendir(3C), closedir(3C), readdir(3C), rewinddir(3C), seekdir(3C), telldir(3C). The file descriptor is automatically closed when closedir() is called for the directory stream dir or when one of the exec functions is called. See exec(2).

The file descriptor can safely be used only by functions that do not depend on or alter the file position, such as fstat(2) and fchdir(2). Closing the file descriptor with close(2) or modifying the file position by means other than the directory stream operations listed above causes undefined behavior to occur when one of the directory stream operations is subsequently called with the directory stream dir.

RETURN VALUES

Upon successful completion, the dirfd() function returns an open file descriptor for the directory associated with the directory stream dir.

ERRORS

There are no defined error returns. Passing an invalid directory stream as an argument to the dirfd() function results in undefined behavior.

USAGE

The dirfd() function is intended to be used to obtain a file descriptor for use with the fchdir() function.

ATTRIBUTES

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE ATTRIBUTE VALUE
Interface Stability Committed
MT-Level Safe
SEE ALSO

close(2), exec(2), fchdir(2), fstat(2), closedir(3C), opendir(3C), readdir(3C), rewinddir(3C), seekdir(3C), telldir(3C), attributes(5)