return code cleanup: build, init and run-time errors
[platform/upstream/curl.git] / lib / strerror.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 2004 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at http://curl.haxx.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  ***************************************************************************/
22
23 #include "setup.h"
24
25 #ifdef HAVE_STRERROR_R
26 #  if (!defined(HAVE_POSIX_STRERROR_R) && \
27        !defined(HAVE_GLIBC_STRERROR_R) && \
28        !defined(HAVE_VXWORKS_STRERROR_R)) || \
29       (defined(HAVE_POSIX_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)) || \
30       (defined(HAVE_GLIBC_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)) || \
31       (defined(HAVE_POSIX_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R))
32 #    error "strerror_r MUST be either POSIX-style, glibc-style or vxworks-style"
33 #  endif
34 #endif
35
36 #include <curl/curl.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <errno.h>
40
41 #ifdef USE_LIBIDN
42 #include <idna.h>
43 #endif
44
45 #include "strerror.h"
46
47 #define _MPRINTF_REPLACE /* use our functions only */
48 #include <curl/mprintf.h>
49
50
51 const char *
52 curl_easy_strerror(CURLcode error)
53 {
54 #ifndef CURL_DISABLE_VERBOSE_STRINGS
55   switch (error) {
56   case CURLE_OK:
57     return "No error";
58
59   case CURLE_UNSUPPORTED_PROTOCOL:
60     return "Unsupported protocol";
61
62   case CURLE_FAILED_INIT:
63     return "Failed initialization";
64
65   case CURLE_URL_MALFORMAT:
66     return "URL using bad/illegal format or missing URL";
67
68   case CURLE_NOT_BUILT_IN:
69     return "A requested feature, protocol or option was not found built-in in"
70       " this libcurl due to a build-time decision.";
71
72   case CURLE_COULDNT_RESOLVE_PROXY:
73     return "Couldn't resolve proxy name";
74
75   case CURLE_COULDNT_RESOLVE_HOST:
76     return "Couldn't resolve host name";
77
78   case CURLE_COULDNT_CONNECT:
79     return "Couldn't connect to server";
80
81   case CURLE_FTP_WEIRD_SERVER_REPLY:
82     return "FTP: weird server reply";
83
84   case CURLE_REMOTE_ACCESS_DENIED:
85     return "Access denied to remote resource";
86
87   case CURLE_FTP_PRET_FAILED:
88     return "FTP: The server did not accept the PRET command.";
89
90   case CURLE_FTP_WEIRD_PASS_REPLY:
91     return "FTP: unknown PASS reply";
92
93   case CURLE_FTP_WEIRD_PASV_REPLY:
94     return "FTP: unknown PASV reply";
95
96   case CURLE_FTP_WEIRD_227_FORMAT:
97     return "FTP: unknown 227 response format";
98
99   case CURLE_FTP_CANT_GET_HOST:
100     return "FTP: can't figure out the host in the PASV response";
101
102   case CURLE_FTP_COULDNT_SET_TYPE:
103     return "FTP: couldn't set file type";
104
105   case CURLE_PARTIAL_FILE:
106     return "Transferred a partial file";
107
108   case CURLE_FTP_COULDNT_RETR_FILE:
109     return "FTP: couldn't retrieve (RETR failed) the specified file";
110
111   case CURLE_QUOTE_ERROR:
112     return "Quote command returned error";
113
114   case CURLE_HTTP_RETURNED_ERROR:
115     return "HTTP response code said error";
116
117   case CURLE_WRITE_ERROR:
118     return "Failed writing received data to disk/application";
119
120   case CURLE_UPLOAD_FAILED:
121     return "Upload failed (at start/before it took off)";
122
123   case CURLE_READ_ERROR:
124     return "Failed to open/read local data from file/application";
125
126   case CURLE_OUT_OF_MEMORY:
127     return "Out of memory";
128
129   case CURLE_OPERATION_TIMEDOUT:
130     return "Timeout was reached";
131
132   case CURLE_FTP_PORT_FAILED:
133     return "FTP: command PORT failed";
134
135   case CURLE_FTP_COULDNT_USE_REST:
136     return "FTP: command REST failed";
137
138   case CURLE_RANGE_ERROR:
139     return "Requested range was not delivered by the server";
140
141   case CURLE_HTTP_POST_ERROR:
142     return "Internal problem setting up the POST";
143
144   case CURLE_SSL_CONNECT_ERROR:
145     return "SSL connect error";
146
147   case CURLE_BAD_DOWNLOAD_RESUME:
148     return "Couldn't resume download";
149
150   case CURLE_FILE_COULDNT_READ_FILE:
151     return "Couldn't read a file:// file";
152
153   case CURLE_LDAP_CANNOT_BIND:
154     return "LDAP: cannot bind";
155
156   case CURLE_LDAP_SEARCH_FAILED:
157     return "LDAP: search failed";
158
159   case CURLE_FUNCTION_NOT_FOUND:
160     return "A required function in the library was not found";
161
162   case CURLE_ABORTED_BY_CALLBACK:
163     return "Operation was aborted by an application callback";
164
165   case CURLE_BAD_FUNCTION_ARGUMENT:
166     return "A libcurl function was given a bad argument";
167
168   case CURLE_INTERFACE_FAILED:
169     return "Failed binding local connection end";
170
171   case CURLE_TOO_MANY_REDIRECTS :
172     return "Number of redirects hit maximum amount";
173
174   case CURLE_UNKNOWN_OPTION:
175     return "An unknown option was passed in to libcurl";
176
177   case CURLE_TELNET_OPTION_SYNTAX :
178     return "Malformed telnet option";
179
180   case CURLE_PEER_FAILED_VERIFICATION:
181     return "SSL peer certificate or SSH remote key was not OK";
182
183   case CURLE_GOT_NOTHING:
184     return "Server returned nothing (no headers, no data)";
185
186   case CURLE_SSL_ENGINE_NOTFOUND:
187     return "SSL crypto engine not found";
188
189   case CURLE_SSL_ENGINE_SETFAILED:
190     return "Can not set SSL crypto engine as default";
191
192   case CURLE_SSL_ENGINE_INITFAILED:
193     return "Failed to initialise SSL crypto engine";
194
195   case CURLE_SEND_ERROR:
196     return "Failed sending data to the peer";
197
198   case CURLE_RECV_ERROR:
199     return "Failure when receiving data from the peer";
200
201   case CURLE_SSL_CERTPROBLEM:
202     return "Problem with the local SSL certificate";
203
204   case CURLE_SSL_CIPHER:
205     return "Couldn't use specified SSL cipher";
206
207   case CURLE_SSL_CACERT:
208     return "Peer certificate cannot be authenticated with known CA certificates";
209
210   case CURLE_SSL_CACERT_BADFILE:
211     return "Problem with the SSL CA cert (path? access rights?)";
212
213   case CURLE_BAD_CONTENT_ENCODING:
214     return "Unrecognized HTTP Content-Encoding";
215
216   case CURLE_LDAP_INVALID_URL:
217     return "Invalid LDAP URL";
218
219   case CURLE_FILESIZE_EXCEEDED:
220     return "Maximum file size exceeded";
221
222   case CURLE_USE_SSL_FAILED:
223     return "Requested SSL level failed";
224
225   case CURLE_SSL_SHUTDOWN_FAILED:
226     return "Failed to shut down the SSL connection";
227
228   case CURLE_SSL_CRL_BADFILE:
229     return "Failed to load CRL file (path? access rights?, format?)";
230
231   case CURLE_SSL_ISSUER_ERROR:
232     return "Issuer check against peer certificate failed";
233
234   case CURLE_SEND_FAIL_REWIND:
235     return "Send failed since rewinding of the data stream failed";
236
237   case CURLE_LOGIN_DENIED:
238     return "Login denied";
239
240   case CURLE_TFTP_NOTFOUND:
241     return "TFTP: File Not Found";
242
243   case CURLE_TFTP_PERM:
244     return "TFTP: Access Violation";
245
246   case CURLE_REMOTE_DISK_FULL:
247     return "Disk full or allocation exceeded";
248
249   case CURLE_TFTP_ILLEGAL:
250     return "TFTP: Illegal operation";
251
252   case CURLE_TFTP_UNKNOWNID:
253     return "TFTP: Unknown transfer ID";
254
255   case CURLE_REMOTE_FILE_EXISTS:
256     return "Remote file already exists";
257
258   case CURLE_TFTP_NOSUCHUSER:
259     return "TFTP: No such user";
260
261   case CURLE_CONV_FAILED:
262     return "Conversion failed";
263
264   case CURLE_CONV_REQD:
265     return "Caller must register CURLOPT_CONV_ callback options";
266
267   case CURLE_REMOTE_FILE_NOT_FOUND:
268     return "Remote file not found";
269
270   case CURLE_SSH:
271     return "Error in the SSH layer";
272
273   case CURLE_AGAIN:
274     return "Socket not ready for send/recv";
275
276   case CURLE_RTSP_CSEQ_ERROR:
277     return "RTSP CSeq mismatch or invalid CSeq";
278
279   case CURLE_RTSP_SESSION_ERROR:
280     return "RTSP session error";
281
282   case CURLE_FTP_BAD_FILE_LIST:
283     return "Unable to parse FTP file list";
284
285   case CURLE_CHUNK_FAILED:
286     return "Chunk callback failed";
287
288     /* error codes not used by current libcurl */
289   case CURLE_OBSOLETE10:
290   case CURLE_OBSOLETE12:
291   case CURLE_OBSOLETE16:
292   case CURLE_OBSOLETE20:
293   case CURLE_OBSOLETE24:
294   case CURLE_OBSOLETE29:
295   case CURLE_OBSOLETE32:
296   case CURLE_OBSOLETE40:
297   case CURLE_OBSOLETE44:
298   case CURLE_OBSOLETE46:
299   case CURLE_OBSOLETE50:
300   case CURLE_OBSOLETE57:
301   case CURL_LAST:
302     break;
303   }
304   /*
305    * By using a switch, gcc -Wall will complain about enum values
306    * which do not appear, helping keep this function up-to-date.
307    * By using gcc -Wall -Werror, you can't forget.
308    *
309    * A table would not have the same benefit.  Most compilers will
310    * generate code very similar to a table in any case, so there
311    * is little performance gain from a table.  And something is broken
312    * for the user's application, anyways, so does it matter how fast
313    * it _doesn't_ work?
314    *
315    * The line number for the error will be near this comment, which
316    * is why it is here, and not at the start of the switch.
317    */
318   return "Unknown error";
319 #else
320   if(error == CURLE_OK)
321     return "No error";
322   else
323     return "Error";
324 #endif
325 }
326
327 const char *
328 curl_multi_strerror(CURLMcode error)
329 {
330 #ifndef CURL_DISABLE_VERBOSE_STRINGS
331   switch (error) {
332   case CURLM_CALL_MULTI_PERFORM:
333     return "Please call curl_multi_perform() soon";
334
335   case CURLM_OK:
336     return "No error";
337
338   case CURLM_BAD_HANDLE:
339     return "Invalid multi handle";
340
341   case CURLM_BAD_EASY_HANDLE:
342     return "Invalid easy handle";
343
344   case CURLM_OUT_OF_MEMORY:
345     return "Out of memory";
346
347   case CURLM_INTERNAL_ERROR:
348     return "Internal error";
349
350   case CURLM_BAD_SOCKET:
351     return "Invalid socket argument";
352
353   case CURLM_UNKNOWN_OPTION:
354     return "Unknown option";
355
356   case CURLM_LAST:
357     break;
358   }
359
360   return "Unknown error";
361 #else
362   if(error == CURLM_OK)
363     return "No error";
364   else
365     return "Error";
366 #endif
367 }
368
369 const char *
370 curl_share_strerror(CURLSHcode error)
371 {
372 #ifndef CURL_DISABLE_VERBOSE_STRINGS
373   switch (error) {
374   case CURLSHE_OK:
375     return "No error";
376
377   case CURLSHE_BAD_OPTION:
378     return "Unknown share option";
379
380   case CURLSHE_IN_USE:
381     return "Share currently in use";
382
383   case CURLSHE_INVALID:
384     return "Invalid share handle";
385
386   case CURLSHE_NOMEM:
387     return "Out of memory";
388
389   case CURLSHE_LAST:
390     break;
391   }
392
393   return "CURLSHcode unknown";
394 #else
395   if(error == CURLSHE_OK)
396     return "No error";
397   else
398     return "Error";
399 #endif
400 }
401
402 #ifdef USE_WINSOCK
403
404 /* This function handles most / all (?) Winsock errors cURL is able to produce.
405  */
406 static const char *
407 get_winsock_error (int err, char *buf, size_t len)
408 {
409   const char *p;
410
411 #ifndef CURL_DISABLE_VERBOSE_STRINGS
412   switch (err) {
413   case WSAEINTR:
414     p = "Call interrupted";
415     break;
416   case WSAEBADF:
417     p = "Bad file";
418     break;
419   case WSAEACCES:
420     p = "Bad access";
421     break;
422   case WSAEFAULT:
423     p = "Bad argument";
424     break;
425   case WSAEINVAL:
426     p = "Invalid arguments";
427     break;
428   case WSAEMFILE:
429     p = "Out of file descriptors";
430     break;
431   case WSAEWOULDBLOCK:
432     p = "Call would block";
433     break;
434   case WSAEINPROGRESS:
435   case WSAEALREADY:
436     p = "Blocking call in progress";
437     break;
438   case WSAENOTSOCK:
439     p = "Descriptor is not a socket";
440     break;
441   case WSAEDESTADDRREQ:
442     p = "Need destination address";
443     break;
444   case WSAEMSGSIZE:
445     p = "Bad message size";
446     break;
447   case WSAEPROTOTYPE:
448     p = "Bad protocol";
449     break;
450   case WSAENOPROTOOPT:
451     p = "Protocol option is unsupported";
452     break;
453   case WSAEPROTONOSUPPORT:
454     p = "Protocol is unsupported";
455     break;
456   case WSAESOCKTNOSUPPORT:
457     p = "Socket is unsupported";
458     break;
459   case WSAEOPNOTSUPP:
460     p = "Operation not supported";
461     break;
462   case WSAEAFNOSUPPORT:
463     p = "Address family not supported";
464     break;
465   case WSAEPFNOSUPPORT:
466     p = "Protocol family not supported";
467     break;
468   case WSAEADDRINUSE:
469     p = "Address already in use";
470     break;
471   case WSAEADDRNOTAVAIL:
472     p = "Address not available";
473     break;
474   case WSAENETDOWN:
475     p = "Network down";
476     break;
477   case WSAENETUNREACH:
478     p = "Network unreachable";
479     break;
480   case WSAENETRESET:
481     p = "Network has been reset";
482     break;
483   case WSAECONNABORTED:
484     p = "Connection was aborted";
485     break;
486   case WSAECONNRESET:
487     p = "Connection was reset";
488     break;
489   case WSAENOBUFS:
490     p = "No buffer space";
491     break;
492   case WSAEISCONN:
493     p = "Socket is already connected";
494     break;
495   case WSAENOTCONN:
496     p = "Socket is not connected";
497     break;
498   case WSAESHUTDOWN:
499     p = "Socket has been shut down";
500     break;
501   case WSAETOOMANYREFS:
502     p = "Too many references";
503     break;
504   case WSAETIMEDOUT:
505     p = "Timed out";
506     break;
507   case WSAECONNREFUSED:
508     p = "Connection refused";
509     break;
510   case WSAELOOP:
511     p = "Loop??";
512     break;
513   case WSAENAMETOOLONG:
514     p = "Name too long";
515     break;
516   case WSAEHOSTDOWN:
517     p = "Host down";
518     break;
519   case WSAEHOSTUNREACH:
520     p = "Host unreachable";
521     break;
522   case WSAENOTEMPTY:
523     p = "Not empty";
524     break;
525   case WSAEPROCLIM:
526     p = "Process limit reached";
527     break;
528   case WSAEUSERS:
529     p = "Too many users";
530     break;
531   case WSAEDQUOT:
532     p = "Bad quota";
533     break;
534   case WSAESTALE:
535     p = "Something is stale";
536     break;
537   case WSAEREMOTE:
538     p = "Remote error";
539     break;
540 #ifdef WSAEDISCON  /* missing in SalfordC! */
541   case WSAEDISCON:
542     p = "Disconnected";
543     break;
544 #endif
545     /* Extended Winsock errors */
546   case WSASYSNOTREADY:
547     p = "Winsock library is not ready";
548     break;
549   case WSANOTINITIALISED:
550     p = "Winsock library not initialised";
551     break;
552   case WSAVERNOTSUPPORTED:
553     p = "Winsock version not supported";
554     break;
555
556     /* getXbyY() errors (already handled in herrmsg):
557      * Authoritative Answer: Host not found */
558   case WSAHOST_NOT_FOUND:
559     p = "Host not found";
560     break;
561
562     /* Non-Authoritative: Host not found, or SERVERFAIL */
563   case WSATRY_AGAIN:
564     p = "Host not found, try again";
565     break;
566
567     /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
568   case WSANO_RECOVERY:
569     p = "Unrecoverable error in call to nameserver";
570     break;
571
572     /* Valid name, no data record of requested type */
573   case WSANO_DATA:
574     p = "No data record of requested type";
575     break;
576
577   default:
578     return NULL;
579   }
580 #else
581   if(err == CURLE_OK)
582     return NULL;
583   else
584     p = "error";
585 #endif
586   strncpy (buf, p, len);
587   buf [len-1] = '\0';
588   return buf;
589 }
590 #endif   /* USE_WINSOCK */
591
592 /*
593  * Our thread-safe and smart strerror() replacement.
594  *
595  * The 'err' argument passed in to this function MUST be a true errno number
596  * as reported on this system. We do no range checking on the number before
597  * we pass it to the "number-to-message" conversion function and there might
598  * be systems that don't do proper range checking in there themselves.
599  *
600  * We don't do range checking (on systems other than Windows) since there is
601  * no good reliable and portable way to do it.
602  */
603 const char *Curl_strerror(struct connectdata *conn, int err)
604 {
605   char *buf, *p;
606   size_t max;
607   int old_errno = ERRNO;
608
609   DEBUGASSERT(conn);
610   DEBUGASSERT(err >= 0);
611
612   buf = conn->syserr_buf;
613   max = sizeof(conn->syserr_buf)-1;
614   *buf = '\0';
615
616 #ifdef USE_WINSOCK
617
618 #ifdef _WIN32_WCE
619   {
620     wchar_t wbuf[256];
621     wbuf[0] = L'\0';
622
623     FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
624                   LANG_NEUTRAL, wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL);
625     wcstombs(buf,wbuf,max);
626   }
627 #else
628   /* 'sys_nerr' is the maximum errno number, it is not widely portable */
629   if(err >= 0 && err < sys_nerr)
630     strncpy(buf, strerror(err), max);
631   else {
632     if(!get_winsock_error(err, buf, max) &&
633         !FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
634                        LANG_NEUTRAL, buf, (DWORD)max, NULL))
635       snprintf(buf, max, "Unknown error %d (%#x)", err, err);
636   }
637 #endif
638
639 #else /* not USE_WINSOCK coming up */
640
641 #if defined(HAVE_STRERROR_R) && defined(HAVE_POSIX_STRERROR_R)
642  /*
643   * The POSIX-style strerror_r() may set errno to ERANGE if insufficient
644   * storage is supplied via 'strerrbuf' and 'buflen' to hold the generated
645   * message string, or EINVAL if 'errnum' is not a valid error number.
646   */
647   if(0 != strerror_r(err, buf, max)) {
648     if('\0' == buf[0])
649       snprintf(buf, max, "Unknown error %d", err);
650   }
651 #elif defined(HAVE_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R)
652  /*
653   * The glibc-style strerror_r() only *might* use the buffer we pass to
654   * the function, but it always returns the error message as a pointer,
655   * so we must copy that string unconditionally (if non-NULL).
656   */
657   {
658     char buffer[256];
659     char *msg = strerror_r(err, buffer, sizeof(buffer));
660     if(msg)
661       strncpy(buf, msg, max);
662     else
663       snprintf(buf, max, "Unknown error %d", err);
664   }
665 #elif defined(HAVE_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)
666  /*
667   * The vxworks-style strerror_r() does use the buffer we pass to the function.
668   * The buffer size should be at least MAXERRSTR_SIZE (150) defined in rtsold.h
669   */
670   {
671     char buffer[256];
672     if(OK == strerror_r(err, buffer))
673       strncpy(buf, buffer, max);
674     else
675       snprintf(buf, max, "Unknown error %d", err);
676   }
677 #else
678   {
679     char *msg = strerror(err);
680     if(msg)
681       strncpy(buf, msg, max);
682     else
683       snprintf(buf, max, "Unknown error %d", err);
684   }
685 #endif
686
687 #endif /* end of ! USE_WINSOCK */
688
689   buf[max] = '\0'; /* make sure the string is zero terminated */
690
691   /* strip trailing '\r\n' or '\n'. */
692   if((p = strrchr(buf,'\n')) != NULL && (p - buf) >= 2)
693      *p = '\0';
694   if((p = strrchr(buf,'\r')) != NULL && (p - buf) >= 1)
695      *p = '\0';
696
697   if(old_errno != ERRNO)
698     SET_ERRNO(old_errno);
699
700   return buf;
701 }
702
703 #ifdef USE_LIBIDN
704 /*
705  * Return error-string for libidn status as returned from idna_to_ascii_lz().
706  */
707 const char *Curl_idn_strerror (struct connectdata *conn, int err)
708 {
709 #ifdef HAVE_IDNA_STRERROR
710   (void)conn;
711   return idna_strerror((Idna_rc) err);
712 #else
713   const char *str;
714   char *buf;
715   size_t max;
716
717   DEBUGASSERT(conn);
718
719   buf = conn->syserr_buf;
720   max = sizeof(conn->syserr_buf)-1;
721   *buf = '\0';
722
723 #ifndef CURL_DISABLE_VERBOSE_STRINGS
724   switch ((Idna_rc)err) {
725     case IDNA_SUCCESS:
726       str = "No error";
727       break;
728     case IDNA_STRINGPREP_ERROR:
729       str = "Error in string preparation";
730       break;
731     case IDNA_PUNYCODE_ERROR:
732       str = "Error in Punycode operation";
733       break;
734     case IDNA_CONTAINS_NON_LDH:
735       str = "Illegal ASCII characters";
736       break;
737     case IDNA_CONTAINS_MINUS:
738       str = "Contains minus";
739       break;
740     case IDNA_INVALID_LENGTH:
741       str = "Invalid output length";
742       break;
743     case IDNA_NO_ACE_PREFIX:
744       str = "No ACE prefix (\"xn--\")";
745       break;
746     case IDNA_ROUNDTRIP_VERIFY_ERROR:
747       str = "Round trip verify error";
748       break;
749     case IDNA_CONTAINS_ACE_PREFIX:
750       str = "Already have ACE prefix (\"xn--\")";
751       break;
752     case IDNA_ICONV_ERROR:
753       str = "Locale conversion failed";
754       break;
755     case IDNA_MALLOC_ERROR:
756       str = "Allocation failed";
757       break;
758     case IDNA_DLOPEN_ERROR:
759       str = "dlopen() error";
760       break;
761     default:
762       snprintf(buf, max, "error %d", err);
763       str = NULL;
764       break;
765   }
766 #else
767   if((Idna_rc)err == IDNA_SUCCESS)
768     str = "No error";
769   else
770     str = "Error";
771 #endif
772   if(str)
773     strncpy(buf, str, max);
774   buf[max] = '\0';
775   return (buf);
776 #endif
777 }
778 #endif  /* USE_LIBIDN */