CLOSEDIR(3C) Standard C Library Functions CLOSEDIR(3C)

NAME


closedir - close a directory stream

SYNOPSIS


#include <sys/types.h>
#include <dirent.h>

int
closedir(DIR *dirp);

DESCRIPTION


The closedir() function closes the directory stream referred to by the
argument dirp, which generally came from calling opendir(3C) or
fdopendir(3C). Upon return, the value of dirp will no longer point to
an accessible object of the type DIR. The underlying file descriptor
for the directory stream will be closed. This includes a DIR created
by passing a file descriptor to fdopendir(3C).

When the directory stream is closed, any memory that is associated with
the stream will no longer be valid. Most notably, the dirent
structures returned from readdir(3C) use memory associated with the
corresponding DIR * argument. Each directory stream has its own
independent memory. Closing one stream does not impact the validity of
other streams.

RETURN VALUES


Upon successful completion, the closedir() function returns 0.
Otherwise, -1 is returned and errno is set to indicate the error.

ERRORS


The closedir() function may fail if:

EBADF The dirp argument does not refer to an open
directory stream.

EINTR The closedir() function was interrupted by a signal.

INTERFACE STABILITY


Standard

MT-LEVEL
Safe

SEE ALSO


fdopendir(3C), opendir(3C), readdir(3C), attributes(7)

illumos February 25, 2021 illumos

tribblix@gmail.com :: GitHub :: Privacy