X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Ffdopendir.c;h=f7b29af30c62539f9836c3971bc990911b6701d2;hb=969fe755730d23ba7ff21ae7511f66067d0a94d8;hp=14dc111c81bfd5f6dec3284406b79edec527165d;hpb=4f1227bdeac3e4e18c9b3efb27623875e02d681d;p=gnulib.git diff --git a/lib/fdopendir.c b/lib/fdopendir.c index 14dc111c8..f7b29af30 100644 --- a/lib/fdopendir.c +++ b/lib/fdopendir.c @@ -1,5 +1,5 @@ /* provide a replacement fdopendir function - Copyright (C) 2004-2009 Free Software Foundation, Inc. + Copyright (C) 2004-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,13 +23,15 @@ #include #include -#include "openat.h" -#include "openat-priv.h" -#include "save-cwd.h" +#if !HAVE_FDOPENDIR -#if GNULIB_DIRENT_SAFER -# include "dirent--.h" -#endif +# include "openat.h" +# include "openat-priv.h" +# include "save-cwd.h" + +# if GNULIB_DIRENT_SAFER +# include "dirent--.h" +# endif /* Replacement for Solaris' function by the same name. @@ -70,32 +72,32 @@ fdopendir (int fd) save_cwd/restore_cwd. */ if (! dir && EXPECTED_ERRNO (saved_errno)) { -#if REPLACE_FCHDIR +# if REPLACE_FCHDIR const char *name = _gl_directory_name (fd); if (name) dir = opendir (name); saved_errno = errno; -#else /* !REPLACE_FCHDIR */ +# else /* !REPLACE_FCHDIR */ struct saved_cwd saved_cwd; if (save_cwd (&saved_cwd) != 0) - openat_save_fail (errno); + openat_save_fail (errno); if (fchdir (fd) != 0) - { - dir = NULL; - saved_errno = errno; - } + { + dir = NULL; + saved_errno = errno; + } else - { - dir = opendir ("."); - saved_errno = errno; + { + dir = opendir ("."); + saved_errno = errno; - if (restore_cwd (&saved_cwd) != 0) - openat_restore_fail (errno); - } + if (restore_cwd (&saved_cwd) != 0) + openat_restore_fail (errno); + } free_cwd (&saved_cwd); -#endif /* !REPLACE_FCHDIR */ +# endif /* !REPLACE_FCHDIR */ } if (dir) @@ -105,3 +107,28 @@ fdopendir (int fd) errno = saved_errno; return dir; } + +#else /* HAVE_FDOPENDIR */ + +# include +# include + +# undef fdopendir + +/* Like fdopendir, but work around GNU/Hurd bug by validating FD. */ + +DIR * +rpl_fdopendir (int fd) +{ + struct stat st; + if (fstat (fd, &st)) + return NULL; + if (!S_ISDIR (st.st_mode)) + { + errno = ENOTDIR; + return NULL; + } + return fdopendir (fd); +} + +#endif /* HAVE_FDOPENDIR */