X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fopendir-safer.c;h=e31da884980a4cfe9b0a76559ca4377131f59b32;hb=1276a2c5f24c0c932426aca9c899fa524d2443f2;hp=8c399d0ca0789544307c2beb514acbcb036d9aaa;hpb=4f1227bdeac3e4e18c9b3efb27623875e02d681d;p=gnulib.git diff --git a/lib/opendir-safer.c b/lib/opendir-safer.c index 8c399d0ca..e31da8849 100644 --- a/lib/opendir-safer.c +++ b/lib/opendir-safer.c @@ -1,6 +1,6 @@ /* Invoke opendir, but avoid some glitches. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2014 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;