aboutsummaryrefslogtreecommitdiffstats
path: root/src/libgamma-error.c.gpp
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-05-31 06:19:28 +0200
committerMattias Andrée <maandree@operamail.com>2014-05-31 06:19:28 +0200
commit01c8a8d3c1f621c56a704308037ee1b013e2eb7e (patch)
treedbbb949066c93ae9f000aa5c95cb85d13463fee2 /src/libgamma-error.c.gpp
parentinfo: doc libgamma_name_of_error and libgamma_value_of_error (diff)
downloadlibgamma-01c8a8d3c1f621c56a704308037ee1b013e2eb7e.tar.gz
libgamma-01c8a8d3c1f621c56a704308037ee1b013e2eb7e.tar.bz2
libgamma-01c8a8d3c1f621c56a704308037ee1b013e2eb7e.tar.xz
add libgamma_perror
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/libgamma-error.c.gpp')
-rw-r--r--src/libgamma-error.c.gpp45
1 files changed, 39 insertions, 6 deletions
diff --git a/src/libgamma-error.c.gpp b/src/libgamma-error.c.gpp
index 93f8542..916e387 100644
--- a/src/libgamma-error.c.gpp
+++ b/src/libgamma-error.c.gpp
@@ -22,6 +22,14 @@
#include <stddef.h>
#include <sys/types.h>
#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+
+
+
+£>set -u
+£>cd info
+£>export PATH=".:${PATH}"
@@ -38,13 +46,38 @@ const char* libgamma_group_name = NULL;
-£>set -u
-£>cd info
-£>export PATH=".:${PATH}"
+/**
+ * Prints an error to stderr in a `perror` fashion,
+ * however this function will not translate the `libgamma`
+ * errors into human-readable strings, it will simply
+ * print the name of the error. If the value `error_code`
+ * is the value of `LIBGAMMA_ERRNO_SET`, `perror` will be
+ * used to print the current error stored in `errno`.
+ * If `value` is non-negative (a `errno` value`), that
+ * value will be stored in `errno` and `perror` will be
+ * used to print it.
+ *
+ * @param name The text to add at the beginning.
+ * @param value The error code, may be an `errno` value.
+ */
+void libgamma_perror(const char* name, int error_code)
+{
+ if (error_code >= 0)
+ {
+ errno = error_code;
+ perror(name);
+ }
+ else if (error_code == LIBGAMMA_ERRNO_SET)
+ perror(name);
+ else if (error_code < LIBGAMMA_ERROR_MIN)
+ fprintf(stderr, "%s: (?)\n", name);
+ else
+ fprintf(stderr, "%s: %s\n", name, libgamma_name_of_error(error_code));
+}
/**
- * Returns the name of the definition associated with a libgamma error code.
+ * Returns the name of the definition associated with a `libgamma` error code.
*
* @param value The error code.
* @return The name of the definition associated with the error code,
@@ -68,11 +101,11 @@ const char* libgamma_name_of_error(int value)
/**
- * Return the value of a libgamma error definition refered to by name.
+ * Return the value of a `libgamma` error definition refered to by name.
*
* @param name The name of the definition associated with the error code.
* @return The error code, zero if the name does is `NULL`
- * or does not refer to an libgamma error.
+ * or does not refer to a `libgamma` error.
*/
int libgamma_value_of_error(const char* name)
{