Line data Source code
1 : /**
2 : r_errors.c
3 :
4 :
5 : Copyright (C) 2002-2003, Network Resonance, Inc.
6 : Copyright (C) 2006, Network Resonance, Inc.
7 : All Rights Reserved
8 :
9 : Redistribution and use in source and binary forms, with or without
10 : modification, are permitted provided that the following conditions
11 : are met:
12 :
13 : 1. Redistributions of source code must retain the above copyright
14 : notice, this list of conditions and the following disclaimer.
15 : 2. Redistributions in binary form must reproduce the above copyright
16 : notice, this list of conditions and the following disclaimer in the
17 : documentation and/or other materials provided with the distribution.
18 : 3. Neither the name of Network Resonance, Inc. nor the name of any
19 : contributors to this software may be used to endorse or promote
20 : products derived from this software without specific prior written
21 : permission.
22 :
23 : THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
24 : AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 : IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 : ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 : LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 : CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 : SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 : INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 : CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 : ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 : POSSIBILITY OF SUCH DAMAGE.
34 :
35 :
36 : */
37 :
38 : /**
39 : r_errors.c
40 :
41 :
42 : Copyright (C) 1999-2000 RTFM, Inc.
43 : All Rights Reserved
44 :
45 : This package is a SSLv3/TLS protocol analyzer written by Eric Rescorla
46 : <ekr@rtfm.com> and licensed by RTFM, Inc.
47 :
48 : Redistribution and use in source and binary forms, with or without
49 : modification, are permitted provided that the following conditions
50 : are met:
51 : 1. Redistributions of source code must retain the above copyright
52 : notice, this list of conditions and the following disclaimer.
53 : 2. Redistributions in binary form must reproduce the above copyright
54 : notice, this list of conditions and the following disclaimer in the
55 : documentation and/or other materials provided with the distribution.
56 : 3. All advertising materials mentioning features or use of this software
57 : must display the following acknowledgement:
58 :
59 : This product includes software developed by Eric Rescorla for
60 : RTFM, Inc.
61 :
62 : 4. Neither the name of RTFM, Inc. nor the name of Eric Rescorla may be
63 : used to endorse or promote products derived from this
64 : software without specific prior written permission.
65 :
66 : THIS SOFTWARE IS PROVIDED BY ERIC RESCORLA AND RTFM, INC. ``AS IS'' AND
67 : ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
68 : IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
69 : ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
70 : FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
71 : DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
72 : OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
73 : HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
74 : LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
75 : OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY SUCH DAMAGE.
76 :
77 : $Id: r_errors.c,v 1.5 2008/11/26 03:22:02 adamcain Exp $
78 :
79 :
80 : ekr@rtfm.com Tue Feb 16 16:37:05 1999
81 : */
82 :
83 :
84 : static char *RCSSTRING __UNUSED__ ="$Id: r_errors.c,v 1.5 2008/11/26 03:22:02 adamcain Exp $";
85 :
86 : #include <stdio.h>
87 : #include <stdarg.h>
88 : #include <string.h>
89 : #include "r_common.h"
90 : #include "r_errors.h"
91 :
92 : static struct {
93 : int errnum;
94 : char *str;
95 : } errors[] = NR_ERROR_MAPPING;
96 :
97 0 : int nr_verr_exit(char *fmt,...)
98 : {
99 : va_list ap;
100 :
101 0 : va_start(ap,fmt);
102 0 : vfprintf(stderr,fmt,ap);
103 :
104 0 : if (fmt[0] != '\0' && fmt[strlen(fmt)-1] != '\n')
105 0 : fprintf(stderr,"\n");
106 :
107 0 : exit(1);
108 : }
109 :
110 : char *
111 0 : nr_strerror(int errnum)
112 : {
113 : static char unknown_error[256];
114 : int i;
115 0 : char *error = 0;
116 :
117 0 : for (i = 0; i < sizeof(errors)/sizeof(*errors); ++i) {
118 0 : if (errnum == errors[i].errnum) {
119 0 : error = errors[i].str;
120 0 : break;
121 : }
122 : }
123 :
124 0 : if (! error) {
125 0 : snprintf(unknown_error, sizeof(unknown_error), "Unknown error: %d", errnum);
126 0 : error = unknown_error;
127 : }
128 :
129 0 : return error;
130 : }
131 :
132 : int
133 0 : nr_strerror_r(int errnum, char *strerrbuf, size_t buflen)
134 : {
135 0 : char *error = nr_strerror(errnum);
136 0 : snprintf(strerrbuf, buflen, "%s", error);
137 0 : return 0;
138 : }
139 :
|