X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fgetcwd.c;h=a185ef3c6b7cc7eee0b871f570fa0aaa27f8030f;hb=57fdfd3f8ec62b105c53bcdf6f127c35c7fe7391;hp=3cdc113916098b0f65043f91916d18a91947269f;hpb=d52c5b93a562113d859c264bbb92f5c0b8c5ae77;p=pspp diff --git a/lib/getcwd.c b/lib/getcwd.c index 3cdc113916..a185ef3c6b 100644 --- a/lib/getcwd.c +++ b/lib/getcwd.c @@ -2,23 +2,23 @@ Foundation, Inc. This file is part of the GNU C Library. - This program is free software; you can redistribute it and/or modify + 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 - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ #if !_LIBC # include # include +# include "dirfd.h" #endif #include @@ -234,6 +234,8 @@ __getcwd (char *buf, size_t size) dirstream = fdopendir (fd); if (dirstream == NULL) goto lose; + /* Reset fd. It may have been closed by fdopendir. */ + fd = dirfd (dirstream); fd_needs_closing = false; #else dirstream = __opendir (dotlist); @@ -388,7 +390,7 @@ __getcwd (char *buf, size_t size) used = dir + allocated - dirp; memmove (dir, dirp, used); - if (buf == NULL && size == 0) + if (size == 0) /* Ensure that the buffer is only as large as necessary. */ buf = realloc (dir, used);