5
5
* | (__| |_| | _ <| |___
6
6
* \___|\___/|_| \_\_____|
8
* Copyright (C) 2004 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
8
* Copyright (C) 2004 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
10
10
* This software is licensed as described in the file COPYING, which
11
11
* you should have received as part of this distribution. The terms
18
18
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
* KIND, either express or implied.
21
* $Id: strerror.c,v 1.50 2008-05-12 21:43:29 bagder Exp $
21
* $Id: strerror.c,v 1.54 2008-09-12 10:51:57 yangtse Exp $
22
22
***************************************************************************/
26
26
#ifdef HAVE_STRERROR_R
27
#if !defined(HAVE_POSIX_STRERROR_R) && !defined(HAVE_GLIBC_STRERROR_R)
28
#error "you MUST have either POSIX or glibc strerror_r if strerror_r is found"
29
#endif /* !POSIX && !glibc */
30
#endif /* HAVE_STRERROR_R */
27
# if (!defined(HAVE_POSIX_STRERROR_R) && !defined(HAVE_GLIBC_STRERROR_R)) || \
28
(defined(HAVE_POSIX_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R))
29
# error "strerror_r MUST be either POSIX-style or glibc-style"
32
33
#include <curl/curl.h>
33
34
#include <stdlib.h>
43
44
#define _MPRINTF_REPLACE /* use our functions only */
44
45
#include <curl/mprintf.h>
46
#if defined(HAVE_STRERROR_R) && defined(HAVE_NO_STRERROR_R_DECL)
47
#ifdef HAVE_POSIX_STRERROR_R
48
/* seen on AIX 5100-02 gcc 2.9 */
49
extern int strerror_r(int errnum, char *strerrbuf, size_t buflen);
51
extern char *strerror_r(int errnum, char *buf, size_t buflen);
56
49
curl_easy_strerror(CURLcode error)
222
215
case CURLE_SSL_SHUTDOWN_FAILED:
223
216
return "Failed to shut down the SSL connection";
218
case CURLE_SSL_CRL_BADFILE:
219
return "Failed to load CRL file (path? access rights?, format?)";
221
case CURLE_SSL_ISSUER_ERROR:
222
return "Issuer check against peer certificate failed";
225
224
case CURLE_SEND_FAIL_REWIND:
226
225
return "Send failed since rewinding of the data stream failed";
595
595
#ifdef USE_WINSOCK
597
597
#ifdef _WIN32_WCE
600
599
wchar_t wbuf[256];
602
602
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
603
603
LANG_NEUTRAL, wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL);
604
604
wcstombs(buf,wbuf,max);
609
607
/* 'sys_nerr' is the maximum errno number, it is not widely portable */
610
608
if(err >= 0 && err < sys_nerr)
611
609
strncpy(buf, strerror(err), max);
616
614
snprintf(buf, max, "Unknown error %d (%#x)", err, err);
619
618
#else /* not USE_WINSOCK coming up */
621
/* These should be atomic and hopefully thread-safe */
622
#ifdef HAVE_STRERROR_R
623
/* There are two different APIs for strerror_r(). The POSIX and the GLIBC
625
#ifdef HAVE_POSIX_STRERROR_R
626
strerror_r(err, buf, max);
627
/* this may set errno to ERANGE if insufficient storage was supplied via
628
'strerrbuf' and 'buflen' to contain the generated message string, or
629
EINVAL if the value of 'errnum' is not a valid error number.*/
620
#if defined(HAVE_STRERROR_R) && defined(HAVE_POSIX_STRERROR_R)
622
* The POSIX-style strerror_r() may set errno to ERANGE if insufficient
623
* storage is supplied via 'strerrbuf' and 'buflen' to hold the generated
624
* message string, or EINVAL if 'errnum' is not a valid error number.
626
if(0 != strerror_r(err, buf, max)) {
628
snprintf(buf, max, "Unknown error %d", err);
630
#elif defined(HAVE_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R)
632
* The glibc-style strerror_r() only *might* use the buffer we pass to
633
* the function, but it always returns the error message as a pointer,
634
* so we must copy that string unconditionally (if non-NULL).
632
/* HAVE_GLIBC_STRERROR_R */
633
637
char buffer[256];
634
638
char *msg = strerror_r(err, buffer, sizeof(buffer));
635
/* this version of strerror_r() only *might* use the buffer we pass to
636
the function, but it always returns the error message as a pointer,
637
so we must copy that string unconditionally (if non-NULL) */
639
strncpy(buf, msg, max);
641
snprintf(buf, max, "Unknown error %d", err);
643
#endif /* end of HAVE_GLIBC_STRERROR_R */
644
#else /* HAVE_STRERROR_R */
645
strncpy(buf, strerror(err), max);
646
#endif /* end of HAVE_STRERROR_R */
640
strncpy(buf, msg, max);
642
snprintf(buf, max, "Unknown error %d", err);
646
char *msg = strerror(err);
648
strncpy(buf, msg, max);
650
snprintf(buf, max, "Unknown error %d", err);
647
654
#endif /* end of ! USE_WINSOCK */
649
656
buf[max] = '\0'; /* make sure the string is zero terminated */