From 055fa4f22f4add7a486acf495345f266934edc52 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 8 Apr 2007 02:04:21 +0000 Subject: [PATCH] Assigning values to errno would not work; the next invocation would overwrite them with the host platform errno again. We do now track changes and use a hopefully reasonable strategy for updating the host errno. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20608 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/build/libroot/errors.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/build/libroot/errors.cpp b/src/build/libroot/errors.cpp index 2ebea8c6dd..1b6c548937 100644 --- a/src/build/libroot/errors.cpp +++ b/src/build/libroot/errors.cpp @@ -159,8 +159,24 @@ _haiku_build_strerror(int errnum) int * _haiku_build_errno() { + static int previousErrno = 0; static int localErrno = 0; - localErrno = to_haiku_error(errno); + static int previousLocalErrno = 0; + + // If the localErrno has been changed and the real errno has not changed + // in the meantime, we update errno itself, so that the local update will + // be reflected. If errno has changed we always update localErrno. + int currentErrno = errno; + if (currentErrno == previousErrno) { + if (localErrno != previousLocalErrno) { + errno = previousErrno = to_host_error(localErrno); + previousLocalErrno = localErrno; + } + } else { + previousErrno = currentErrno; + previousLocalErrno = localErrno = to_haiku_error(errno); + } + return &localErrno; }