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:
Ryo Nakamura
2024-02-06 21:54:04 +09:00
parent 76892a69f9
commit 4f0669f8f8
18 changed files with 268 additions and 292 deletions

33
src/strerrno.h Normal file
View File

@@ -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_ */