Merge from vendor branch BINUTILS:
[dragonfly.git] / contrib / bind-9.3 / lib / lwres / gai_strerror.c
1 /*
2  * Copyright (C) 2004, 2006  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 2000, 2001  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: gai_strerror.c,v 1.14.2.1.10.3 2006/08/25 05:25:50 marka Exp $ */
19
20 #include <config.h>
21
22 #include <lwres/netdb.h>
23
24 static const char *gai_messages[] = {
25         "no error",
26         "address family for hostname not supported",
27         "temporary failure in name resolution",
28         "invalid value for ai_flags",
29         "non-recoverable failure in name resolution",
30         "ai_family not supported",
31         "memory allocation failure",
32         "no address associated with hostname",
33         "hostname nor servname provided, or not known",
34         "servname not supported for ai_socktype",
35         "ai_socktype not supported",
36         "system error returned in errno",
37         "bad hints",
38         "bad protocol"
39 };
40
41 char *
42 lwres_gai_strerror(int ecode) {
43         union {
44                 const char *const_ptr;
45                 char *deconst_ptr;
46         } ptr;
47
48         if ((ecode < 0) ||
49             (ecode >= (int)(sizeof(gai_messages)/sizeof(*gai_messages))))
50                 ptr.const_ptr = "invalid error code";
51         else
52                 ptr.const_ptr = gai_messages[ecode];
53         return (ptr.deconst_ptr);
54 }