X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Ffdopendir.c;h=c3643066305ea43a1ad68b722d54e1e1cbb4310c;hb=d1d75d5540bf75df8bc41c85b5a9fd111ca1f2dd;hp=3bc13acf4126a1aae1ee2704368d41be240e1f97;hpb=eeb36a484013c26402222f677f53a20e3f8488e2;p=gnulib.git diff --git a/lib/fdopendir.c b/lib/fdopendir.c index 3bc13acf4..c36430663 100644 --- a/lib/fdopendir.c +++ b/lib/fdopendir.c @@ -23,9 +23,15 @@ #include #include -#include "openat.h" -#include "openat-priv.h" -#include "save-cwd.h" +#if !HAVE_FDOPENDIR + +# 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. @@ -66,12 +72,12 @@ 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); @@ -91,7 +97,7 @@ fdopendir (int fd) } free_cwd (&saved_cwd); -#endif /* !REPLACE_FCHDIR */ +# endif /* !REPLACE_FCHDIR */ } if (dir) @@ -101,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 */