summaryrefslogtreecommitdiffhomepage
path: root/src/internal/argv
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2024-01-26 14:46:15 +0000
committermidipix <writeonce@midipix.org>2024-01-26 14:48:00 +0000
commit1d74f38b2ac5e0e6717b312acd3efc404c16d4e8 (patch)
tree133b2fc400acfe6904c01cbb6587b9143e8bf3e3 /src/internal/argv
parenta89706525f82ea623bc9e8f0f258e20344d3dd83 (diff)
downloadtpax-1d74f38b2ac5e0e6717b312acd3efc404c16d4e8.tar.bz2
tpax-1d74f38b2ac5e0e6717b312acd3efc404c16d4e8.tar.xz
argv.h: argv_show_error: refactor handling of vendor-specific option string.
Diffstat (limited to 'src/internal/argv')
-rw-r--r--src/internal/argv/argv.h29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/internal/argv/argv.h b/src/internal/argv/argv.h
index 79b0249..cbd2343 100644
--- a/src/internal/argv/argv.h
+++ b/src/internal/argv/argv.h
@@ -536,10 +536,11 @@ static const char * argv_program_name(const char * program_path)
static void argv_show_error(int fd, struct argv_ctx * ctx)
{
- char * ch;
- char * cap;
- char opt_vendor_buf[256];
- char opt_short_name[2] = {0,0};
+ const char * src;
+ char * dst;
+ char * cap;
+ char opt_vendor_buf[256];
+ char opt_short_name[2] = {0,0};
if (ctx->erropt && ctx->erropt->short_name)
opt_short_name[0] = ctx->erropt->short_name;
@@ -556,14 +557,22 @@ static void argv_show_error(int fd, struct argv_ctx * ctx)
break;
case ARGV_ERROR_VENDOR_OPTION:
- memset(opt_vendor_buf,0,sizeof(opt_vendor_buf));
- strncpy(opt_vendor_buf,ctx->errch,sizeof(opt_vendor_buf) - 1);
-
+ src = ctx->errch;
+ dst = opt_vendor_buf;
cap = &opt_vendor_buf[sizeof(opt_vendor_buf)];
- for (ch=opt_vendor_buf; ch && *ch && ch<cap; ch++)
- if ((*ch == '=') || (*ch == ',') || (*ch == ':'))
- *ch = '\0';
+ for (; src && *src && dst<cap; ) {
+ if ((*src == '=') || (*src == ',') || (*src == ':')) {
+ src = 0;
+ } else {
+ *dst++ = *src++;
+ }
+ }
+
+ if (dst == cap)
+ dst--;
+
+ *dst = '\0';
argv_dprintf(fd,"'-%s' is not a valid vendor option\n",opt_vendor_buf);
break;