Back to index

glibc  2.9
Functions
fdopendir.c File Reference
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <not-cancel.h>

Go to the source code of this file.

Functions

DIR * __fdopendir (int fd)

Function Documentation

DIR* __fdopendir ( int  fd)

Definition at line 28 of file fdopendir.c.

{
  struct stat64 statbuf;

  if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &statbuf), 0) < 0)
    return NULL;
  if (__builtin_expect (! S_ISDIR (statbuf.st_mode), 0))
    {
      __set_errno (ENOTDIR);
      return NULL;
    }

  /* Make sure the descriptor allows for reading.  */
  int flags = __fcntl (fd, F_GETFL);
  if (__builtin_expect (flags == -1, 0))
    return NULL;
  if (__builtin_expect ((flags & O_ACCMODE) == O_WRONLY, 0))
    {
      __set_errno (EINVAL);
      return NULL;
    }

  return __alloc_dir (fd, false, &statbuf);
}

Here is the call graph for this function: