summaryrefslogtreecommitdiff
path: root/src/print.h
diff options
context:
space:
mode:
authorRyo Nakamura <upa@haeena.net>2024-02-06 21:54:04 +0900
committerRyo Nakamura <upa@haeena.net>2024-02-06 21:54:04 +0900
commit4f0669f8f86acb09f10ffb5af273f86d8d6ddd34 (patch)
tree65d5d0adfd90e31b77474993addeb065edfeb75c /src/print.h
parent76892a69f95f7dcf47050800385bc610f8ccf5f3 (diff)
refactor error message-related functions
split message print fuctions (mpr_*), strerrno, and mscp_get/set_error into print.c/h and strerrno.c/h. ToDo: revise usages of priv_set_errv and pr_* functions.
Diffstat (limited to 'src/print.h')
-rw-r--r--src/print.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/print.h b/src/print.h
new file mode 100644
index 0000000..c0b3359
--- /dev/null
+++ b/src/print.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-3.0-only */
+#ifndef _PRINT_H_
+#define _PRINT_H_
+
+#include <libgen.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+#include <mscp.h>
+
+/* message print. printed messages are passed to application via msg_fd */
+void set_print_severity(int severity);
+int get_print_severity();
+
+#define __print(fp, severity, fmt, ...) \
+ do { \
+ if (severity <= get_print_severity()) { \
+ fprintf(fp, "\r\033[K" fmt "\n", ##__VA_ARGS__); \
+ fflush(fp); \
+ } \
+ } while (0)
+
+#define pr_err(fmt, ...) \
+ __print(stderr, MSCP_SEVERITY_ERR, fmt, ##__VA_ARGS__)
+#define pr_warn(fmt, ...) \
+ __print(stderr, MSCP_SEVERITY_WARN, fmt, ##__VA_ARGS__)
+#define pr_notice(fmt, ...) \
+ __print(stdout, MSCP_SEVERITY_NOTICE, fmt, ##__VA_ARGS__)
+#define pr_info(fmt, ...) \
+ __print(stdout, MSCP_SEVERITY_INFO, fmt, ##__VA_ARGS__)
+#define pr_debug(fmt, ...) \
+ __print(stdout, MSCP_SEVERITY_DEBUG, fmt, ##__VA_ARGS__)
+
+#endif /* _PRINT_H_ */