+2009-02-05 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/opendir.c (__alloc_dir): We have a lot more memory
+ today than when the original code was written. Use larger
+ buffers. This also makes it unnecessary to have stat information,
+ if this causes extra efforts.
+ (__opendir): In case O_DIRECTORY works, don't call fstat just for
+ __alloc_dir.
+
2009-02-03 Andrew Stubbs <ams@codesourcery.com>
* sysdeps/sh/sh4/dl-trampoline.S: Only set HAVE_FPU if __SH_FPU_ANY__
-/* Copyright (C) 1991-1996,98,2000-2003,2005,2007
+/* Copyright (C) 1991-1996,98,2000-2003,2005,2007,2009
Free Software Foundation, Inc.
This file is part of the GNU C Library.
__opendir (const char *name)
{
struct stat64 statbuf;
+ struct stat64 *statp = NULL;
if (__builtin_expect (name[0], '\1') == '\0')
{
if (__builtin_expect (fd, 0) < 0)
return NULL;
- /* Now make sure this really is a directory and nothing changed since
- the `stat' call. We do not have to perform the test for the
- descriptor being associated with a directory if we know the
- O_DIRECTORY flag is honored by the kernel. */
- if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &statbuf), 0) < 0)
- goto lose;
#ifdef O_DIRECTORY
if (o_directory_works <= 0)
#endif
{
+ /* Now make sure this really is a directory and nothing changed since
+ the `stat' call. */
+ if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &statbuf), 0) < 0)
+ goto lose;
if (__builtin_expect (! S_ISDIR (statbuf.st_mode), 0))
{
__set_errno (ENOTDIR);
close_not_cancel_no_status (fd);
return NULL;
}
+ statp = &statbuf;
}
- return __alloc_dir (fd, true, &statbuf);
+ return __alloc_dir (fd, true, statp);
}
weak_alias (__opendir, opendir)
goto lose;
}
- const size_t default_allocation = (BUFSIZ < sizeof (struct dirent64)
- ? sizeof (struct dirent64) : BUFSIZ);
- size_t allocation;
+ const size_t default_allocation = (4 * BUFSIZ < sizeof (struct dirent64)
+ ? sizeof (struct dirent64) : 4 * BUFSIZ);
+ const size_t small_allocation = (BUFSIZ < sizeof (struct dirent64)
+ ? sizeof (struct dirent64) : BUFSIZ);
+ size_t allocation = default_allocation;
#ifdef _STATBUF_ST_BLKSIZE
- if (__builtin_expect ((size_t) statp->st_blksize >= sizeof (struct dirent64),
- 1))
+ if (statp != NULL && default_allocation < statp->st_blksize)
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);
- }
+ allocation = small_allocation;
+ dirp = (DIR *) malloc (sizeof (DIR) + allocation);
+
if (dirp == NULL)
-#endif
lose:
{
if (close_fd)