summaryrefslogtreecommitdiff
path: root/lib/errors.c
diff options
context:
space:
mode:
authorSimon Josefsson <simon@josefsson.org>2008-11-06 10:32:49 +0100
committerSimon Josefsson <simon@josefsson.org>2008-11-06 10:32:49 +0100
commitb1405c1bd8ca63ee7031e27b2e9b98613f2a1a6e (patch)
treeeb50320204ddbe45150e5c66b88e04d371e03da3 /lib/errors.c
parent927856fa3007e7b225a408878159f28968400cb4 (diff)
downloadlibtasn1-b1405c1bd8ca63ee7031e27b2e9b98613f2a1a6e.tar.gz
libtasn1-b1405c1bd8ca63ee7031e27b2e9b98613f2a1a6e.tar.bz2
libtasn1-b1405c1bd8ca63ee7031e27b2e9b98613f2a1a6e.zip
Fix error function namespace.
Diffstat (limited to 'lib/errors.c')
-rw-r--r--lib/errors.c120
1 files changed, 59 insertions, 61 deletions
diff --git a/lib/errors.c b/lib/errors.c
index 0d3e4a2..f4ed364 100644
--- a/lib/errors.c
+++ b/lib/errors.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006 Free Software Foundation, Inc.
+ * Copyright (C) 2006, 2008 Free Software Foundation, Inc.
* Copyright (C) 2002, 2005 Fabio Fiorina
*
* This file is part of LIBTASN1.
@@ -26,9 +26,7 @@
# include <stdarg.h>
#endif
-
-#define LIBTASN1_ERROR_ENTRY(name) \
- { #name, name }
+#define LIBTASN1_ERROR_ENTRY(name) { #name, name }
struct libtasn1_error_entry
{
@@ -59,77 +57,77 @@ static const libtasn1_error_entry error_algorithms[] = {
{0}
};
-#define LIBTASN1_ERROR_LOOP(b) \
- const libtasn1_error_entry *p; \
- for(p = error_algorithms; p->name != NULL; p++) { b ; }
-
-#define LIBTASN1_ERROR_ALG_LOOP(a) \
- LIBTASN1_ERROR_LOOP( if(p->number == error) { a; break; } )
-
-
-
/**
- * libtasn1_perror - prints a string to stderr with a description of an error
- * @error: is an error returned by a libtasn1 function.
- *
- * This function is like perror(). The only difference is that it
- * accepts an error returned by a libtasn1 function.
- **/
+ * asn1_perror - prints a string to stderr with a description of an error
+ * @error: is an error returned by a libtasn1 function.
+ *
+ * This function is like perror(). The only difference is that it
+ * accepts an error returned by a libtasn1 function.
+ *
+ * Since: 1.6
+ **/
void
-libtasn1_perror (asn1_retCode error)
+asn1_perror (asn1_retCode error)
{
- const char *ret = NULL;
-
- /* avoid prefix */
- LIBTASN1_ERROR_ALG_LOOP (ret = p->name + sizeof ("ASN1_") - 1);
-
- fprintf (stderr, "LIBTASN1 ERROR: %s\n", ret);
-
+ const char *str = asn1_strerror (error);
+ fprintf (stderr, "LIBTASN1 ERROR: %s\n", str ? str : "(null)");
}
-
/**
- * libtasn1_strerror - Returns a string with a description of an error
- * @error: is an error returned by a libtasn1 function.
- *
- * This function is similar to strerror(). The only difference is
- * that it accepts an error (number) returned by a libtasn1 function.
- *
- * Returns: Pointer to static zero-terminated string describing error
- * code.
- **/
+ * asn1_strerror - Returns a string with a description of an error
+ * @error: is an error returned by a libtasn1 function.
+ *
+ * This function is similar to strerror(). The only difference is
+ * that it accepts an error (number) returned by a libtasn1 function.
+ *
+ * Returns: Pointer to static zero-terminated string describing error
+ * code.
+ *
+ * Since: 1.6
+ **/
const char *
-libtasn1_strerror (asn1_retCode error)
+asn1_strerror (asn1_retCode error)
{
- const char *ret = NULL;
+ const libtasn1_error_entry *p;
- /* avoid prefix */
- LIBTASN1_ERROR_ALG_LOOP (ret = p->name + sizeof ("ASN1_") - 1);
+ for (p = error_algorithms; p->name != NULL; p++)
+ if (p->number == error)
+ return p->name + sizeof ("ASN1_") - 1;
- return ret;
+ return NULL;
}
-/* this function will output a message.
- */
-#ifdef LIBTASN1_DEBUG
+/* Compatibility mappings to preserve ABI. */
+
+/**
+ * libtasn1_perror - prints a string to stderr with a description of an error
+ * @error: is an error returned by a libtasn1 function.
+ *
+ * This function is like perror(). The only difference is that it
+ * accepts an error returned by a libtasn1 function.
+ *
+ * Deprecated: Use asn1_perror() instead.
+ **/
void
-_libtasn1_log (const char *fmt, ...)
+libtasn1_perror (asn1_retCode error)
{
- va_list args;
- char str[MAX_LOG_SIZE];
-
- va_start (args, fmt);
- vsprintf (str, fmt, args); /* Flawfinder: ignore */
- va_end (args);
-
- fprintf (stderr, str);
-
- return;
+ asn1_perror (error);
}
-#else /* not DEBUG */
-void
-_libtasn1_log (const char *fmt, ...)
+
+/**
+ * libtasn1_strerror - Returns a string with a description of an error
+ * @error: is an error returned by a libtasn1 function.
+ *
+ * This function is similar to strerror(). The only difference is
+ * that it accepts an error (number) returned by a libtasn1 function.
+ *
+ * Returns: Pointer to static zero-terminated string describing error
+ * code.
+ *
+ * Deprecated: Use asn1_strerror() instead.
+ **/
+const char *
+libtasn1_strerror (asn1_retCode error)
{
- return;
+ return asn1_strerror (error);
}
-#endif /* DEBUG */