X-Git-Url: https://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fopendir-safer.c;h=432071658915194e8cae29804e8fc4447642a5a2;hb=e1baaf8d7c7da5c45041f3ecaf227dfd03c01891;hp=f1e5fb7aa88ebdce4a8493e2eb8c911a775e4258;hpb=d60f3b0c6b0f93a601acd1cfd3923f94ca05abb0;p=gnulib.git diff --git a/lib/opendir-safer.c b/lib/opendir-safer.c index f1e5fb7aa..432071658 100644 --- a/lib/opendir-safer.c +++ b/lib/opendir-safer.c @@ -1,6 +1,6 @@ /* Invoke opendir, but avoid some glitches. - Copyright (C) 2009-2011 Free Software Foundation, Inc. + Copyright (C) 2009-2012 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 @@ -50,10 +50,18 @@ opendir_safer (char const *name) int e; #if HAVE_FDOPENDIR || GNULIB_FDOPENDIR int f = dup_safer (fd); - newdp = fdopendir (f); - e = errno; - if (! newdp) - close (f); + if (f < 0) + { + e = errno; + newdp = NULL; + } + else + { + newdp = fdopendir (f); + e = errno; + if (! newdp) + close (f); + } #else /* !FDOPENDIR */ newdp = opendir_safer (name); e = errno;