summaryrefslogtreecommitdiff
path: root/src/strerrno.h
blob: c7d935d497b0626e2141370889f2d19269a86608 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* 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 thread-local private
 * buffer. This error message can be accessed via priv_get_err().
 *
 * The top-level function in a thread should print errors using
 * priv_get_err(), while lower-level functions should set error
 * messages using priv_set_err().
 */
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 the thread-local private buffer.
 */
const char *priv_get_err();

#endif /* _STRERRNO_ */