]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/BsdSocketLib/herror.c
Fix send to properly wait while long transmits are in progress
[mirror_edk2.git] / StdLib / BsdSocketLib / herror.c
CommitLineData
d7ce7006 1/*\r
2 * Copyright (c) 1987, 1993\r
3 * The Regents of the University of California. All rights reserved.\r
4 *\r
5 * Portions copyright (c) 1999, 2000\r
6 * Intel Corporation.\r
7 * All rights reserved.\r
8 * \r
9 * Redistribution and use in source and binary forms, with or without\r
10 * modification, are permitted provided that the following conditions\r
11 * are met:\r
12 * \r
13 * 1. Redistributions of source code must retain the above copyright\r
14 * notice, this list of conditions and the following disclaimer.\r
15 * \r
16 * 2. Redistributions in binary form must reproduce the above copyright\r
17 * notice, this list of conditions and the following disclaimer in the\r
18 * documentation and/or other materials provided with the distribution.\r
19 * \r
20 * 3. All advertising materials mentioning features or use of this software\r
21 * must display the following acknowledgement:\r
22 * \r
23 * This product includes software developed by the University of\r
24 * California, Berkeley, Intel Corporation, and its contributors.\r
25 * \r
26 * 4. Neither the name of University, Intel Corporation, or their respective\r
27 * contributors may be used to endorse or promote products derived from\r
28 * this software without specific prior written permission.\r
29 * \r
30 * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND\r
31 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
32 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
33 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,\r
34 * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
35 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
36 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
40 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
41 *\r
42 */\r
43\r
44/*\r
45 * Portions Copyright (c) 1996 by Internet Software Consortium.\r
46 *\r
47 * Permission to use, copy, modify, and distribute this software for any\r
48 * purpose with or without fee is hereby granted, provided that the above\r
49 * copyright notice and this permission notice appear in all copies.\r
50 *\r
51 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS\r
52 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES\r
53 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE\r
54 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL\r
55 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR\r
56 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\r
57 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\r
58 * SOFTWARE.\r
59 */\r
60\r
61#if defined(LIBC_SCCS) && !defined(lint)\r
62static char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93";\r
63static char rcsid[] = "$Id: herror.c,v 1.1.1.1 2003/11/19 01:51:28 kyu3 Exp $";\r
64#endif /* LIBC_SCCS and not lint */\r
65\r
66#include <sys/types.h>\r
67#include <sys/uio.h>\r
68#include <netdb.h>\r
69#include <string.h>\r
70#include <stdio.h>\r
71#include <unistd.h>\r
72\r
73const char *h_errlist[] = {\r
74 "Resolver Error 0 (no error)",\r
75 "Unknown host", /* 1 HOST_NOT_FOUND */\r
76 "Host name lookup failure", /* 2 TRY_AGAIN */\r
77 "Unknown server error", /* 3 NO_RECOVERY */\r
78 "No address associated with name", /* 4 NO_ADDRESS */\r
79};\r
80int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };\r
81\r
82int h_errno;\r
83\r
84const char *\r
85hstrerror(\r
86 int err\r
87 );\r
88\r
89/*\r
90 * herror --\r
91 * print the error indicated by the h_errno value.\r
92 */\r
93void\r
94herror(\r
95 const char *s\r
96 )\r
97{\r
98 struct iovec iov[4];\r
99 register struct iovec *v = iov;\r
100 int i;\r
101\r
102 if (s && *s) {\r
103 v->iov_base = (char *)s;\r
104 v->iov_len = strlen(s);\r
105 v++;\r
106 v->iov_base = ": ";\r
107 v->iov_len = 2;\r
108 v++;\r
109 }\r
110 v->iov_base = (char *)hstrerror(h_errno);\r
111 v->iov_len = strlen(v->iov_base);\r
112 v++;\r
113 v->iov_base = "\n";\r
114 v->iov_len = 1;\r
115#ifdef _ORG_FREEBSD_\r
116 writev(STDERR_FILENO, iov, (v - iov) + 1);\r
117#else\r
118 for (i = 0; i < (v - iov) + 1; i++)\r
119 fprintf( stderr, iov[i].iov_base);\r
120#endif\r
121\r
122}\r
123\r
124const char *\r
125hstrerror(\r
126 int err\r
127 )\r
128{\r
129 if (err < 0)\r
130 return ("Resolver internal error");\r
131 else if (err < h_nerr)\r
132 return (h_errlist[err]);\r
133 return ("Unknown resolver error");\r
134}\r