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