cleanup error message handling

The top-level funtion in a thread should print errors using
priv_get_err(), while lower-level functions should set error messages
using priv_set_err() except that error mesesages should be printed
immediately, e.g., under walk_src_path().
This commit is contained in:
Ryo Nakamura
2024-02-07 13:29:45 +09:00
parent 5119d5ae26
commit 96084004b6
6 changed files with 58 additions and 58 deletions

View File

@@ -18,20 +18,15 @@ const char *strerrno(void)
}
#define PRIV_ERR_BUFSIZ (1 << 12)
static char priv_err_buf[PRIV_ERR_BUFSIZ], internal[PRIV_ERR_BUFSIZ];
__thread char priv_err_buf[PRIV_ERR_BUFSIZ], internal[PRIV_ERR_BUFSIZ];
void priv_set_err(const char *fmt, ...)
{
va_list va;
/* arguments may contains priv_err_buf. Thus, we build the
* string in a internal buffer, and then copy it to
* priv_err_buf. */
memset(internal, 0, sizeof(internal));
va_start(va, fmt);
vsnprintf(internal, sizeof(internal), fmt, va);
va_end(va);
snprintf(priv_err_buf, sizeof(priv_err_buf), "%s", internal);
}