From e99182dab3093f1645f9e4ff216aa752d7443fb1 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 1 Jan 2026 13:47:45 +0000 Subject: Save/restore errno in all safe wrappers --- src/libstddjb/open3.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/libstddjb/open3.c') diff --git a/src/libstddjb/open3.c b/src/libstddjb/open3.c index a9ff9e6..b7e5a4e 100644 --- a/src/libstddjb/open3.c +++ b/src/libstddjb/open3.c @@ -13,9 +13,11 @@ int open3 (char const *s, unsigned int flags, unsigned int mode) { + int e = errno ; int r ; do r = open(s, flags, mode) ; while (r == -1 && errno == EINTR) ; + if (r >= 0) errno = e ; return r ; } @@ -23,6 +25,7 @@ int open3 (char const *s, unsigned int flags, unsigned int mode) int open3 (char const *s, unsigned int flags, unsigned int mode) { + int e = errno ; int fd ; do fd = open(s, flags & ~O_CLOEXEC, mode) ; while (fd == -1 && errno == EINTR) ; @@ -32,6 +35,7 @@ int open3 (char const *s, unsigned int flags, unsigned int mode) fd_close(fd) ; return -1 ; } + errno = e ; return fd ; } -- cgit v1.3.1