Back to index

glibc  2.9
readdir_r.c
Go to the documentation of this file.
00001 /* Copyright (C) 1993,94,95,96,97,2001,02 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <errno.h>
00020 #include <limits.h>
00021 #include <stddef.h>
00022 #include <string.h>
00023 #include <dirent.h>
00024 #include <unistd.h>
00025 #include <sys/types.h>
00026 #include <hurd.h>
00027 #include <hurd/fd.h>
00028 #include "dirstream.h"
00029 
00030 
00031 /* Read a directory entry from DIRP.  */
00032 int
00033 __readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result)
00034 {
00035   if (sizeof (struct dirent64) == sizeof (struct dirent))
00036     /* We should in fact just be an alias to readdir64_r on this machine.  */
00037     return __readdir64_r (dirp,
00038                        (struct dirent64 *) entry,
00039                        (struct dirent64 **) result);
00040 
00041   struct dirent64 *result64;
00042   union
00043   {
00044     struct dirent64 d;
00045     char b[offsetof (struct dirent64, d_name) + UCHAR_MAX + 1];
00046   } u;
00047   int err;
00048 
00049   err = __readdir64_r (dirp, &u.d, &result64);
00050   if (result64)
00051     {
00052       entry->d_fileno = result64->d_fileno;
00053       entry->d_reclen = result64->d_reclen;
00054       entry->d_type = result64->d_type;
00055       entry->d_namlen = result64->d_namlen;
00056       memcpy (entry->d_name, result64->d_name, result64->d_namlen + 1);
00057       *result = entry;
00058     }
00059   else
00060     *result = NULL;
00061 
00062   return err;
00063 }
00064 
00065 weak_alias (__readdir_r, readdir_r)