summaryrefslogtreecommitdiff
path: root/src/internal
diff options
context:
space:
mode:
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/argv/argv.h99
-rw-r--r--src/internal/tpax_dprintf_impl.c10
-rw-r--r--src/internal/tpax_driver_impl.h15
-rw-r--r--src/internal/tpax_errinfo_impl.c10
-rw-r--r--src/internal/tpax_errinfo_impl.h10
-rw-r--r--src/internal/tpax_getdents_impl.h10
-rw-r--r--src/internal/tpax_readlink_impl.h10
-rw-r--r--src/internal/tpax_tmpfile_impl.c32
8 files changed, 130 insertions, 66 deletions
diff --git a/src/internal/argv/argv.h b/src/internal/argv/argv.h
index 287ad5e..87c60d2 100644
--- a/src/internal/argv/argv.h
+++ b/src/internal/argv/argv.h
@@ -1,6 +1,6 @@
/****************************************************************************/
/* argv.h: a thread-safe argument vector parser and usage screen generator */
-/* Copyright (C) 2015--2021 Z. Gilboa */
+/* Copyright (C) 2015--2024 SysDeer Technologies, LLC */
/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
/****************************************************************************/
@@ -83,6 +83,7 @@ enum argv_error {
ARGV_ERROR_INTERNAL,
ARGV_ERROR_SHORT_OPTION,
ARGV_ERROR_LONG_OPTION,
+ ARGV_ERROR_VENDOR_OPTION,
ARGV_ERROR_OPTARG_NONE,
ARGV_ERROR_OPTARG_REQUIRED,
ARGV_ERROR_OPTARG_PARADIGM,
@@ -398,7 +399,11 @@ static void argv_scan(
fval = ch;
}
} else {
- ferr = ARGV_ERROR_SHORT_OPTION;
+ if ((ch == &parg[0][1]) && (ch[0] == 'W') && ch[1]) {
+ ferr = ARGV_ERROR_VENDOR_OPTION;
+ } else {
+ ferr = ARGV_ERROR_SHORT_OPTION;
+ }
}
} else if (!fnoscan && (fhybrid || is_long_option(ch))) {
@@ -413,49 +418,72 @@ static void argv_scan(
ch = *parg;
}
- if (fhybrid && !(option->flags & ARGV_OPTION_HYBRID_SWITCH))
+ /* now verify the proper setting of option values */
+ if (fhybrid && !(option->flags & ARGV_OPTION_HYBRID_SWITCH)) {
ferr = ARGV_ERROR_HYBRID_NONE;
- else if (!fhybrid && (option->flags & ARGV_OPTION_HYBRID_ONLY))
+
+ } else if (!fhybrid && (option->flags & ARGV_OPTION_HYBRID_ONLY)) {
ferr = ARGV_ERROR_HYBRID_ONLY;
- else if (option->optarg == ARGV_OPTARG_NONE) {
+
+ } else if (option->optarg == ARGV_OPTARG_NONE) {
if (val[0]) {
ferr = ARGV_ERROR_OPTARG_NONE;
ctx->errch = val + 1;
- } else
+ } else {
fval = false;
+ }
+
} else if (val[0] && (option->flags & ARGV_OPTION_HYBRID_JOINED)) {
fval = true;
ch = val;
- } else if (fhybrid && !val[0] && !(option->flags & ARGV_OPTION_HYBRID_SPACE))
- ferr = ARGV_ERROR_HYBRID_SPACE;
- else if (fhybrid && (val[0]=='=') && !(option->flags & ARGV_OPTION_HYBRID_EQUAL))
+
+ } else if (fhybrid && !val[0] && !(option->flags & ARGV_OPTION_HYBRID_SPACE)) {
+ if (option->optarg == ARGV_OPTARG_OPTIONAL) {
+ fval = false;
+
+ } else {
+ ferr = ARGV_ERROR_HYBRID_SPACE;
+ }
+
+ } else if (fhybrid && (val[0]=='=') && !(option->flags & ARGV_OPTION_HYBRID_EQUAL)) {
ferr = ARGV_ERROR_HYBRID_EQUAL;
- else if (fhybrid && (val[0]==',') && !(option->flags & ARGV_OPTION_HYBRID_COMMA))
+
+ } else if (fhybrid && (val[0]==',') && !(option->flags & ARGV_OPTION_HYBRID_COMMA)) {
ferr = ARGV_ERROR_HYBRID_COMMA;
- else if (!fhybrid && (val[0]==','))
+
+ } else if (!fhybrid && (val[0]==',')) {
ferr = ARGV_ERROR_HYBRID_COMMA;
- else if (val[0] && !val[1])
+
+ } else if (val[0] && !val[1]) {
ferr = ARGV_ERROR_OPTARG_REQUIRED;
- else if (val[0] && val[1]) {
+
+ } else if (val[0] && val[1]) {
fval = true;
ch = ++val;
+
} else if (option->optarg == ARGV_OPTARG_REQUIRED) {
- if (!val[0] && !*parg)
+ if (!val[0] && !*parg) {
ferr = ARGV_ERROR_OPTARG_REQUIRED;
- else if (*parg && is_short_option(*parg))
+
+ } else if (*parg && is_short_option(*parg)) {
ferr = ARGV_ERROR_OPTARG_REQUIRED;
- else if (*parg && is_long_option(*parg))
+
+ } else if (*parg && is_long_option(*parg)) {
ferr = ARGV_ERROR_OPTARG_REQUIRED;
- else if (*parg && is_last_option(*parg))
+
+ } else if (*parg && is_last_option(*parg)) {
ferr = ARGV_ERROR_OPTARG_REQUIRED;
- else
+
+ } else {
fval = true;
+ }
} else {
/* ARGV_OPTARG_OPTIONAL */
fval = val[0];
}
- } else
+ } else {
ferr = ARGV_ERROR_LONG_OPTION;
+ }
}
if (ferr == ARGV_ERROR_OK)
@@ -531,7 +559,11 @@ static const char * argv_program_name(const char * program_path)
static void argv_show_error(int fd, struct argv_ctx * ctx)
{
- 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;
@@ -547,6 +579,27 @@ static void argv_show_error(int fd, struct argv_ctx * ctx)
argv_dprintf(fd,"'--%s' is not a valid long option\n",ctx->errch);
break;
+ case ARGV_ERROR_VENDOR_OPTION:
+ src = ctx->errch;
+ dst = opt_vendor_buf;
+ cap = &opt_vendor_buf[sizeof(opt_vendor_buf)];
+
+ 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;
+
case ARGV_ERROR_OPTARG_NONE:
argv_dprintf(fd,"'%s' is not a valid option value for [%s%s%s%s%s] "
"(option values may not be specified)\n",
@@ -563,7 +616,9 @@ static void argv_show_error(int fd, struct argv_ctx * ctx)
opt_short_name[0] ? "-" : "",
opt_short_name,
opt_short_name[0] ? "," : "",
- ctx->erropt->long_name ? "--" : "",
+ ctx->erropt->long_name
+ ? (ctx->erropt->flags & ARGV_OPTION_HYBRID_ONLY) ? "-" : "--"
+ : "",
ctx->erropt->long_name,
ctx->erropt->paradigm ? "one of the following values:" : "a value",
ctx->erropt->paradigm ? "{" : "",
@@ -849,7 +904,7 @@ static void argv_usage_impl(
/* color */
if (fcolor) {
color = (color == ccyan) ? cblue : ccyan;
- argv_dprintf(fd,color);
+ argv_dprintf(fd,color,0);
}
/* description, using either paradigm or argname if applicable */
diff --git a/src/internal/tpax_dprintf_impl.c b/src/internal/tpax_dprintf_impl.c
index aa1936d..b8d2b0b 100644
--- a/src/internal/tpax_dprintf_impl.c
+++ b/src/internal/tpax_dprintf_impl.c
@@ -1,8 +1,8 @@
-/******************************************************/
-/* tpax: a topological pax implementation */
-/* Copyright (C) 2020--2021 Z. Gilboa */
-/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
-/******************************************************/
+/**************************************************************/
+/* tpax: a topological pax implementation */
+/* Copyright (C) 2020--2021 SysDeer Technologies, LLC */
+/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
+/**************************************************************/
#include <stdio.h>
#include <stdarg.h>
diff --git a/src/internal/tpax_driver_impl.h b/src/internal/tpax_driver_impl.h
index 48d3cf7..5fabb0a 100644
--- a/src/internal/tpax_driver_impl.h
+++ b/src/internal/tpax_driver_impl.h
@@ -1,8 +1,8 @@
-/******************************************************/
-/* tpax: a topological pax implementation */
-/* Copyright (C) 2020--2021 Z. Gilboa */
-/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
-/******************************************************/
+/**************************************************************/
+/* tpax: a topological pax implementation */
+/* Copyright (C) 2020--2021 SysDeer Technologies, LLC */
+/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
+/**************************************************************/
#ifndef TPAX_DRIVER_IMPL_H
#define TPAX_DRIVER_IMPL_H
@@ -84,10 +84,7 @@ struct tpax_unit_ctx_impl {
off_t dpos;
const char * link;
char linkbuf[1024];
- union {
- struct tpax_ustar_header uhdr;
- struct tpax_cpio_header chdr;
- } hdrbufs;
+ size_t hdrbuf[];
};
diff --git a/src/internal/tpax_errinfo_impl.c b/src/internal/tpax_errinfo_impl.c
index 50d7aec..5fd2247 100644
--- a/src/internal/tpax_errinfo_impl.c
+++ b/src/internal/tpax_errinfo_impl.c
@@ -1,8 +1,8 @@
-/******************************************************/
-/* tpax: a topological pax implementation */
-/* Copyright (C) 2020--2021 Z. Gilboa */
-/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
-/******************************************************/
+/**************************************************************/
+/* tpax: a topological pax implementation */
+/* Copyright (C) 2020--2021 SysDeer Technologies, LLC */
+/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
+/**************************************************************/
#include <tpax/tpax.h>
#include "tpax_driver_impl.h"
diff --git a/src/internal/tpax_errinfo_impl.h b/src/internal/tpax_errinfo_impl.h
index 2e884a1..99b416b 100644
--- a/src/internal/tpax_errinfo_impl.h
+++ b/src/internal/tpax_errinfo_impl.h
@@ -1,8 +1,8 @@
-/******************************************************/
-/* tpax: a topological pax implementation */
-/* Copyright (C) 2020--2021 Z. Gilboa */
-/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
-/******************************************************/
+/**************************************************************/
+/* tpax: a topological pax implementation */
+/* Copyright (C) 2020--2021 SysDeer Technologies, LLC */
+/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
+/**************************************************************/
#include <errno.h>
#include <tpax/tpax.h>
diff --git a/src/internal/tpax_getdents_impl.h b/src/internal/tpax_getdents_impl.h
index e4d0e2f..42b9da0 100644
--- a/src/internal/tpax_getdents_impl.h
+++ b/src/internal/tpax_getdents_impl.h
@@ -1,8 +1,8 @@
-/******************************************************/
-/* tpax: a topological pax implementation */
-/* Copyright (C) 2020--2021 Z. Gilboa */
-/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
-/******************************************************/
+/**************************************************************/
+/* tpax: a topological pax implementation */
+/* Copyright (C) 2020--2021 SysDeer Technologies, LLC */
+/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
+/**************************************************************/
#ifndef TPAX_GETDENTS_IMPL_H
#define TPAX_GETDENTS_IMPL_H
diff --git a/src/internal/tpax_readlink_impl.h b/src/internal/tpax_readlink_impl.h
index 67fe0c8..d6c5580 100644
--- a/src/internal/tpax_readlink_impl.h
+++ b/src/internal/tpax_readlink_impl.h
@@ -1,8 +1,8 @@
-/******************************************************/
-/* tpax: a topological pax implementation */
-/* Copyright (C) 2020--2021 Z. Gilboa */
-/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
-/******************************************************/
+/**************************************************************/
+/* tpax: a topological pax implementation */
+/* Copyright (C) 2020--2021 SysDeer Technologies, LLC */
+/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
+/**************************************************************/
#ifndef TPAX_READLINK_IMPL_H
#define TPAX_READLINK_IMPL_H
diff --git a/src/internal/tpax_tmpfile_impl.c b/src/internal/tpax_tmpfile_impl.c
index b4e115a..9dd9d40 100644
--- a/src/internal/tpax_tmpfile_impl.c
+++ b/src/internal/tpax_tmpfile_impl.c
@@ -1,16 +1,20 @@
-/******************************************************/
-/* tpax: a topological pax implementation */
-/* Copyright (C) 2020--2021 Z. Gilboa */
-/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
-/******************************************************/
+/**************************************************************/
+/* tpax: a topological pax implementation */
+/* Copyright (C) 2020--2021 SysDeer Technologies, LLC */
+/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
+/**************************************************************/
#define _GNU_SOURCE
+#include <time.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
+#include <inttypes.h>
+
+#define PPRIX64 "%"PRIx64
/* mkostemp might be guarded by non-standard macros */
/* unless HAVE_NO_MKOSTEMP, assume it is available */
@@ -54,8 +58,8 @@ static int tpax_mkostemp(char * tmplate)
int tpax_tmpfile(void)
{
int fd;
- unsigned seed;
- char tmplate[64];
+ void * addr;
+ char tmplate[128];
/* try with __fs_tmpfile() */
if ((fd = tpax_tmpfile_by_framework()) >= 0)
@@ -66,10 +70,18 @@ int tpax_tmpfile(void)
return fd;
/* fallback to mk{o}stemp */
- seed = getpid();
+ addr = tmplate;
memset(tmplate,0,sizeof(tmplate));
- snprintf(tmplate,sizeof(tmplate),"/tmp/tpax_%d_%d_%d_XXXXXXXXXXXX",
- getppid(),getpid(),rand_r(&seed));
+ snprintf(tmplate,sizeof(tmplate),
+ "/tmp/"
+ ".tpax.tmpfile"
+ ".time."PPRIX64
+ ".salt.%p"
+ ".pid.%d"
+ ".XXXXXXXXXXXX",
+ time(0),
+ addr,
+ getpid());
return tpax_mkostemp(tmplate);
}