mirror of
https://github.com/upa/mscp.git
synced 2026-02-21 23:04:43 +08:00
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.
This commit is contained in:
35
src/print.h
Normal file
35
src/print.h
Normal file
@@ -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_ */
|
||||
Reference in New Issue
Block a user