Fix use of deprecated types, for now and the future.
[gnutls.git] / lib / minitasn1 / errors.c
blob86dec68d01e3dd7f29b1fb99486507ee827d9b63
1 /*
2 * Copyright (C) 2006, 2008, 2009 Free Software Foundation, Inc.
3 * Copyright (C) 2002, 2005 Fabio Fiorina
5 * This file is part of LIBTASN1.
7 * The LIBTASN1 library is free software; you can redistribute it
8 * and/or modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA
23 #include <int.h>
24 #ifdef STDC_HEADERS
25 # include <stdarg.h>
26 #endif
28 #define LIBTASN1_ERROR_ENTRY(name) { #name, name }
30 struct libtasn1_error_entry
32 const char *name;
33 int number;
35 typedef struct libtasn1_error_entry libtasn1_error_entry;
37 static const libtasn1_error_entry error_algorithms[] = {
38 LIBTASN1_ERROR_ENTRY (ASN1_SUCCESS),
39 LIBTASN1_ERROR_ENTRY (ASN1_FILE_NOT_FOUND),
40 LIBTASN1_ERROR_ENTRY (ASN1_ELEMENT_NOT_FOUND),
41 LIBTASN1_ERROR_ENTRY (ASN1_IDENTIFIER_NOT_FOUND),
42 LIBTASN1_ERROR_ENTRY (ASN1_DER_ERROR),
43 LIBTASN1_ERROR_ENTRY (ASN1_VALUE_NOT_FOUND),
44 LIBTASN1_ERROR_ENTRY (ASN1_GENERIC_ERROR),
45 LIBTASN1_ERROR_ENTRY (ASN1_VALUE_NOT_VALID),
46 LIBTASN1_ERROR_ENTRY (ASN1_TAG_ERROR),
47 LIBTASN1_ERROR_ENTRY (ASN1_TAG_IMPLICIT),
48 LIBTASN1_ERROR_ENTRY (ASN1_ERROR_TYPE_ANY),
49 LIBTASN1_ERROR_ENTRY (ASN1_SYNTAX_ERROR),
50 LIBTASN1_ERROR_ENTRY (ASN1_MEM_ERROR),
51 LIBTASN1_ERROR_ENTRY (ASN1_MEM_ALLOC_ERROR),
52 LIBTASN1_ERROR_ENTRY (ASN1_DER_OVERFLOW),
53 LIBTASN1_ERROR_ENTRY (ASN1_NAME_TOO_LONG),
54 LIBTASN1_ERROR_ENTRY (ASN1_ARRAY_ERROR),
55 LIBTASN1_ERROR_ENTRY (ASN1_ELEMENT_NOT_EMPTY),
56 {0, 0}
59 /**
60 * asn1_perror - prints a string to stderr with a description of an error
61 * @error: is an error returned by a libtasn1 function.
63 * This function is like perror(). The only difference is that it
64 * accepts an error returned by a libtasn1 function.
66 * This function replaces libtasn1_perror() in older libtasn1.
68 * Since: 1.6
69 **/
70 void
71 asn1_perror (asn1_retCode error)
73 const char *str = asn1_strerror (error);
74 fprintf (stderr, "LIBTASN1 ERROR: %s\n", str ? str : "(null)");
77 /**
78 * asn1_strerror - Returns a string with a description of an error
79 * @error: is an error returned by a libtasn1 function.
81 * This function is similar to strerror. The only difference is that
82 * it accepts an error (number) returned by a libtasn1 function.
84 * This function replaces libtasn1_strerror() in older libtasn1.
86 * Returns: Pointer to static zero-terminated string describing error
87 * code.
89 * Since: 1.6
90 **/
91 const char *
92 asn1_strerror (asn1_retCode error)
94 const libtasn1_error_entry *p;
96 for (p = error_algorithms; p->name != NULL; p++)
97 if (p->number == error)
98 return p->name + sizeof ("ASN1_") - 1;
100 return NULL;
103 #ifndef ASN1_DISABLE_DEPRECATED
105 /* Compatibility mappings to preserve ABI. */
108 * libtasn1_perror - prints a string to stderr with a description of an error
109 * @error: is an error returned by a libtasn1 function.
111 * This function is like perror(). The only difference is that it
112 * accepts an error returned by a libtasn1 function.
114 * Deprecated: Use asn1_perror() instead.
116 void
117 libtasn1_perror (asn1_retCode error)
119 asn1_perror (error);
123 * libtasn1_strerror - Returns a string with a description of an error
124 * @error: is an error returned by a libtasn1 function.
126 * This function is similar to strerror. The only difference is that
127 * it accepts an error (number) returned by a libtasn1 function.
129 * Returns: Pointer to static zero-terminated string describing error
130 * code.
132 * Deprecated: Use asn1_strerror() instead.
134 const char *
135 libtasn1_strerror (asn1_retCode error)
137 return asn1_strerror (error);
140 #endif