summaryrefslogtreecommitdiff
path: root/src/strerrno.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/strerrno.h')
-rw-r--r--src/strerrno.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/strerrno.h b/src/strerrno.h
new file mode 100644
index 0000000..e000c86
--- /dev/null
+++ b/src/strerrno.h
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-3.0-only */
+#ifndef _STRERRNO_
+#define _STRERRNO_
+
+#include <libgen.h> /* basename() */
+
+/**
+ * strerrno() returns error message string corresponding to errno.
+ * strerrno() is thread safe.
+ */
+const char *strerrno(void);
+
+/**
+ * priv_set_err() sets an error message into a private buffer. This
+ * error message set by priv_set_err() can be accessed via
+ * priv_get_err(). priv_*_err functions are not thread safe.
+ */
+void priv_set_err(const char *fmt, ...);
+
+/**
+ * priv_set_errv(), a wrapper for priv_set_err(), just adds filename,
+ * line, and function name to the error message.
+ */
+#define priv_set_errv(fmt, ...) \
+ priv_set_err("[%s:%d:%s] " fmt "\0", \
+ basename(__FILE__), __LINE__, __func__, ##__VA_ARGS__)
+
+/**
+ * priv_get_err() gets the error message sotred in a private buffer.
+ */
+const char *priv_get_err();
+
+#endif /* _STRERRNO_ */