Back to index

glibc  2.9
Functions
dirent.h File Reference
#include <dirstream.h>
#include <dirent/dirent.h>
#include <sys/stat.h>
#include <stdbool.h>

Go to the source code of this file.

Functions

DIR * __opendir (__const char *__name)
DIR * __fdopendir (int __fd)
int __closedir (DIR *__dirp)
struct dirent__readdir (DIR *__dirp)
struct dirent64__readdir64 (DIR *__dirp)
int __readdir_r (DIR *__dirp, struct dirent *__entry, struct dirent **__result)
int __readdir64_r (DIR *__dirp, struct dirent64 *__entry, struct dirent64 **__result)
int __scandir64 (__const char *__dir, struct dirent64 ***__namelist, int(*__selector)(__const struct dirent64 *), int(*__cmp)(__const void *, __const void *))
__ssize_t __getdents (int __fd, char *__buf, size_t __nbytes) internal_function
__ssize_t __getdents64 (int __fd, char *__buf, size_t __nbytes) internal_function
int __alphasort64 (const void *a, const void *b) __attribute_pure__
int __versionsort64 (const void *a, const void *b) __attribute_pure__
DIR * __alloc_dir (int fd, bool close_fd, const struct stat64 *statp) internal_function

Function Documentation

DIR* __alloc_dir ( int  fd,
bool  close_fd,
const struct stat64 statp 
)

Definition at line 161 of file opendir.c.

{
  /* We always have to set the close-on-exit flag if the user provided
     the file descriptor.  Otherwise only if we have no working
     O_CLOEXEC support.  */
#ifdef O_CLOEXEC
  if (! close_fd || ! check_have_o_cloexec (fd))
#endif
    {
      if (__builtin_expect (__fcntl (fd, F_SETFD, FD_CLOEXEC), 0) < 0)
       goto lose;
    }

  const size_t default_allocation = (BUFSIZ < sizeof (struct dirent64)
                                 ? sizeof (struct dirent64) : BUFSIZ);
  size_t allocation;
#ifdef _STATBUF_ST_BLKSIZE
  if (__builtin_expect ((size_t) statp->st_blksize >= sizeof (struct dirent64),
                     1))
    allocation = statp->st_blksize;
  else
#endif
    allocation = default_allocation;

  DIR *dirp = (DIR *) malloc (sizeof (DIR) + allocation);
  if (dirp == NULL)
    {
#ifdef _STATBUF_ST_BLKSIZE
      if (allocation == statp->st_blksize
         && allocation != default_allocation)
       {
         allocation = default_allocation;
         dirp = (DIR *) malloc (sizeof (DIR) + allocation);
       }
      if (dirp == NULL)
#endif
      lose:
       {
         if (close_fd)
           {
             int save_errno = errno;
             close_not_cancel_no_status (fd);
             __set_errno (save_errno);
           }
         return NULL;
       }
    }

  dirp->fd = fd;
#ifndef NOT_IN_libc
  __libc_lock_init (dirp->lock);
#endif
  dirp->allocation = allocation;
  dirp->size = 0;
  dirp->offset = 0;
  dirp->filepos = 0;

  return dirp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int __alphasort64 ( const void *  a,
const void *  b 
)

Definition at line 23 of file alphasort64.c.

{
  return strcoll ((*(const struct dirent64 **) a)->d_name,
                (*(const struct dirent64 **) b)->d_name);
}

Here is the call graph for this function:

int __closedir ( DIR *  __dirp)

Definition at line 27 of file closedir.c.

{
  __set_errno (ENOSYS);
  return -1;
}

Here is the call graph for this function:

DIR* __fdopendir ( int  __fd)

Definition at line 27 of file fdopendir.c.

{
  __set_errno (ENOSYS);
  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

__ssize_t __getdents ( int  __fd,
char *  __buf,
size_t  __nbytes 
)

Definition at line 25 of file getdents.c.

{
  return getdirent (fd, buf, count);
}

Here is the caller graph for this function:

__ssize_t __getdents64 ( int  __fd,
char *  __buf,
size_t  __nbytes 
)
DIR* __opendir ( __const char *  __name)
struct dirent* __readdir ( DIR *  __dirp) [read]

Definition at line 25 of file readdir.c.

{
  __set_errno (ENOSYS);
  return NULL;
}
struct dirent64* __readdir64 ( DIR *  __dirp) [read]

Definition at line 25 of file readdir64.c.

{
  __set_errno (ENOSYS);
  return NULL;
}

Here is the call graph for this function:

int __readdir64_r ( DIR *  __dirp,
struct dirent64 __entry,
struct dirent64 **  __result 
)

Definition at line 29 of file readdir64_r.c.

{
  struct dirent64 *dp;
  error_t err = 0;

  if (dirp == NULL)
    {
      errno = EINVAL;
      return errno;
    }

  __libc_lock_lock (dirp->__lock);

  do
    {
      if (dirp->__ptr - dirp->__data >= dirp->__size)
       {
         /* We've emptied out our buffer.  Refill it.  */

         char *data = dirp->__data;
         int nentries;

         if (err = HURD_FD_PORT_USE (dirp->__fd,
                                  __dir_readdir (port,
                                               &data, &dirp->__size,
                                               dirp->__entry_ptr,
                                               -1, 0, &nentries)))
           {
             __hurd_fail (err);
             dp = NULL;
             break;
           }

         /* DATA now corresponds to entry index DIRP->__entry_ptr.  */
         dirp->__entry_data = dirp->__entry_ptr;

         if (data != dirp->__data)
           {
             /* The data was passed out of line, so our old buffer is no
               longer useful.  Deallocate the old buffer and reset our
               information for the new buffer.  */
             __vm_deallocate (__mach_task_self (),
                            (vm_address_t) dirp->__data,
                            dirp->__allocation);
             dirp->__data = data;
             dirp->__allocation = round_page (dirp->__size);
           }

         /* Reset the pointer into the buffer.  */
         dirp->__ptr = dirp->__data;

         if (nentries == 0)
           {
             /* End of file.  */
             dp = NULL;
             break;
           }

         /* We trust the filesystem to return correct data and so we
            ignore NENTRIES.  */
       }

      dp = (struct dirent64 *) dirp->__ptr;
      dirp->__ptr += dp->d_reclen;
      ++dirp->__entry_ptr;

      /* Loop to ignore deleted files.  */
    } while (dp->d_fileno == 0);

  if (dp)
    {
      *entry = *dp;
      memcpy (entry->d_name, dp->d_name, dp->d_namlen + 1);
      *result = entry;
    }
  else
    *result = NULL;

  __libc_lock_unlock (dirp->__lock);

  return dp ? 0 : err ? errno : 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int __readdir_r ( DIR *  __dirp,
struct dirent __entry,
struct dirent **  __result 
)

Definition at line 26 of file readdir_r.c.

{
  __set_errno (ENOSYS);
  *result = NULL;
  return ENOSYS;
}

Here is the call graph for this function:

int __scandir64 ( __const char *  __dir,
struct dirent64 ***  __namelist,
int(*)(__const struct dirent64 *)  __selector,
int(*)(__const void *, __const void *)  __cmp 
)
int __versionsort64 ( const void *  a,
const void *  b 
)

Definition at line 23 of file versionsort64.c.

{
  return __strverscmp ((*(const struct dirent64 **) a)->d_name,
                     (*(const struct dirent64 **) b)->d_name);
}

Here is the call graph for this function: