X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fopendir-safer.c;h=3726f88b13f5a74afd7141447ca7673ee711e5a7;hb=67d133ee7b512af59a392f533b17302d71e937db;hp=36d47329bbbe632ba1eae055b1aceaecb95b74b9;hpb=b2e2010c7c902235b5efb5bd3c6529f61b093aa4;p=gnulib.git diff --git a/lib/opendir-safer.c b/lib/opendir-safer.c index 36d47329b..3726f88b1 100644 --- a/lib/opendir-safer.c +++ b/lib/opendir-safer.c @@ -1,6 +1,6 @@ /* Invoke opendir, but avoid some glitches. - Copyright (C) 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 2009-2011 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;