Name

scandirat — scan a directory relative to a directory file descriptor

Synopsis

#define _GNU_SOURCE          /* See feature_test_macros(7) */

#include <fcntl.h>           /* Definition of AT_* constants */
#include <dirent.h>
int scandirat( int dirfd,
  const char *dirp,
  struct dirent ***namelist,
  int (*filter)(const struct dirent *),
  int (*compar)(const struct dirent **, const struct dirent **));
 

DESCRIPTION

The scandirat() system call operates in exactly the same way as scandir(3), except for the differences described in this manual page.

If the pathname given in dirp is relative, then it is interpreted relative to the directory referred to by the file descriptor dirfd (rather than relative to the current working directory of the calling process, as is done by scandir(3) for a relative pathname).

If dirp is relative and dirfd is the special value AT_FDCWD, then dirp is interpreted relative to the current working directory of the calling process (like scandir(3)).

If dirp is absolute, then dirfd is ignored.

RETURN VALUE

On success, scandirat() returns the number of directory entries selected. On error, −1 is returned and errno is set to indicate the error.

ERRORS

The same errors that occur for scandir(3) can also occur for scandirat(). The following additional errors can occur for scandirat():

EBADF

dirfd is not a valid file descriptor.

ENOTDIR

dirp is a relative path and dirfd is a file descriptor referring to a file other than a directory.

VERSIONS

scandirat() was added to glibc in version 2.15.

CONFORMING TO

This function is a GNU extension.

NOTES

See openat(2) for an explanation of the need for scandirat().

SEE ALSO

openat(2), scandir(3), path_resolution(7)

COLOPHON

This page is part of release 3.52 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man−pages/.


  Copyright (c) 2012, Mark R. Bannister <cambridgeusers.sourceforge.net>
       based on text in mkfifoat.3 Copyright (c) 2006, Michael Kerrisk

%%%LICENSE_START(GPLv2+_DOC_FULL)
This is free documentation; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.

The GNU General Public License's references to "object code"
and "executables" are to be interpreted as the output of any
document formatting or typesetting system, including
intermediate and printed output.

This manual is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public
License along with this manual; if not, see
<http://www.gnu.org/licenses/>.
%%%LICENSE_END