summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authormckay <mckay@FreeBSD.org>1998-01-15 13:52:55 +0000
committermckay <mckay@FreeBSD.org>1998-01-15 13:52:55 +0000
commit46ca486c3c21327f96b98da48c5055699c866df1 (patch)
tree803b5aa5ade134be5801058c12aca9119de27993 /lib/libc
parentcb201a4a429b174bc5a167c81a652875386775ec (diff)
downloadFreeBSD-src-46ca486c3c21327f96b98da48c5055699c866df1.zip
FreeBSD-src-46ca486c3c21327f96b98da48c5055699c866df1.tar.gz
Return the correct errno from getcwd() even if free() or closedir()
overwrites it. This actually showed up when running under an old kernel when free() called the madvise() stub which set errno, causing getcwd() to return EOPNOTSUPP instead of ERANGE.
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/gen/getcwd.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/libc/gen/getcwd.c b/lib/libc/gen/getcwd.c
index 344a418..f178784 100644
--- a/lib/libc/gen/getcwd.c
+++ b/lib/libc/gen/getcwd.c
@@ -268,10 +268,14 @@ notfound:
errno = save_errno ? save_errno : ENOENT;
/* FALLTHROUGH */
err:
+ save_errno = errno;
+
if (ptsize)
free(pt);
if (dir)
(void) closedir(dir);
free(up);
+
+ errno = save_errno;
return (NULL);
}
OpenPOWER on IntegriCloud