summaryrefslogtreecommitdiff
path: root/lib/strerror.c
diff options
context:
space:
mode:
authorJay Satiro <raysatiro@yahoo.com>2017-06-19 00:52:38 -0400
committerJay Satiro <raysatiro@yahoo.com>2017-07-10 02:09:27 -0400
commitaf0216251b94e751baa47146ac9609db70793b8e (patch)
treede39c7130d519f0bcda17b9a09df822f02fc32e6 /lib/strerror.c
parent17da6750026cf00277aad3a44fd20b1a4cea6406 (diff)
downloadcurl-af0216251b94e751baa47146ac9609db70793b8e.tar.gz
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
Diffstat (limited to 'lib/strerror.c')
-rw-r--r--lib/strerror.c24
1 files changed, 18 insertions, 6 deletions
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