summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2024-07-18 06:57:32 +0000
committermidipix <writeonce@midipix.org>2024-07-18 06:57:32 +0000
commitf18eb49fd10d21c6f1c0fa37d3a61a54bf6d9d97 (patch)
tree5d55aae84d6e321413d9a489f4f797f815de56ee
parent57abba86083cd65d73e0df3bc12bd9560c178f21 (diff)
downloadtpax-main.tar.bz2
tpax-main.tar.xz
driver: refactor the strerror() logic.HEADmain
-rw-r--r--src/driver/tpax_driver_ctx.c51
1 files changed, 22 insertions, 29 deletions
diff --git a/src/driver/tpax_driver_ctx.c b/src/driver/tpax_driver_ctx.c
index 4348ebc..b7b949e 100644
--- a/src/driver/tpax_driver_ctx.c
+++ b/src/driver/tpax_driver_ctx.c
@@ -55,6 +55,9 @@ static const struct tpax_fd_ctx tpax_default_fdctx = {
.fdlog = (-1),
};
+/* fallback error description */
+static const char tpax_null_errdesc[] = "<no error description>";
+
struct tpax_driver_ctx_alloc {
struct argv_meta * meta;
struct tpax_driver_ctx_impl ctx;
@@ -78,6 +81,21 @@ static uint32_t tpax_argv_flags(uint32_t flags)
return ret;
}
+static const char * tpax_driver_errdesc(void)
+{
+ int lerrno;
+ const char * errstr;
+
+ lerrno = errno;
+ errno = 0;
+
+ errstr = strerror(lerrno);
+ errstr = errno ? tpax_null_errdesc : errstr;
+ errno = lerrno;
+
+ return errstr;
+}
+
static int tpax_driver_usage(
int fdout,
const char * program,
@@ -173,8 +191,7 @@ static int tpax_driver_usage_copy_mode(
break;
default:
- if (!(errdesc = strerror(errno)))
- errdesc = "<no error description>";
+ errdesc = tpax_driver_errdesc();
tpax_dprintf(
fdout,
@@ -263,15 +280,7 @@ static int tpax_driver_error_archive_path(
struct argv_meta * meta,
bool fwrite)
{
- int lerrno;
- const char * errstr;
-
- lerrno = errno;
- errno = 0;
-
- errstr = strerror(lerrno);
- errstr = errno ? "" : errstr;
- errno = lerrno;
+ const char * errstr = tpax_driver_errdesc();
if (fwrite) {
tpax_dprintf(
@@ -584,15 +593,7 @@ static int tpax_driver_srcstat_error(
const struct argv_entry * archive,
const char * program)
{
- int lerrno;
- const char * errstr;
-
- lerrno = errno;
- errno = 0;
-
- errstr = strerror(lerrno);
- errstr = errno ? "" : errstr;
- errno = lerrno;
+ const char * errstr = tpax_driver_errdesc();
if (archive) {
tpax_dprintf(
@@ -615,15 +616,7 @@ static int tpax_driver_cache_error(
struct tpax_driver_ctx_impl * ctx,
const char * program)
{
- int lerrno;
- const char * errstr;
-
- lerrno = errno;
- errno = 0;
-
- errstr = strerror(lerrno);
- errstr = errno ? tpax_null_errdesc : errstr;
- errno = lerrno;
+ const char * errstr = tpax_driver_errdesc();
tpax_dprintf(
ctx->fdctx.fderr,