diff options
Diffstat (limited to 'sysdeps/unix/opendir.c')
-rw-r--r-- | sysdeps/unix/opendir.c | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/sysdeps/unix/opendir.c b/sysdeps/unix/opendir.c index 6aa738f..5e03ed9 100644 --- a/sysdeps/unix/opendir.c +++ b/sysdeps/unix/opendir.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-1996,98,2000-2003,2005 Free Software Foundation, Inc. +/* Copyright (C) 1991-1996,98,2000-2002, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -78,7 +78,11 @@ tryopen_o_directory (void) DIR * __opendir (const char *name) { + DIR *dirp; struct stat64 statbuf; + int fd; + size_t allocation; + int save_errno; if (__builtin_expect (name[0], '\1') == '\0') { @@ -109,7 +113,7 @@ __opendir (const char *name) } } - int fd = open_not_cancel_2 (name, O_RDONLY|O_NDELAY|EXTRA_FLAGS|O_LARGEFILE); + fd = open_not_cancel_2 (name, O_RDONLY|O_NDELAY|EXTRA_FLAGS|O_LARGEFILE); if (__builtin_expect (fd, 0) < 0) return NULL; @@ -125,30 +129,18 @@ __opendir (const char *name) { if (__builtin_expect (! S_ISDIR (statbuf.st_mode), 0)) { - __set_errno (ENOTDIR); - lose: - close_not_cancel_no_status (fd); - return NULL; + save_errno = ENOTDIR; + goto lose; } } - return __alloc_dir (fd, true, &statbuf); -} -weak_alias (__opendir, opendir) - - -DIR * -internal_function -__alloc_dir (int fd, bool close_fd, const struct stat64 *statp) -{ if (__builtin_expect (__fcntl (fd, F_SETFD, FD_CLOEXEC), 0) < 0) goto lose; - size_t allocation; #ifdef _STATBUF_ST_BLKSIZE - if (__builtin_expect ((size_t) statp->st_blksize >= sizeof (struct dirent64), + if (__builtin_expect ((size_t) statbuf.st_blksize >= sizeof (struct dirent64), 1)) - allocation = statp->st_blksize; + allocation = statbuf.st_blksize; else #endif allocation = (BUFSIZ < sizeof (struct dirent64) @@ -156,16 +148,13 @@ __alloc_dir (int fd, bool close_fd, const struct stat64 *statp) const int pad = -sizeof (DIR) % __alignof__ (struct dirent64); - DIR *dirp = (DIR *) malloc (sizeof (DIR) + allocation + pad); + dirp = (DIR *) malloc (sizeof (DIR) + allocation + pad); if (dirp == NULL) lose: { - if (close_fd) - { - int save_errno = errno; - close_not_cancel_no_status (fd); - __set_errno (save_errno); - } + save_errno = errno; + close_not_cancel_no_status (fd); + __set_errno (save_errno); return NULL; } memset (dirp, '\0', sizeof (DIR)); @@ -177,3 +166,4 @@ __alloc_dir (int fd, bool close_fd, const struct stat64 *statp) return dirp; } +weak_alias (__opendir, opendir) |