X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fopendir-safer.c;h=0052ce1dadfbfe2768684cec498021e25e9a78f0;hb=5556cec1e3f87122e1b0e7bf82f1f75c57219a21;hp=f1e5fb7aa88ebdce4a8493e2eb8c911a775e4258;hpb=d60f3b0c6b0f93a601acd1cfd3923f94ca05abb0;p=gnulib.git diff --git a/lib/opendir-safer.c b/lib/opendir-safer.c index f1e5fb7aa..0052ce1da 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-2013 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;