113498266Sopenharmony_ci/***************************************************************************
213498266Sopenharmony_ci *                                  _   _ ____  _
313498266Sopenharmony_ci *  Project                     ___| | | |  _ \| |
413498266Sopenharmony_ci *                             / __| | | | |_) | |
513498266Sopenharmony_ci *                            | (__| |_| |  _ <| |___
613498266Sopenharmony_ci *                             \___|\___/|_| \_\_____|
713498266Sopenharmony_ci *
813498266Sopenharmony_ci * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
913498266Sopenharmony_ci *
1013498266Sopenharmony_ci * This software is licensed as described in the file COPYING, which
1113498266Sopenharmony_ci * you should have received as part of this distribution. The terms
1213498266Sopenharmony_ci * are also available at https://curl.se/docs/copyright.html.
1313498266Sopenharmony_ci *
1413498266Sopenharmony_ci * You may opt to use, copy, modify, merge, publish, distribute and/or sell
1513498266Sopenharmony_ci * copies of the Software, and permit persons to whom the Software is
1613498266Sopenharmony_ci * furnished to do so, under the terms of the COPYING file.
1713498266Sopenharmony_ci *
1813498266Sopenharmony_ci * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1913498266Sopenharmony_ci * KIND, either express or implied.
2013498266Sopenharmony_ci *
2113498266Sopenharmony_ci * SPDX-License-Identifier: curl
2213498266Sopenharmony_ci *
2313498266Sopenharmony_ci ***************************************************************************/
2413498266Sopenharmony_ci
2513498266Sopenharmony_ci#include "curl_setup.h"
2613498266Sopenharmony_ci
2713498266Sopenharmony_ci#ifdef HAVE_STRERROR_R
2813498266Sopenharmony_ci#  if (!defined(HAVE_POSIX_STRERROR_R) && \
2913498266Sopenharmony_ci       !defined(HAVE_GLIBC_STRERROR_R)) || \
3013498266Sopenharmony_ci      (defined(HAVE_POSIX_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R))
3113498266Sopenharmony_ci#    error "strerror_r MUST be either POSIX, glibc style"
3213498266Sopenharmony_ci#  endif
3313498266Sopenharmony_ci#endif
3413498266Sopenharmony_ci
3513498266Sopenharmony_ci#include <curl/curl.h>
3613498266Sopenharmony_ci
3713498266Sopenharmony_ci#ifdef USE_LIBIDN2
3813498266Sopenharmony_ci#include <idn2.h>
3913498266Sopenharmony_ci#endif
4013498266Sopenharmony_ci
4113498266Sopenharmony_ci#ifdef USE_WINDOWS_SSPI
4213498266Sopenharmony_ci#include "curl_sspi.h"
4313498266Sopenharmony_ci#endif
4413498266Sopenharmony_ci
4513498266Sopenharmony_ci#include "strerror.h"
4613498266Sopenharmony_ci/* The last 3 #include files should be in this order */
4713498266Sopenharmony_ci#include "curl_printf.h"
4813498266Sopenharmony_ci#include "curl_memory.h"
4913498266Sopenharmony_ci#include "memdebug.h"
5013498266Sopenharmony_ci
5113498266Sopenharmony_ci#if defined(_WIN32) || defined(_WIN32_WCE)
5213498266Sopenharmony_ci#define PRESERVE_WINDOWS_ERROR_CODE
5313498266Sopenharmony_ci#endif
5413498266Sopenharmony_ci
5513498266Sopenharmony_ciconst char *
5613498266Sopenharmony_cicurl_easy_strerror(CURLcode error)
5713498266Sopenharmony_ci{
5813498266Sopenharmony_ci#ifndef CURL_DISABLE_VERBOSE_STRINGS
5913498266Sopenharmony_ci  switch(error) {
6013498266Sopenharmony_ci  case CURLE_OK:
6113498266Sopenharmony_ci    return "No error";
6213498266Sopenharmony_ci
6313498266Sopenharmony_ci  case CURLE_UNSUPPORTED_PROTOCOL:
6413498266Sopenharmony_ci    return "Unsupported protocol";
6513498266Sopenharmony_ci
6613498266Sopenharmony_ci  case CURLE_FAILED_INIT:
6713498266Sopenharmony_ci    return "Failed initialization";
6813498266Sopenharmony_ci
6913498266Sopenharmony_ci  case CURLE_URL_MALFORMAT:
7013498266Sopenharmony_ci    return "URL using bad/illegal format or missing URL";
7113498266Sopenharmony_ci
7213498266Sopenharmony_ci  case CURLE_NOT_BUILT_IN:
7313498266Sopenharmony_ci    return "A requested feature, protocol or option was not found built-in in"
7413498266Sopenharmony_ci      " this libcurl due to a build-time decision.";
7513498266Sopenharmony_ci
7613498266Sopenharmony_ci  case CURLE_COULDNT_RESOLVE_PROXY:
7713498266Sopenharmony_ci    return "Couldn't resolve proxy name";
7813498266Sopenharmony_ci
7913498266Sopenharmony_ci  case CURLE_COULDNT_RESOLVE_HOST:
8013498266Sopenharmony_ci    return "Couldn't resolve host name";
8113498266Sopenharmony_ci
8213498266Sopenharmony_ci  case CURLE_COULDNT_CONNECT:
8313498266Sopenharmony_ci    return "Couldn't connect to server";
8413498266Sopenharmony_ci
8513498266Sopenharmony_ci  case CURLE_WEIRD_SERVER_REPLY:
8613498266Sopenharmony_ci    return "Weird server reply";
8713498266Sopenharmony_ci
8813498266Sopenharmony_ci  case CURLE_REMOTE_ACCESS_DENIED:
8913498266Sopenharmony_ci    return "Access denied to remote resource";
9013498266Sopenharmony_ci
9113498266Sopenharmony_ci  case CURLE_FTP_ACCEPT_FAILED:
9213498266Sopenharmony_ci    return "FTP: The server failed to connect to data port";
9313498266Sopenharmony_ci
9413498266Sopenharmony_ci  case CURLE_FTP_ACCEPT_TIMEOUT:
9513498266Sopenharmony_ci    return "FTP: Accepting server connect has timed out";
9613498266Sopenharmony_ci
9713498266Sopenharmony_ci  case CURLE_FTP_PRET_FAILED:
9813498266Sopenharmony_ci    return "FTP: The server did not accept the PRET command.";
9913498266Sopenharmony_ci
10013498266Sopenharmony_ci  case CURLE_FTP_WEIRD_PASS_REPLY:
10113498266Sopenharmony_ci    return "FTP: unknown PASS reply";
10213498266Sopenharmony_ci
10313498266Sopenharmony_ci  case CURLE_FTP_WEIRD_PASV_REPLY:
10413498266Sopenharmony_ci    return "FTP: unknown PASV reply";
10513498266Sopenharmony_ci
10613498266Sopenharmony_ci  case CURLE_FTP_WEIRD_227_FORMAT:
10713498266Sopenharmony_ci    return "FTP: unknown 227 response format";
10813498266Sopenharmony_ci
10913498266Sopenharmony_ci  case CURLE_FTP_CANT_GET_HOST:
11013498266Sopenharmony_ci    return "FTP: can't figure out the host in the PASV response";
11113498266Sopenharmony_ci
11213498266Sopenharmony_ci  case CURLE_HTTP2:
11313498266Sopenharmony_ci    return "Error in the HTTP2 framing layer";
11413498266Sopenharmony_ci
11513498266Sopenharmony_ci  case CURLE_FTP_COULDNT_SET_TYPE:
11613498266Sopenharmony_ci    return "FTP: couldn't set file type";
11713498266Sopenharmony_ci
11813498266Sopenharmony_ci  case CURLE_PARTIAL_FILE:
11913498266Sopenharmony_ci    return "Transferred a partial file";
12013498266Sopenharmony_ci
12113498266Sopenharmony_ci  case CURLE_FTP_COULDNT_RETR_FILE:
12213498266Sopenharmony_ci    return "FTP: couldn't retrieve (RETR failed) the specified file";
12313498266Sopenharmony_ci
12413498266Sopenharmony_ci  case CURLE_QUOTE_ERROR:
12513498266Sopenharmony_ci    return "Quote command returned error";
12613498266Sopenharmony_ci
12713498266Sopenharmony_ci  case CURLE_HTTP_RETURNED_ERROR:
12813498266Sopenharmony_ci    return "HTTP response code said error";
12913498266Sopenharmony_ci
13013498266Sopenharmony_ci  case CURLE_WRITE_ERROR:
13113498266Sopenharmony_ci    return "Failed writing received data to disk/application";
13213498266Sopenharmony_ci
13313498266Sopenharmony_ci  case CURLE_UPLOAD_FAILED:
13413498266Sopenharmony_ci    return "Upload failed (at start/before it took off)";
13513498266Sopenharmony_ci
13613498266Sopenharmony_ci  case CURLE_READ_ERROR:
13713498266Sopenharmony_ci    return "Failed to open/read local data from file/application";
13813498266Sopenharmony_ci
13913498266Sopenharmony_ci  case CURLE_OUT_OF_MEMORY:
14013498266Sopenharmony_ci    return "Out of memory";
14113498266Sopenharmony_ci
14213498266Sopenharmony_ci  case CURLE_OPERATION_TIMEDOUT:
14313498266Sopenharmony_ci    return "Timeout was reached";
14413498266Sopenharmony_ci
14513498266Sopenharmony_ci  case CURLE_FTP_PORT_FAILED:
14613498266Sopenharmony_ci    return "FTP: command PORT failed";
14713498266Sopenharmony_ci
14813498266Sopenharmony_ci  case CURLE_FTP_COULDNT_USE_REST:
14913498266Sopenharmony_ci    return "FTP: command REST failed";
15013498266Sopenharmony_ci
15113498266Sopenharmony_ci  case CURLE_RANGE_ERROR:
15213498266Sopenharmony_ci    return "Requested range was not delivered by the server";
15313498266Sopenharmony_ci
15413498266Sopenharmony_ci  case CURLE_HTTP_POST_ERROR:
15513498266Sopenharmony_ci    return "Internal problem setting up the POST";
15613498266Sopenharmony_ci
15713498266Sopenharmony_ci  case CURLE_SSL_CONNECT_ERROR:
15813498266Sopenharmony_ci    return "SSL connect error";
15913498266Sopenharmony_ci
16013498266Sopenharmony_ci  case CURLE_BAD_DOWNLOAD_RESUME:
16113498266Sopenharmony_ci    return "Couldn't resume download";
16213498266Sopenharmony_ci
16313498266Sopenharmony_ci  case CURLE_FILE_COULDNT_READ_FILE:
16413498266Sopenharmony_ci    return "Couldn't read a file:// file";
16513498266Sopenharmony_ci
16613498266Sopenharmony_ci  case CURLE_LDAP_CANNOT_BIND:
16713498266Sopenharmony_ci    return "LDAP: cannot bind";
16813498266Sopenharmony_ci
16913498266Sopenharmony_ci  case CURLE_LDAP_SEARCH_FAILED:
17013498266Sopenharmony_ci    return "LDAP: search failed";
17113498266Sopenharmony_ci
17213498266Sopenharmony_ci  case CURLE_FUNCTION_NOT_FOUND:
17313498266Sopenharmony_ci    return "A required function in the library was not found";
17413498266Sopenharmony_ci
17513498266Sopenharmony_ci  case CURLE_ABORTED_BY_CALLBACK:
17613498266Sopenharmony_ci    return "Operation was aborted by an application callback";
17713498266Sopenharmony_ci
17813498266Sopenharmony_ci  case CURLE_BAD_FUNCTION_ARGUMENT:
17913498266Sopenharmony_ci    return "A libcurl function was given a bad argument";
18013498266Sopenharmony_ci
18113498266Sopenharmony_ci  case CURLE_INTERFACE_FAILED:
18213498266Sopenharmony_ci    return "Failed binding local connection end";
18313498266Sopenharmony_ci
18413498266Sopenharmony_ci  case CURLE_TOO_MANY_REDIRECTS:
18513498266Sopenharmony_ci    return "Number of redirects hit maximum amount";
18613498266Sopenharmony_ci
18713498266Sopenharmony_ci  case CURLE_UNKNOWN_OPTION:
18813498266Sopenharmony_ci    return "An unknown option was passed in to libcurl";
18913498266Sopenharmony_ci
19013498266Sopenharmony_ci  case CURLE_SETOPT_OPTION_SYNTAX:
19113498266Sopenharmony_ci    return "Malformed option provided in a setopt";
19213498266Sopenharmony_ci
19313498266Sopenharmony_ci  case CURLE_GOT_NOTHING:
19413498266Sopenharmony_ci    return "Server returned nothing (no headers, no data)";
19513498266Sopenharmony_ci
19613498266Sopenharmony_ci  case CURLE_SSL_ENGINE_NOTFOUND:
19713498266Sopenharmony_ci    return "SSL crypto engine not found";
19813498266Sopenharmony_ci
19913498266Sopenharmony_ci  case CURLE_SSL_ENGINE_SETFAILED:
20013498266Sopenharmony_ci    return "Can not set SSL crypto engine as default";
20113498266Sopenharmony_ci
20213498266Sopenharmony_ci  case CURLE_SSL_ENGINE_INITFAILED:
20313498266Sopenharmony_ci    return "Failed to initialise SSL crypto engine";
20413498266Sopenharmony_ci
20513498266Sopenharmony_ci  case CURLE_SEND_ERROR:
20613498266Sopenharmony_ci    return "Failed sending data to the peer";
20713498266Sopenharmony_ci
20813498266Sopenharmony_ci  case CURLE_RECV_ERROR:
20913498266Sopenharmony_ci    return "Failure when receiving data from the peer";
21013498266Sopenharmony_ci
21113498266Sopenharmony_ci  case CURLE_SSL_CERTPROBLEM:
21213498266Sopenharmony_ci    return "Problem with the local SSL certificate";
21313498266Sopenharmony_ci
21413498266Sopenharmony_ci  case CURLE_SSL_CIPHER:
21513498266Sopenharmony_ci    return "Couldn't use specified SSL cipher";
21613498266Sopenharmony_ci
21713498266Sopenharmony_ci  case CURLE_PEER_FAILED_VERIFICATION:
21813498266Sopenharmony_ci    return "SSL peer certificate or SSH remote key was not OK";
21913498266Sopenharmony_ci
22013498266Sopenharmony_ci  case CURLE_SSL_CACERT_BADFILE:
22113498266Sopenharmony_ci    return "Problem with the SSL CA cert (path? access rights?)";
22213498266Sopenharmony_ci
22313498266Sopenharmony_ci  case CURLE_BAD_CONTENT_ENCODING:
22413498266Sopenharmony_ci    return "Unrecognized or bad HTTP Content or Transfer-Encoding";
22513498266Sopenharmony_ci
22613498266Sopenharmony_ci  case CURLE_FILESIZE_EXCEEDED:
22713498266Sopenharmony_ci    return "Maximum file size exceeded";
22813498266Sopenharmony_ci
22913498266Sopenharmony_ci  case CURLE_USE_SSL_FAILED:
23013498266Sopenharmony_ci    return "Requested SSL level failed";
23113498266Sopenharmony_ci
23213498266Sopenharmony_ci  case CURLE_SSL_SHUTDOWN_FAILED:
23313498266Sopenharmony_ci    return "Failed to shut down the SSL connection";
23413498266Sopenharmony_ci
23513498266Sopenharmony_ci  case CURLE_SSL_CRL_BADFILE:
23613498266Sopenharmony_ci    return "Failed to load CRL file (path? access rights?, format?)";
23713498266Sopenharmony_ci
23813498266Sopenharmony_ci  case CURLE_SSL_ISSUER_ERROR:
23913498266Sopenharmony_ci    return "Issuer check against peer certificate failed";
24013498266Sopenharmony_ci
24113498266Sopenharmony_ci  case CURLE_SEND_FAIL_REWIND:
24213498266Sopenharmony_ci    return "Send failed since rewinding of the data stream failed";
24313498266Sopenharmony_ci
24413498266Sopenharmony_ci  case CURLE_LOGIN_DENIED:
24513498266Sopenharmony_ci    return "Login denied";
24613498266Sopenharmony_ci
24713498266Sopenharmony_ci  case CURLE_TFTP_NOTFOUND:
24813498266Sopenharmony_ci    return "TFTP: File Not Found";
24913498266Sopenharmony_ci
25013498266Sopenharmony_ci  case CURLE_TFTP_PERM:
25113498266Sopenharmony_ci    return "TFTP: Access Violation";
25213498266Sopenharmony_ci
25313498266Sopenharmony_ci  case CURLE_REMOTE_DISK_FULL:
25413498266Sopenharmony_ci    return "Disk full or allocation exceeded";
25513498266Sopenharmony_ci
25613498266Sopenharmony_ci  case CURLE_TFTP_ILLEGAL:
25713498266Sopenharmony_ci    return "TFTP: Illegal operation";
25813498266Sopenharmony_ci
25913498266Sopenharmony_ci  case CURLE_TFTP_UNKNOWNID:
26013498266Sopenharmony_ci    return "TFTP: Unknown transfer ID";
26113498266Sopenharmony_ci
26213498266Sopenharmony_ci  case CURLE_REMOTE_FILE_EXISTS:
26313498266Sopenharmony_ci    return "Remote file already exists";
26413498266Sopenharmony_ci
26513498266Sopenharmony_ci  case CURLE_TFTP_NOSUCHUSER:
26613498266Sopenharmony_ci    return "TFTP: No such user";
26713498266Sopenharmony_ci
26813498266Sopenharmony_ci  case CURLE_REMOTE_FILE_NOT_FOUND:
26913498266Sopenharmony_ci    return "Remote file not found";
27013498266Sopenharmony_ci
27113498266Sopenharmony_ci  case CURLE_SSH:
27213498266Sopenharmony_ci    return "Error in the SSH layer";
27313498266Sopenharmony_ci
27413498266Sopenharmony_ci  case CURLE_AGAIN:
27513498266Sopenharmony_ci    return "Socket not ready for send/recv";
27613498266Sopenharmony_ci
27713498266Sopenharmony_ci  case CURLE_RTSP_CSEQ_ERROR:
27813498266Sopenharmony_ci    return "RTSP CSeq mismatch or invalid CSeq";
27913498266Sopenharmony_ci
28013498266Sopenharmony_ci  case CURLE_RTSP_SESSION_ERROR:
28113498266Sopenharmony_ci    return "RTSP session error";
28213498266Sopenharmony_ci
28313498266Sopenharmony_ci  case CURLE_FTP_BAD_FILE_LIST:
28413498266Sopenharmony_ci    return "Unable to parse FTP file list";
28513498266Sopenharmony_ci
28613498266Sopenharmony_ci  case CURLE_CHUNK_FAILED:
28713498266Sopenharmony_ci    return "Chunk callback failed";
28813498266Sopenharmony_ci
28913498266Sopenharmony_ci  case CURLE_NO_CONNECTION_AVAILABLE:
29013498266Sopenharmony_ci    return "The max connection limit is reached";
29113498266Sopenharmony_ci
29213498266Sopenharmony_ci  case CURLE_SSL_PINNEDPUBKEYNOTMATCH:
29313498266Sopenharmony_ci    return "SSL public key does not match pinned public key";
29413498266Sopenharmony_ci
29513498266Sopenharmony_ci  case CURLE_SSL_INVALIDCERTSTATUS:
29613498266Sopenharmony_ci    return "SSL server certificate status verification FAILED";
29713498266Sopenharmony_ci
29813498266Sopenharmony_ci  case CURLE_HTTP2_STREAM:
29913498266Sopenharmony_ci    return "Stream error in the HTTP/2 framing layer";
30013498266Sopenharmony_ci
30113498266Sopenharmony_ci  case CURLE_RECURSIVE_API_CALL:
30213498266Sopenharmony_ci    return "API function called from within callback";
30313498266Sopenharmony_ci
30413498266Sopenharmony_ci  case CURLE_AUTH_ERROR:
30513498266Sopenharmony_ci    return "An authentication function returned an error";
30613498266Sopenharmony_ci
30713498266Sopenharmony_ci  case CURLE_HTTP3:
30813498266Sopenharmony_ci    return "HTTP/3 error";
30913498266Sopenharmony_ci
31013498266Sopenharmony_ci  case CURLE_QUIC_CONNECT_ERROR:
31113498266Sopenharmony_ci    return "QUIC connection error";
31213498266Sopenharmony_ci
31313498266Sopenharmony_ci  case CURLE_PROXY:
31413498266Sopenharmony_ci    return "proxy handshake error";
31513498266Sopenharmony_ci
31613498266Sopenharmony_ci  case CURLE_SSL_CLIENTCERT:
31713498266Sopenharmony_ci    return "SSL Client Certificate required";
31813498266Sopenharmony_ci
31913498266Sopenharmony_ci  case CURLE_UNRECOVERABLE_POLL:
32013498266Sopenharmony_ci    return "Unrecoverable error in select/poll";
32113498266Sopenharmony_ci
32213498266Sopenharmony_ci  case CURLE_TOO_LARGE:
32313498266Sopenharmony_ci    return "A value or data field grew larger than allowed";
32413498266Sopenharmony_ci
32513498266Sopenharmony_ci    /* error codes not used by current libcurl */
32613498266Sopenharmony_ci  case CURLE_OBSOLETE20:
32713498266Sopenharmony_ci  case CURLE_OBSOLETE24:
32813498266Sopenharmony_ci  case CURLE_OBSOLETE29:
32913498266Sopenharmony_ci  case CURLE_OBSOLETE32:
33013498266Sopenharmony_ci  case CURLE_OBSOLETE40:
33113498266Sopenharmony_ci  case CURLE_OBSOLETE44:
33213498266Sopenharmony_ci  case CURLE_OBSOLETE46:
33313498266Sopenharmony_ci  case CURLE_OBSOLETE50:
33413498266Sopenharmony_ci  case CURLE_OBSOLETE51:
33513498266Sopenharmony_ci  case CURLE_OBSOLETE57:
33613498266Sopenharmony_ci  case CURLE_OBSOLETE62:
33713498266Sopenharmony_ci  case CURLE_OBSOLETE75:
33813498266Sopenharmony_ci  case CURLE_OBSOLETE76:
33913498266Sopenharmony_ci  case CURL_LAST:
34013498266Sopenharmony_ci    break;
34113498266Sopenharmony_ci  }
34213498266Sopenharmony_ci  /*
34313498266Sopenharmony_ci   * By using a switch, gcc -Wall will complain about enum values
34413498266Sopenharmony_ci   * which do not appear, helping keep this function up-to-date.
34513498266Sopenharmony_ci   * By using gcc -Wall -Werror, you can't forget.
34613498266Sopenharmony_ci   *
34713498266Sopenharmony_ci   * A table would not have the same benefit.  Most compilers will
34813498266Sopenharmony_ci   * generate code very similar to a table in any case, so there
34913498266Sopenharmony_ci   * is little performance gain from a table.  And something is broken
35013498266Sopenharmony_ci   * for the user's application, anyways, so does it matter how fast
35113498266Sopenharmony_ci   * it _doesn't_ work?
35213498266Sopenharmony_ci   *
35313498266Sopenharmony_ci   * The line number for the error will be near this comment, which
35413498266Sopenharmony_ci   * is why it is here, and not at the start of the switch.
35513498266Sopenharmony_ci   */
35613498266Sopenharmony_ci  return "Unknown error";
35713498266Sopenharmony_ci#else
35813498266Sopenharmony_ci  if(!error)
35913498266Sopenharmony_ci    return "No error";
36013498266Sopenharmony_ci  else
36113498266Sopenharmony_ci    return "Error";
36213498266Sopenharmony_ci#endif
36313498266Sopenharmony_ci}
36413498266Sopenharmony_ci
36513498266Sopenharmony_ciconst char *
36613498266Sopenharmony_cicurl_multi_strerror(CURLMcode error)
36713498266Sopenharmony_ci{
36813498266Sopenharmony_ci#ifndef CURL_DISABLE_VERBOSE_STRINGS
36913498266Sopenharmony_ci  switch(error) {
37013498266Sopenharmony_ci  case CURLM_CALL_MULTI_PERFORM:
37113498266Sopenharmony_ci    return "Please call curl_multi_perform() soon";
37213498266Sopenharmony_ci
37313498266Sopenharmony_ci  case CURLM_OK:
37413498266Sopenharmony_ci    return "No error";
37513498266Sopenharmony_ci
37613498266Sopenharmony_ci  case CURLM_BAD_HANDLE:
37713498266Sopenharmony_ci    return "Invalid multi handle";
37813498266Sopenharmony_ci
37913498266Sopenharmony_ci  case CURLM_BAD_EASY_HANDLE:
38013498266Sopenharmony_ci    return "Invalid easy handle";
38113498266Sopenharmony_ci
38213498266Sopenharmony_ci  case CURLM_OUT_OF_MEMORY:
38313498266Sopenharmony_ci    return "Out of memory";
38413498266Sopenharmony_ci
38513498266Sopenharmony_ci  case CURLM_INTERNAL_ERROR:
38613498266Sopenharmony_ci    return "Internal error";
38713498266Sopenharmony_ci
38813498266Sopenharmony_ci  case CURLM_BAD_SOCKET:
38913498266Sopenharmony_ci    return "Invalid socket argument";
39013498266Sopenharmony_ci
39113498266Sopenharmony_ci  case CURLM_UNKNOWN_OPTION:
39213498266Sopenharmony_ci    return "Unknown option";
39313498266Sopenharmony_ci
39413498266Sopenharmony_ci  case CURLM_ADDED_ALREADY:
39513498266Sopenharmony_ci    return "The easy handle is already added to a multi handle";
39613498266Sopenharmony_ci
39713498266Sopenharmony_ci  case CURLM_RECURSIVE_API_CALL:
39813498266Sopenharmony_ci    return "API function called from within callback";
39913498266Sopenharmony_ci
40013498266Sopenharmony_ci  case CURLM_WAKEUP_FAILURE:
40113498266Sopenharmony_ci    return "Wakeup is unavailable or failed";
40213498266Sopenharmony_ci
40313498266Sopenharmony_ci  case CURLM_BAD_FUNCTION_ARGUMENT:
40413498266Sopenharmony_ci    return "A libcurl function was given a bad argument";
40513498266Sopenharmony_ci
40613498266Sopenharmony_ci  case CURLM_ABORTED_BY_CALLBACK:
40713498266Sopenharmony_ci    return "Operation was aborted by an application callback";
40813498266Sopenharmony_ci
40913498266Sopenharmony_ci  case CURLM_UNRECOVERABLE_POLL:
41013498266Sopenharmony_ci    return "Unrecoverable error in select/poll";
41113498266Sopenharmony_ci
41213498266Sopenharmony_ci  case CURLM_LAST:
41313498266Sopenharmony_ci    break;
41413498266Sopenharmony_ci  }
41513498266Sopenharmony_ci
41613498266Sopenharmony_ci  return "Unknown error";
41713498266Sopenharmony_ci#else
41813498266Sopenharmony_ci  if(error == CURLM_OK)
41913498266Sopenharmony_ci    return "No error";
42013498266Sopenharmony_ci  else
42113498266Sopenharmony_ci    return "Error";
42213498266Sopenharmony_ci#endif
42313498266Sopenharmony_ci}
42413498266Sopenharmony_ci
42513498266Sopenharmony_ciconst char *
42613498266Sopenharmony_cicurl_share_strerror(CURLSHcode error)
42713498266Sopenharmony_ci{
42813498266Sopenharmony_ci#ifndef CURL_DISABLE_VERBOSE_STRINGS
42913498266Sopenharmony_ci  switch(error) {
43013498266Sopenharmony_ci  case CURLSHE_OK:
43113498266Sopenharmony_ci    return "No error";
43213498266Sopenharmony_ci
43313498266Sopenharmony_ci  case CURLSHE_BAD_OPTION:
43413498266Sopenharmony_ci    return "Unknown share option";
43513498266Sopenharmony_ci
43613498266Sopenharmony_ci  case CURLSHE_IN_USE:
43713498266Sopenharmony_ci    return "Share currently in use";
43813498266Sopenharmony_ci
43913498266Sopenharmony_ci  case CURLSHE_INVALID:
44013498266Sopenharmony_ci    return "Invalid share handle";
44113498266Sopenharmony_ci
44213498266Sopenharmony_ci  case CURLSHE_NOMEM:
44313498266Sopenharmony_ci    return "Out of memory";
44413498266Sopenharmony_ci
44513498266Sopenharmony_ci  case CURLSHE_NOT_BUILT_IN:
44613498266Sopenharmony_ci    return "Feature not enabled in this library";
44713498266Sopenharmony_ci
44813498266Sopenharmony_ci  case CURLSHE_LAST:
44913498266Sopenharmony_ci    break;
45013498266Sopenharmony_ci  }
45113498266Sopenharmony_ci
45213498266Sopenharmony_ci  return "CURLSHcode unknown";
45313498266Sopenharmony_ci#else
45413498266Sopenharmony_ci  if(error == CURLSHE_OK)
45513498266Sopenharmony_ci    return "No error";
45613498266Sopenharmony_ci  else
45713498266Sopenharmony_ci    return "Error";
45813498266Sopenharmony_ci#endif
45913498266Sopenharmony_ci}
46013498266Sopenharmony_ci
46113498266Sopenharmony_ciconst char *
46213498266Sopenharmony_cicurl_url_strerror(CURLUcode error)
46313498266Sopenharmony_ci{
46413498266Sopenharmony_ci#ifndef CURL_DISABLE_VERBOSE_STRINGS
46513498266Sopenharmony_ci  switch(error) {
46613498266Sopenharmony_ci  case CURLUE_OK:
46713498266Sopenharmony_ci    return "No error";
46813498266Sopenharmony_ci
46913498266Sopenharmony_ci  case CURLUE_BAD_HANDLE:
47013498266Sopenharmony_ci    return "An invalid CURLU pointer was passed as argument";
47113498266Sopenharmony_ci
47213498266Sopenharmony_ci  case CURLUE_BAD_PARTPOINTER:
47313498266Sopenharmony_ci    return "An invalid 'part' argument was passed as argument";
47413498266Sopenharmony_ci
47513498266Sopenharmony_ci  case CURLUE_MALFORMED_INPUT:
47613498266Sopenharmony_ci    return "Malformed input to a URL function";
47713498266Sopenharmony_ci
47813498266Sopenharmony_ci  case CURLUE_BAD_PORT_NUMBER:
47913498266Sopenharmony_ci    return "Port number was not a decimal number between 0 and 65535";
48013498266Sopenharmony_ci
48113498266Sopenharmony_ci  case CURLUE_UNSUPPORTED_SCHEME:
48213498266Sopenharmony_ci    return "Unsupported URL scheme";
48313498266Sopenharmony_ci
48413498266Sopenharmony_ci  case CURLUE_URLDECODE:
48513498266Sopenharmony_ci    return "URL decode error, most likely because of rubbish in the input";
48613498266Sopenharmony_ci
48713498266Sopenharmony_ci  case CURLUE_OUT_OF_MEMORY:
48813498266Sopenharmony_ci    return "A memory function failed";
48913498266Sopenharmony_ci
49013498266Sopenharmony_ci  case CURLUE_USER_NOT_ALLOWED:
49113498266Sopenharmony_ci    return "Credentials was passed in the URL when prohibited";
49213498266Sopenharmony_ci
49313498266Sopenharmony_ci  case CURLUE_UNKNOWN_PART:
49413498266Sopenharmony_ci    return "An unknown part ID was passed to a URL API function";
49513498266Sopenharmony_ci
49613498266Sopenharmony_ci  case CURLUE_NO_SCHEME:
49713498266Sopenharmony_ci    return "No scheme part in the URL";
49813498266Sopenharmony_ci
49913498266Sopenharmony_ci  case CURLUE_NO_USER:
50013498266Sopenharmony_ci    return "No user part in the URL";
50113498266Sopenharmony_ci
50213498266Sopenharmony_ci  case CURLUE_NO_PASSWORD:
50313498266Sopenharmony_ci    return "No password part in the URL";
50413498266Sopenharmony_ci
50513498266Sopenharmony_ci  case CURLUE_NO_OPTIONS:
50613498266Sopenharmony_ci    return "No options part in the URL";
50713498266Sopenharmony_ci
50813498266Sopenharmony_ci  case CURLUE_NO_HOST:
50913498266Sopenharmony_ci    return "No host part in the URL";
51013498266Sopenharmony_ci
51113498266Sopenharmony_ci  case CURLUE_NO_PORT:
51213498266Sopenharmony_ci    return "No port part in the URL";
51313498266Sopenharmony_ci
51413498266Sopenharmony_ci  case CURLUE_NO_QUERY:
51513498266Sopenharmony_ci    return "No query part in the URL";
51613498266Sopenharmony_ci
51713498266Sopenharmony_ci  case CURLUE_NO_FRAGMENT:
51813498266Sopenharmony_ci    return "No fragment part in the URL";
51913498266Sopenharmony_ci
52013498266Sopenharmony_ci  case CURLUE_NO_ZONEID:
52113498266Sopenharmony_ci    return "No zoneid part in the URL";
52213498266Sopenharmony_ci
52313498266Sopenharmony_ci  case CURLUE_BAD_LOGIN:
52413498266Sopenharmony_ci    return "Bad login part";
52513498266Sopenharmony_ci
52613498266Sopenharmony_ci  case CURLUE_BAD_IPV6:
52713498266Sopenharmony_ci    return "Bad IPv6 address";
52813498266Sopenharmony_ci
52913498266Sopenharmony_ci  case CURLUE_BAD_HOSTNAME:
53013498266Sopenharmony_ci    return "Bad hostname";
53113498266Sopenharmony_ci
53213498266Sopenharmony_ci  case CURLUE_BAD_FILE_URL:
53313498266Sopenharmony_ci    return "Bad file:// URL";
53413498266Sopenharmony_ci
53513498266Sopenharmony_ci  case CURLUE_BAD_SLASHES:
53613498266Sopenharmony_ci    return "Unsupported number of slashes following scheme";
53713498266Sopenharmony_ci
53813498266Sopenharmony_ci  case CURLUE_BAD_SCHEME:
53913498266Sopenharmony_ci    return "Bad scheme";
54013498266Sopenharmony_ci
54113498266Sopenharmony_ci  case CURLUE_BAD_PATH:
54213498266Sopenharmony_ci    return "Bad path";
54313498266Sopenharmony_ci
54413498266Sopenharmony_ci  case CURLUE_BAD_FRAGMENT:
54513498266Sopenharmony_ci    return "Bad fragment";
54613498266Sopenharmony_ci
54713498266Sopenharmony_ci  case CURLUE_BAD_QUERY:
54813498266Sopenharmony_ci    return "Bad query";
54913498266Sopenharmony_ci
55013498266Sopenharmony_ci  case CURLUE_BAD_PASSWORD:
55113498266Sopenharmony_ci    return "Bad password";
55213498266Sopenharmony_ci
55313498266Sopenharmony_ci  case CURLUE_BAD_USER:
55413498266Sopenharmony_ci    return "Bad user";
55513498266Sopenharmony_ci
55613498266Sopenharmony_ci  case CURLUE_LACKS_IDN:
55713498266Sopenharmony_ci    return "libcurl lacks IDN support";
55813498266Sopenharmony_ci
55913498266Sopenharmony_ci  case CURLUE_TOO_LARGE:
56013498266Sopenharmony_ci    return "A value or data field is larger than allowed";
56113498266Sopenharmony_ci
56213498266Sopenharmony_ci  case CURLUE_LAST:
56313498266Sopenharmony_ci    break;
56413498266Sopenharmony_ci  }
56513498266Sopenharmony_ci
56613498266Sopenharmony_ci  return "CURLUcode unknown";
56713498266Sopenharmony_ci#else
56813498266Sopenharmony_ci  if(error == CURLUE_OK)
56913498266Sopenharmony_ci    return "No error";
57013498266Sopenharmony_ci  else
57113498266Sopenharmony_ci    return "Error";
57213498266Sopenharmony_ci#endif
57313498266Sopenharmony_ci}
57413498266Sopenharmony_ci
57513498266Sopenharmony_ci#ifdef USE_WINSOCK
57613498266Sopenharmony_ci/* This is a helper function for Curl_strerror that converts Winsock error
57713498266Sopenharmony_ci * codes (WSAGetLastError) to error messages.
57813498266Sopenharmony_ci * Returns NULL if no error message was found for error code.
57913498266Sopenharmony_ci */
58013498266Sopenharmony_cistatic const char *
58113498266Sopenharmony_ciget_winsock_error(int err, char *buf, size_t len)
58213498266Sopenharmony_ci{
58313498266Sopenharmony_ci#ifndef CURL_DISABLE_VERBOSE_STRINGS
58413498266Sopenharmony_ci  const char *p;
58513498266Sopenharmony_ci  size_t alen;
58613498266Sopenharmony_ci#endif
58713498266Sopenharmony_ci
58813498266Sopenharmony_ci  if(!len)
58913498266Sopenharmony_ci    return NULL;
59013498266Sopenharmony_ci
59113498266Sopenharmony_ci  *buf = '\0';
59213498266Sopenharmony_ci
59313498266Sopenharmony_ci#ifdef CURL_DISABLE_VERBOSE_STRINGS
59413498266Sopenharmony_ci  (void)err;
59513498266Sopenharmony_ci  return NULL;
59613498266Sopenharmony_ci#else
59713498266Sopenharmony_ci  switch(err) {
59813498266Sopenharmony_ci  case WSAEINTR:
59913498266Sopenharmony_ci    p = "Call interrupted";
60013498266Sopenharmony_ci    break;
60113498266Sopenharmony_ci  case WSAEBADF:
60213498266Sopenharmony_ci    p = "Bad file";
60313498266Sopenharmony_ci    break;
60413498266Sopenharmony_ci  case WSAEACCES:
60513498266Sopenharmony_ci    p = "Bad access";
60613498266Sopenharmony_ci    break;
60713498266Sopenharmony_ci  case WSAEFAULT:
60813498266Sopenharmony_ci    p = "Bad argument";
60913498266Sopenharmony_ci    break;
61013498266Sopenharmony_ci  case WSAEINVAL:
61113498266Sopenharmony_ci    p = "Invalid arguments";
61213498266Sopenharmony_ci    break;
61313498266Sopenharmony_ci  case WSAEMFILE:
61413498266Sopenharmony_ci    p = "Out of file descriptors";
61513498266Sopenharmony_ci    break;
61613498266Sopenharmony_ci  case WSAEWOULDBLOCK:
61713498266Sopenharmony_ci    p = "Call would block";
61813498266Sopenharmony_ci    break;
61913498266Sopenharmony_ci  case WSAEINPROGRESS:
62013498266Sopenharmony_ci  case WSAEALREADY:
62113498266Sopenharmony_ci    p = "Blocking call in progress";
62213498266Sopenharmony_ci    break;
62313498266Sopenharmony_ci  case WSAENOTSOCK:
62413498266Sopenharmony_ci    p = "Descriptor is not a socket";
62513498266Sopenharmony_ci    break;
62613498266Sopenharmony_ci  case WSAEDESTADDRREQ:
62713498266Sopenharmony_ci    p = "Need destination address";
62813498266Sopenharmony_ci    break;
62913498266Sopenharmony_ci  case WSAEMSGSIZE:
63013498266Sopenharmony_ci    p = "Bad message size";
63113498266Sopenharmony_ci    break;
63213498266Sopenharmony_ci  case WSAEPROTOTYPE:
63313498266Sopenharmony_ci    p = "Bad protocol";
63413498266Sopenharmony_ci    break;
63513498266Sopenharmony_ci  case WSAENOPROTOOPT:
63613498266Sopenharmony_ci    p = "Protocol option is unsupported";
63713498266Sopenharmony_ci    break;
63813498266Sopenharmony_ci  case WSAEPROTONOSUPPORT:
63913498266Sopenharmony_ci    p = "Protocol is unsupported";
64013498266Sopenharmony_ci    break;
64113498266Sopenharmony_ci  case WSAESOCKTNOSUPPORT:
64213498266Sopenharmony_ci    p = "Socket is unsupported";
64313498266Sopenharmony_ci    break;
64413498266Sopenharmony_ci  case WSAEOPNOTSUPP:
64513498266Sopenharmony_ci    p = "Operation not supported";
64613498266Sopenharmony_ci    break;
64713498266Sopenharmony_ci  case WSAEAFNOSUPPORT:
64813498266Sopenharmony_ci    p = "Address family not supported";
64913498266Sopenharmony_ci    break;
65013498266Sopenharmony_ci  case WSAEPFNOSUPPORT:
65113498266Sopenharmony_ci    p = "Protocol family not supported";
65213498266Sopenharmony_ci    break;
65313498266Sopenharmony_ci  case WSAEADDRINUSE:
65413498266Sopenharmony_ci    p = "Address already in use";
65513498266Sopenharmony_ci    break;
65613498266Sopenharmony_ci  case WSAEADDRNOTAVAIL:
65713498266Sopenharmony_ci    p = "Address not available";
65813498266Sopenharmony_ci    break;
65913498266Sopenharmony_ci  case WSAENETDOWN:
66013498266Sopenharmony_ci    p = "Network down";
66113498266Sopenharmony_ci    break;
66213498266Sopenharmony_ci  case WSAENETUNREACH:
66313498266Sopenharmony_ci    p = "Network unreachable";
66413498266Sopenharmony_ci    break;
66513498266Sopenharmony_ci  case WSAENETRESET:
66613498266Sopenharmony_ci    p = "Network has been reset";
66713498266Sopenharmony_ci    break;
66813498266Sopenharmony_ci  case WSAECONNABORTED:
66913498266Sopenharmony_ci    p = "Connection was aborted";
67013498266Sopenharmony_ci    break;
67113498266Sopenharmony_ci  case WSAECONNRESET:
67213498266Sopenharmony_ci    p = "Connection was reset";
67313498266Sopenharmony_ci    break;
67413498266Sopenharmony_ci  case WSAENOBUFS:
67513498266Sopenharmony_ci    p = "No buffer space";
67613498266Sopenharmony_ci    break;
67713498266Sopenharmony_ci  case WSAEISCONN:
67813498266Sopenharmony_ci    p = "Socket is already connected";
67913498266Sopenharmony_ci    break;
68013498266Sopenharmony_ci  case WSAENOTCONN:
68113498266Sopenharmony_ci    p = "Socket is not connected";
68213498266Sopenharmony_ci    break;
68313498266Sopenharmony_ci  case WSAESHUTDOWN:
68413498266Sopenharmony_ci    p = "Socket has been shut down";
68513498266Sopenharmony_ci    break;
68613498266Sopenharmony_ci  case WSAETOOMANYREFS:
68713498266Sopenharmony_ci    p = "Too many references";
68813498266Sopenharmony_ci    break;
68913498266Sopenharmony_ci  case WSAETIMEDOUT:
69013498266Sopenharmony_ci    p = "Timed out";
69113498266Sopenharmony_ci    break;
69213498266Sopenharmony_ci  case WSAECONNREFUSED:
69313498266Sopenharmony_ci    p = "Connection refused";
69413498266Sopenharmony_ci    break;
69513498266Sopenharmony_ci  case WSAELOOP:
69613498266Sopenharmony_ci    p = "Loop??";
69713498266Sopenharmony_ci    break;
69813498266Sopenharmony_ci  case WSAENAMETOOLONG:
69913498266Sopenharmony_ci    p = "Name too long";
70013498266Sopenharmony_ci    break;
70113498266Sopenharmony_ci  case WSAEHOSTDOWN:
70213498266Sopenharmony_ci    p = "Host down";
70313498266Sopenharmony_ci    break;
70413498266Sopenharmony_ci  case WSAEHOSTUNREACH:
70513498266Sopenharmony_ci    p = "Host unreachable";
70613498266Sopenharmony_ci    break;
70713498266Sopenharmony_ci  case WSAENOTEMPTY:
70813498266Sopenharmony_ci    p = "Not empty";
70913498266Sopenharmony_ci    break;
71013498266Sopenharmony_ci  case WSAEPROCLIM:
71113498266Sopenharmony_ci    p = "Process limit reached";
71213498266Sopenharmony_ci    break;
71313498266Sopenharmony_ci  case WSAEUSERS:
71413498266Sopenharmony_ci    p = "Too many users";
71513498266Sopenharmony_ci    break;
71613498266Sopenharmony_ci  case WSAEDQUOT:
71713498266Sopenharmony_ci    p = "Bad quota";
71813498266Sopenharmony_ci    break;
71913498266Sopenharmony_ci  case WSAESTALE:
72013498266Sopenharmony_ci    p = "Something is stale";
72113498266Sopenharmony_ci    break;
72213498266Sopenharmony_ci  case WSAEREMOTE:
72313498266Sopenharmony_ci    p = "Remote error";
72413498266Sopenharmony_ci    break;
72513498266Sopenharmony_ci#ifdef WSAEDISCON  /* missing in SalfordC! */
72613498266Sopenharmony_ci  case WSAEDISCON:
72713498266Sopenharmony_ci    p = "Disconnected";
72813498266Sopenharmony_ci    break;
72913498266Sopenharmony_ci#endif
73013498266Sopenharmony_ci    /* Extended Winsock errors */
73113498266Sopenharmony_ci  case WSASYSNOTREADY:
73213498266Sopenharmony_ci    p = "Winsock library is not ready";
73313498266Sopenharmony_ci    break;
73413498266Sopenharmony_ci  case WSANOTINITIALISED:
73513498266Sopenharmony_ci    p = "Winsock library not initialised";
73613498266Sopenharmony_ci    break;
73713498266Sopenharmony_ci  case WSAVERNOTSUPPORTED:
73813498266Sopenharmony_ci    p = "Winsock version not supported";
73913498266Sopenharmony_ci    break;
74013498266Sopenharmony_ci
74113498266Sopenharmony_ci    /* getXbyY() errors (already handled in herrmsg):
74213498266Sopenharmony_ci     * Authoritative Answer: Host not found */
74313498266Sopenharmony_ci  case WSAHOST_NOT_FOUND:
74413498266Sopenharmony_ci    p = "Host not found";
74513498266Sopenharmony_ci    break;
74613498266Sopenharmony_ci
74713498266Sopenharmony_ci    /* Non-Authoritative: Host not found, or SERVERFAIL */
74813498266Sopenharmony_ci  case WSATRY_AGAIN:
74913498266Sopenharmony_ci    p = "Host not found, try again";
75013498266Sopenharmony_ci    break;
75113498266Sopenharmony_ci
75213498266Sopenharmony_ci    /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
75313498266Sopenharmony_ci  case WSANO_RECOVERY:
75413498266Sopenharmony_ci    p = "Unrecoverable error in call to nameserver";
75513498266Sopenharmony_ci    break;
75613498266Sopenharmony_ci
75713498266Sopenharmony_ci    /* Valid name, no data record of requested type */
75813498266Sopenharmony_ci  case WSANO_DATA:
75913498266Sopenharmony_ci    p = "No data record of requested type";
76013498266Sopenharmony_ci    break;
76113498266Sopenharmony_ci
76213498266Sopenharmony_ci  default:
76313498266Sopenharmony_ci    return NULL;
76413498266Sopenharmony_ci  }
76513498266Sopenharmony_ci  alen = strlen(p);
76613498266Sopenharmony_ci  if(alen < len)
76713498266Sopenharmony_ci    strcpy(buf, p);
76813498266Sopenharmony_ci  return buf;
76913498266Sopenharmony_ci#endif
77013498266Sopenharmony_ci}
77113498266Sopenharmony_ci#endif   /* USE_WINSOCK */
77213498266Sopenharmony_ci
77313498266Sopenharmony_ci#if defined(_WIN32) || defined(_WIN32_WCE)
77413498266Sopenharmony_ci/* This is a helper function for Curl_strerror that converts Windows API error
77513498266Sopenharmony_ci * codes (GetLastError) to error messages.
77613498266Sopenharmony_ci * Returns NULL if no error message was found for error code.
77713498266Sopenharmony_ci */
77813498266Sopenharmony_cistatic const char *
77913498266Sopenharmony_ciget_winapi_error(int err, char *buf, size_t buflen)
78013498266Sopenharmony_ci{
78113498266Sopenharmony_ci  char *p;
78213498266Sopenharmony_ci  wchar_t wbuf[256];
78313498266Sopenharmony_ci
78413498266Sopenharmony_ci  if(!buflen)
78513498266Sopenharmony_ci    return NULL;
78613498266Sopenharmony_ci
78713498266Sopenharmony_ci  *buf = '\0';
78813498266Sopenharmony_ci  *wbuf = L'\0';
78913498266Sopenharmony_ci
79013498266Sopenharmony_ci  /* We return the local codepage version of the error string because if it is
79113498266Sopenharmony_ci     output to the user's terminal it will likely be with functions which
79213498266Sopenharmony_ci     expect the local codepage (eg fprintf, failf, infof).
79313498266Sopenharmony_ci     FormatMessageW -> wcstombs is used for Windows CE compatibility. */
79413498266Sopenharmony_ci  if(FormatMessageW((FORMAT_MESSAGE_FROM_SYSTEM |
79513498266Sopenharmony_ci                     FORMAT_MESSAGE_IGNORE_INSERTS), NULL, err,
79613498266Sopenharmony_ci                    LANG_NEUTRAL, wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL)) {
79713498266Sopenharmony_ci    size_t written = wcstombs(buf, wbuf, buflen - 1);
79813498266Sopenharmony_ci    if(written != (size_t)-1)
79913498266Sopenharmony_ci      buf[written] = '\0';
80013498266Sopenharmony_ci    else
80113498266Sopenharmony_ci      *buf = '\0';
80213498266Sopenharmony_ci  }
80313498266Sopenharmony_ci
80413498266Sopenharmony_ci  /* Truncate multiple lines */
80513498266Sopenharmony_ci  p = strchr(buf, '\n');
80613498266Sopenharmony_ci  if(p) {
80713498266Sopenharmony_ci    if(p > buf && *(p-1) == '\r')
80813498266Sopenharmony_ci      *(p-1) = '\0';
80913498266Sopenharmony_ci    else
81013498266Sopenharmony_ci      *p = '\0';
81113498266Sopenharmony_ci  }
81213498266Sopenharmony_ci
81313498266Sopenharmony_ci  return (*buf ? buf : NULL);
81413498266Sopenharmony_ci}
81513498266Sopenharmony_ci#endif /* _WIN32 || _WIN32_WCE */
81613498266Sopenharmony_ci
81713498266Sopenharmony_ci/*
81813498266Sopenharmony_ci * Our thread-safe and smart strerror() replacement.
81913498266Sopenharmony_ci *
82013498266Sopenharmony_ci * The 'err' argument passed in to this function MUST be a true errno number
82113498266Sopenharmony_ci * as reported on this system. We do no range checking on the number before
82213498266Sopenharmony_ci * we pass it to the "number-to-message" conversion function and there might
82313498266Sopenharmony_ci * be systems that don't do proper range checking in there themselves.
82413498266Sopenharmony_ci *
82513498266Sopenharmony_ci * We don't do range checking (on systems other than Windows) since there is
82613498266Sopenharmony_ci * no good reliable and portable way to do it.
82713498266Sopenharmony_ci *
82813498266Sopenharmony_ci * On Windows different types of error codes overlap. This function has an
82913498266Sopenharmony_ci * order of preference when trying to match error codes:
83013498266Sopenharmony_ci * CRT (errno), Winsock (WSAGetLastError), Windows API (GetLastError).
83113498266Sopenharmony_ci *
83213498266Sopenharmony_ci * It may be more correct to call one of the variant functions instead:
83313498266Sopenharmony_ci * Call Curl_sspi_strerror if the error code is definitely Windows SSPI.
83413498266Sopenharmony_ci * Call Curl_winapi_strerror if the error code is definitely Windows API.
83513498266Sopenharmony_ci */
83613498266Sopenharmony_ciconst char *Curl_strerror(int err, char *buf, size_t buflen)
83713498266Sopenharmony_ci{
83813498266Sopenharmony_ci#ifdef PRESERVE_WINDOWS_ERROR_CODE
83913498266Sopenharmony_ci  DWORD old_win_err = GetLastError();
84013498266Sopenharmony_ci#endif
84113498266Sopenharmony_ci  int old_errno = errno;
84213498266Sopenharmony_ci  char *p;
84313498266Sopenharmony_ci
84413498266Sopenharmony_ci  if(!buflen)
84513498266Sopenharmony_ci    return NULL;
84613498266Sopenharmony_ci
84713498266Sopenharmony_ci#ifndef _WIN32
84813498266Sopenharmony_ci  DEBUGASSERT(err >= 0);
84913498266Sopenharmony_ci#endif
85013498266Sopenharmony_ci
85113498266Sopenharmony_ci  *buf = '\0';
85213498266Sopenharmony_ci
85313498266Sopenharmony_ci#if defined(_WIN32) || defined(_WIN32_WCE)
85413498266Sopenharmony_ci#if defined(_WIN32)
85513498266Sopenharmony_ci  /* 'sys_nerr' is the maximum errno number, it is not widely portable */
85613498266Sopenharmony_ci  if(err >= 0 && err < sys_nerr)
85713498266Sopenharmony_ci    msnprintf(buf, buflen, "%s", sys_errlist[err]);
85813498266Sopenharmony_ci  else
85913498266Sopenharmony_ci#endif
86013498266Sopenharmony_ci  {
86113498266Sopenharmony_ci    if(
86213498266Sopenharmony_ci#ifdef USE_WINSOCK
86313498266Sopenharmony_ci       !get_winsock_error(err, buf, buflen) &&
86413498266Sopenharmony_ci#endif
86513498266Sopenharmony_ci       !get_winapi_error((DWORD)err, buf, buflen))
86613498266Sopenharmony_ci      msnprintf(buf, buflen, "Unknown error %d (%#x)", err, err);
86713498266Sopenharmony_ci  }
86813498266Sopenharmony_ci#else /* not Windows coming up */
86913498266Sopenharmony_ci
87013498266Sopenharmony_ci#if defined(HAVE_STRERROR_R) && defined(HAVE_POSIX_STRERROR_R)
87113498266Sopenharmony_ci /*
87213498266Sopenharmony_ci  * The POSIX-style strerror_r() may set errno to ERANGE if insufficient
87313498266Sopenharmony_ci  * storage is supplied via 'strerrbuf' and 'buflen' to hold the generated
87413498266Sopenharmony_ci  * message string, or EINVAL if 'errnum' is not a valid error number.
87513498266Sopenharmony_ci  */
87613498266Sopenharmony_ci  if(0 != strerror_r(err, buf, buflen)) {
87713498266Sopenharmony_ci    if('\0' == buf[0])
87813498266Sopenharmony_ci      msnprintf(buf, buflen, "Unknown error %d", err);
87913498266Sopenharmony_ci  }
88013498266Sopenharmony_ci#elif defined(HAVE_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R)
88113498266Sopenharmony_ci /*
88213498266Sopenharmony_ci  * The glibc-style strerror_r() only *might* use the buffer we pass to
88313498266Sopenharmony_ci  * the function, but it always returns the error message as a pointer,
88413498266Sopenharmony_ci  * so we must copy that string unconditionally (if non-NULL).
88513498266Sopenharmony_ci  */
88613498266Sopenharmony_ci  {
88713498266Sopenharmony_ci    char buffer[256];
88813498266Sopenharmony_ci    char *msg = strerror_r(err, buffer, sizeof(buffer));
88913498266Sopenharmony_ci    if(msg)
89013498266Sopenharmony_ci      msnprintf(buf, buflen, "%s", msg);
89113498266Sopenharmony_ci    else
89213498266Sopenharmony_ci      msnprintf(buf, buflen, "Unknown error %d", err);
89313498266Sopenharmony_ci  }
89413498266Sopenharmony_ci#else
89513498266Sopenharmony_ci  {
89613498266Sopenharmony_ci    /* !checksrc! disable STRERROR 1 */
89713498266Sopenharmony_ci    const char *msg = strerror(err);
89813498266Sopenharmony_ci    if(msg)
89913498266Sopenharmony_ci      msnprintf(buf, buflen, "%s", msg);
90013498266Sopenharmony_ci    else
90113498266Sopenharmony_ci      msnprintf(buf, buflen, "Unknown error %d", err);
90213498266Sopenharmony_ci  }
90313498266Sopenharmony_ci#endif
90413498266Sopenharmony_ci
90513498266Sopenharmony_ci#endif /* end of not Windows */
90613498266Sopenharmony_ci
90713498266Sopenharmony_ci  /* strip trailing '\r\n' or '\n'. */
90813498266Sopenharmony_ci  p = strrchr(buf, '\n');
90913498266Sopenharmony_ci  if(p && (p - buf) >= 2)
91013498266Sopenharmony_ci    *p = '\0';
91113498266Sopenharmony_ci  p = strrchr(buf, '\r');
91213498266Sopenharmony_ci  if(p && (p - buf) >= 1)
91313498266Sopenharmony_ci    *p = '\0';
91413498266Sopenharmony_ci
91513498266Sopenharmony_ci  if(errno != old_errno)
91613498266Sopenharmony_ci    errno = old_errno;
91713498266Sopenharmony_ci
91813498266Sopenharmony_ci#ifdef PRESERVE_WINDOWS_ERROR_CODE
91913498266Sopenharmony_ci  if(old_win_err != GetLastError())
92013498266Sopenharmony_ci    SetLastError(old_win_err);
92113498266Sopenharmony_ci#endif
92213498266Sopenharmony_ci
92313498266Sopenharmony_ci  return buf;
92413498266Sopenharmony_ci}
92513498266Sopenharmony_ci
92613498266Sopenharmony_ci/*
92713498266Sopenharmony_ci * Curl_winapi_strerror:
92813498266Sopenharmony_ci * Variant of Curl_strerror if the error code is definitely Windows API.
92913498266Sopenharmony_ci */
93013498266Sopenharmony_ci#if defined(_WIN32) || defined(_WIN32_WCE)
93113498266Sopenharmony_ciconst char *Curl_winapi_strerror(DWORD err, char *buf, size_t buflen)
93213498266Sopenharmony_ci{
93313498266Sopenharmony_ci#ifdef PRESERVE_WINDOWS_ERROR_CODE
93413498266Sopenharmony_ci  DWORD old_win_err = GetLastError();
93513498266Sopenharmony_ci#endif
93613498266Sopenharmony_ci  int old_errno = errno;
93713498266Sopenharmony_ci
93813498266Sopenharmony_ci  if(!buflen)
93913498266Sopenharmony_ci    return NULL;
94013498266Sopenharmony_ci
94113498266Sopenharmony_ci  *buf = '\0';
94213498266Sopenharmony_ci
94313498266Sopenharmony_ci#ifndef CURL_DISABLE_VERBOSE_STRINGS
94413498266Sopenharmony_ci  if(!get_winapi_error(err, buf, buflen)) {
94513498266Sopenharmony_ci    msnprintf(buf, buflen, "Unknown error %lu (0x%08lX)", err, err);
94613498266Sopenharmony_ci  }
94713498266Sopenharmony_ci#else
94813498266Sopenharmony_ci  {
94913498266Sopenharmony_ci    const char *txt = (err == ERROR_SUCCESS) ? "No error" : "Error";
95013498266Sopenharmony_ci    if(strlen(txt) < buflen)
95113498266Sopenharmony_ci      strcpy(buf, txt);
95213498266Sopenharmony_ci  }
95313498266Sopenharmony_ci#endif
95413498266Sopenharmony_ci
95513498266Sopenharmony_ci  if(errno != old_errno)
95613498266Sopenharmony_ci    errno = old_errno;
95713498266Sopenharmony_ci
95813498266Sopenharmony_ci#ifdef PRESERVE_WINDOWS_ERROR_CODE
95913498266Sopenharmony_ci  if(old_win_err != GetLastError())
96013498266Sopenharmony_ci    SetLastError(old_win_err);
96113498266Sopenharmony_ci#endif
96213498266Sopenharmony_ci
96313498266Sopenharmony_ci  return buf;
96413498266Sopenharmony_ci}
96513498266Sopenharmony_ci#endif /* _WIN32 || _WIN32_WCE */
96613498266Sopenharmony_ci
96713498266Sopenharmony_ci#ifdef USE_WINDOWS_SSPI
96813498266Sopenharmony_ci/*
96913498266Sopenharmony_ci * Curl_sspi_strerror:
97013498266Sopenharmony_ci * Variant of Curl_strerror if the error code is definitely Windows SSPI.
97113498266Sopenharmony_ci */
97213498266Sopenharmony_ciconst char *Curl_sspi_strerror(int err, char *buf, size_t buflen)
97313498266Sopenharmony_ci{
97413498266Sopenharmony_ci#ifdef PRESERVE_WINDOWS_ERROR_CODE
97513498266Sopenharmony_ci  DWORD old_win_err = GetLastError();
97613498266Sopenharmony_ci#endif
97713498266Sopenharmony_ci  int old_errno = errno;
97813498266Sopenharmony_ci  const char *txt;
97913498266Sopenharmony_ci
98013498266Sopenharmony_ci  if(!buflen)
98113498266Sopenharmony_ci    return NULL;
98213498266Sopenharmony_ci
98313498266Sopenharmony_ci  *buf = '\0';
98413498266Sopenharmony_ci
98513498266Sopenharmony_ci#ifndef CURL_DISABLE_VERBOSE_STRINGS
98613498266Sopenharmony_ci
98713498266Sopenharmony_ci  switch(err) {
98813498266Sopenharmony_ci    case SEC_E_OK:
98913498266Sopenharmony_ci      txt = "No error";
99013498266Sopenharmony_ci      break;
99113498266Sopenharmony_ci#define SEC2TXT(sec) case sec: txt = #sec; break
99213498266Sopenharmony_ci    SEC2TXT(CRYPT_E_REVOKED);
99313498266Sopenharmony_ci    SEC2TXT(CRYPT_E_NO_REVOCATION_DLL);
99413498266Sopenharmony_ci    SEC2TXT(CRYPT_E_NO_REVOCATION_CHECK);
99513498266Sopenharmony_ci    SEC2TXT(CRYPT_E_REVOCATION_OFFLINE);
99613498266Sopenharmony_ci    SEC2TXT(CRYPT_E_NOT_IN_REVOCATION_DATABASE);
99713498266Sopenharmony_ci    SEC2TXT(SEC_E_ALGORITHM_MISMATCH);
99813498266Sopenharmony_ci    SEC2TXT(SEC_E_BAD_BINDINGS);
99913498266Sopenharmony_ci    SEC2TXT(SEC_E_BAD_PKGID);
100013498266Sopenharmony_ci    SEC2TXT(SEC_E_BUFFER_TOO_SMALL);
100113498266Sopenharmony_ci    SEC2TXT(SEC_E_CANNOT_INSTALL);
100213498266Sopenharmony_ci    SEC2TXT(SEC_E_CANNOT_PACK);
100313498266Sopenharmony_ci    SEC2TXT(SEC_E_CERT_EXPIRED);
100413498266Sopenharmony_ci    SEC2TXT(SEC_E_CERT_UNKNOWN);
100513498266Sopenharmony_ci    SEC2TXT(SEC_E_CERT_WRONG_USAGE);
100613498266Sopenharmony_ci    SEC2TXT(SEC_E_CONTEXT_EXPIRED);
100713498266Sopenharmony_ci    SEC2TXT(SEC_E_CROSSREALM_DELEGATION_FAILURE);
100813498266Sopenharmony_ci    SEC2TXT(SEC_E_CRYPTO_SYSTEM_INVALID);
100913498266Sopenharmony_ci    SEC2TXT(SEC_E_DECRYPT_FAILURE);
101013498266Sopenharmony_ci    SEC2TXT(SEC_E_DELEGATION_POLICY);
101113498266Sopenharmony_ci    SEC2TXT(SEC_E_DELEGATION_REQUIRED);
101213498266Sopenharmony_ci    SEC2TXT(SEC_E_DOWNGRADE_DETECTED);
101313498266Sopenharmony_ci    SEC2TXT(SEC_E_ENCRYPT_FAILURE);
101413498266Sopenharmony_ci    SEC2TXT(SEC_E_ILLEGAL_MESSAGE);
101513498266Sopenharmony_ci    SEC2TXT(SEC_E_INCOMPLETE_CREDENTIALS);
101613498266Sopenharmony_ci    SEC2TXT(SEC_E_INCOMPLETE_MESSAGE);
101713498266Sopenharmony_ci    SEC2TXT(SEC_E_INSUFFICIENT_MEMORY);
101813498266Sopenharmony_ci    SEC2TXT(SEC_E_INTERNAL_ERROR);
101913498266Sopenharmony_ci    SEC2TXT(SEC_E_INVALID_HANDLE);
102013498266Sopenharmony_ci    SEC2TXT(SEC_E_INVALID_PARAMETER);
102113498266Sopenharmony_ci    SEC2TXT(SEC_E_INVALID_TOKEN);
102213498266Sopenharmony_ci    SEC2TXT(SEC_E_ISSUING_CA_UNTRUSTED);
102313498266Sopenharmony_ci    SEC2TXT(SEC_E_ISSUING_CA_UNTRUSTED_KDC);
102413498266Sopenharmony_ci    SEC2TXT(SEC_E_KDC_CERT_EXPIRED);
102513498266Sopenharmony_ci    SEC2TXT(SEC_E_KDC_CERT_REVOKED);
102613498266Sopenharmony_ci    SEC2TXT(SEC_E_KDC_INVALID_REQUEST);
102713498266Sopenharmony_ci    SEC2TXT(SEC_E_KDC_UNABLE_TO_REFER);
102813498266Sopenharmony_ci    SEC2TXT(SEC_E_KDC_UNKNOWN_ETYPE);
102913498266Sopenharmony_ci    SEC2TXT(SEC_E_LOGON_DENIED);
103013498266Sopenharmony_ci    SEC2TXT(SEC_E_MAX_REFERRALS_EXCEEDED);
103113498266Sopenharmony_ci    SEC2TXT(SEC_E_MESSAGE_ALTERED);
103213498266Sopenharmony_ci    SEC2TXT(SEC_E_MULTIPLE_ACCOUNTS);
103313498266Sopenharmony_ci    SEC2TXT(SEC_E_MUST_BE_KDC);
103413498266Sopenharmony_ci    SEC2TXT(SEC_E_NOT_OWNER);
103513498266Sopenharmony_ci    SEC2TXT(SEC_E_NO_AUTHENTICATING_AUTHORITY);
103613498266Sopenharmony_ci    SEC2TXT(SEC_E_NO_CREDENTIALS);
103713498266Sopenharmony_ci    SEC2TXT(SEC_E_NO_IMPERSONATION);
103813498266Sopenharmony_ci    SEC2TXT(SEC_E_NO_IP_ADDRESSES);
103913498266Sopenharmony_ci    SEC2TXT(SEC_E_NO_KERB_KEY);
104013498266Sopenharmony_ci    SEC2TXT(SEC_E_NO_PA_DATA);
104113498266Sopenharmony_ci    SEC2TXT(SEC_E_NO_S4U_PROT_SUPPORT);
104213498266Sopenharmony_ci    SEC2TXT(SEC_E_NO_TGT_REPLY);
104313498266Sopenharmony_ci    SEC2TXT(SEC_E_OUT_OF_SEQUENCE);
104413498266Sopenharmony_ci    SEC2TXT(SEC_E_PKINIT_CLIENT_FAILURE);
104513498266Sopenharmony_ci    SEC2TXT(SEC_E_PKINIT_NAME_MISMATCH);
104613498266Sopenharmony_ci    SEC2TXT(SEC_E_POLICY_NLTM_ONLY);
104713498266Sopenharmony_ci    SEC2TXT(SEC_E_QOP_NOT_SUPPORTED);
104813498266Sopenharmony_ci    SEC2TXT(SEC_E_REVOCATION_OFFLINE_C);
104913498266Sopenharmony_ci    SEC2TXT(SEC_E_REVOCATION_OFFLINE_KDC);
105013498266Sopenharmony_ci    SEC2TXT(SEC_E_SECPKG_NOT_FOUND);
105113498266Sopenharmony_ci    SEC2TXT(SEC_E_SECURITY_QOS_FAILED);
105213498266Sopenharmony_ci    SEC2TXT(SEC_E_SHUTDOWN_IN_PROGRESS);
105313498266Sopenharmony_ci    SEC2TXT(SEC_E_SMARTCARD_CERT_EXPIRED);
105413498266Sopenharmony_ci    SEC2TXT(SEC_E_SMARTCARD_CERT_REVOKED);
105513498266Sopenharmony_ci    SEC2TXT(SEC_E_SMARTCARD_LOGON_REQUIRED);
105613498266Sopenharmony_ci    SEC2TXT(SEC_E_STRONG_CRYPTO_NOT_SUPPORTED);
105713498266Sopenharmony_ci    SEC2TXT(SEC_E_TARGET_UNKNOWN);
105813498266Sopenharmony_ci    SEC2TXT(SEC_E_TIME_SKEW);
105913498266Sopenharmony_ci    SEC2TXT(SEC_E_TOO_MANY_PRINCIPALS);
106013498266Sopenharmony_ci    SEC2TXT(SEC_E_UNFINISHED_CONTEXT_DELETED);
106113498266Sopenharmony_ci    SEC2TXT(SEC_E_UNKNOWN_CREDENTIALS);
106213498266Sopenharmony_ci    SEC2TXT(SEC_E_UNSUPPORTED_FUNCTION);
106313498266Sopenharmony_ci    SEC2TXT(SEC_E_UNSUPPORTED_PREAUTH);
106413498266Sopenharmony_ci    SEC2TXT(SEC_E_UNTRUSTED_ROOT);
106513498266Sopenharmony_ci    SEC2TXT(SEC_E_WRONG_CREDENTIAL_HANDLE);
106613498266Sopenharmony_ci    SEC2TXT(SEC_E_WRONG_PRINCIPAL);
106713498266Sopenharmony_ci    SEC2TXT(SEC_I_COMPLETE_AND_CONTINUE);
106813498266Sopenharmony_ci    SEC2TXT(SEC_I_COMPLETE_NEEDED);
106913498266Sopenharmony_ci    SEC2TXT(SEC_I_CONTEXT_EXPIRED);
107013498266Sopenharmony_ci    SEC2TXT(SEC_I_CONTINUE_NEEDED);
107113498266Sopenharmony_ci    SEC2TXT(SEC_I_INCOMPLETE_CREDENTIALS);
107213498266Sopenharmony_ci    SEC2TXT(SEC_I_LOCAL_LOGON);
107313498266Sopenharmony_ci    SEC2TXT(SEC_I_NO_LSA_CONTEXT);
107413498266Sopenharmony_ci    SEC2TXT(SEC_I_RENEGOTIATE);
107513498266Sopenharmony_ci    SEC2TXT(SEC_I_SIGNATURE_NEEDED);
107613498266Sopenharmony_ci    default:
107713498266Sopenharmony_ci      txt = "Unknown error";
107813498266Sopenharmony_ci  }
107913498266Sopenharmony_ci
108013498266Sopenharmony_ci  if(err == SEC_E_ILLEGAL_MESSAGE) {
108113498266Sopenharmony_ci    msnprintf(buf, buflen,
108213498266Sopenharmony_ci              "SEC_E_ILLEGAL_MESSAGE (0x%08X) - This error usually occurs "
108313498266Sopenharmony_ci              "when a fatal SSL/TLS alert is received (e.g. handshake failed)."
108413498266Sopenharmony_ci              " More detail may be available in the Windows System event log.",
108513498266Sopenharmony_ci              err);
108613498266Sopenharmony_ci  }
108713498266Sopenharmony_ci  else {
108813498266Sopenharmony_ci    char msgbuf[256];
108913498266Sopenharmony_ci    if(get_winapi_error(err, msgbuf, sizeof(msgbuf)))
109013498266Sopenharmony_ci      msnprintf(buf, buflen, "%s (0x%08X) - %s", txt, err, msgbuf);
109113498266Sopenharmony_ci    else
109213498266Sopenharmony_ci      msnprintf(buf, buflen, "%s (0x%08X)", txt, err);
109313498266Sopenharmony_ci  }
109413498266Sopenharmony_ci
109513498266Sopenharmony_ci#else
109613498266Sopenharmony_ci  if(err == SEC_E_OK)
109713498266Sopenharmony_ci    txt = "No error";
109813498266Sopenharmony_ci  else
109913498266Sopenharmony_ci    txt = "Error";
110013498266Sopenharmony_ci  if(buflen > strlen(txt))
110113498266Sopenharmony_ci    strcpy(buf, txt);
110213498266Sopenharmony_ci#endif
110313498266Sopenharmony_ci
110413498266Sopenharmony_ci  if(errno != old_errno)
110513498266Sopenharmony_ci    errno = old_errno;
110613498266Sopenharmony_ci
110713498266Sopenharmony_ci#ifdef PRESERVE_WINDOWS_ERROR_CODE
110813498266Sopenharmony_ci  if(old_win_err != GetLastError())
110913498266Sopenharmony_ci    SetLastError(old_win_err);
111013498266Sopenharmony_ci#endif
111113498266Sopenharmony_ci
111213498266Sopenharmony_ci  return buf;
111313498266Sopenharmony_ci}
111413498266Sopenharmony_ci#endif /* USE_WINDOWS_SSPI */
1115