From af0216251b94e751baa47146ac9609db70793b8e Mon Sep 17 00:00:00 2001 From: Jay Satiro Date: Mon, 19 Jun 2017 00:52:38 -0400 Subject: curl_setup_once: Remove ERRNO/SET_ERRNO macros Prior to this change (SET_)ERRNO mapped to GetLastError/SetLastError for Win32 and regular errno otherwise. I reviewed the code and found no justifiable reason for conflating errno on WIN32 with GetLastError/SetLastError. All Win32 CRTs support errno, and any Win32 multithreaded CRT supports thread-local errno. Fixes https://github.com/curl/curl/issues/895 Closes https://github.com/curl/curl/pull/1589 --- lib/strerror.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'lib/strerror.c') diff --git a/lib/strerror.c b/lib/strerror.c index 7e5cde47b..35dc0a421 100644 --- a/lib/strerror.c +++ b/lib/strerror.c @@ -630,11 +630,15 @@ const char *Curl_strerror(struct connectdata *conn, int err) { char *buf, *p; size_t max; - int old_errno = ERRNO; + int old_errno; + DWORD old_win_err; DEBUGASSERT(conn); DEBUGASSERT(err >= 0); + old_errno = errno; + old_win_err = GetLastError(); + buf = conn->syserr_buf; max = sizeof(conn->syserr_buf)-1; *buf = '\0'; @@ -722,8 +726,11 @@ const char *Curl_strerror(struct connectdata *conn, int err) if(p && (p - buf) >= 1) *p = '\0'; - if(old_errno != ERRNO) - SET_ERRNO(old_errno); + if(old_win_err != GetLastError()) + SetLastError(old_win_err); + + if(errno != old_errno) + errno = old_errno; return buf; } @@ -737,6 +744,7 @@ const char *Curl_sspi_strerror (struct connectdata *conn, int err) char *p, *str, *msg = NULL; bool msg_formatted = FALSE; int old_errno; + DWORD old_win_err; #endif const char *txt; char *outbuf; @@ -750,7 +758,8 @@ const char *Curl_sspi_strerror (struct connectdata *conn, int err) #ifndef CURL_DISABLE_VERBOSE_STRINGS - old_errno = ERRNO; + old_errno = errno; + old_win_err = GetLastError(); switch(err) { case SEC_E_OK: @@ -1051,8 +1060,11 @@ const char *Curl_sspi_strerror (struct connectdata *conn, int err) strncpy(outbuf, str, outmax); } - if(old_errno != ERRNO) - SET_ERRNO(old_errno); + if(old_win_err != GetLastError()) + SetLastError(old_win_err); + + if(errno != old_errno) + errno = old_errno; #else -- cgit v1.2.3