aboutsummaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
Diffstat (limited to 'compat')
-rw-r--r--compat/openat.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/compat/openat.c b/compat/openat.c
index 5cd9e551..6b04eedc 100644
--- a/compat/openat.c
+++ b/compat/openat.c
@@ -40,8 +40,12 @@ openat(int fd, const char *path, int flags, ...)
dotfd = open(".", O_RDONLY);
if (dotfd == -1)
return (-1);
- if (fchdir(fd) != 0)
+ if (fchdir(fd) != 0) {
+ saved_errno = errno;
+ close(dotfd);
+ errno = saved_errno;
return (-1);
+ }
}
retval = open(path, flags, mode);