aboutsummaryrefslogtreecommitdiffstats
path: root/src/u_utils.c
diff options
context:
space:
mode:
authorjozan <jozan@noemail.net>2020-11-06 03:12:33 +0000
committerjozan <jozan@noemail.net>2020-11-06 03:12:33 +0000
commit77084d56e34887fe1b19f7ba9a9a5b2508af89e3 (patch)
treecb8539c202debf2f4ada5ddb53a28a55b6552510 /src/u_utils.c
parentFreed some leaks, work in progress (diff)
downloadunixize-77084d56e34887fe1b19f7ba9a9a5b2508af89e3.tar.gz
unixize-77084d56e34887fe1b19f7ba9a9a5b2508af89e3.tar.bz2
unixize-77084d56e34887fe1b19f7ba9a9a5b2508af89e3.tar.xz
unixize-77084d56e34887fe1b19f7ba9a9a5b2508af89e3.tar.zst
unixize-77084d56e34887fe1b19f7ba9a9a5b2508af89e3.zip
Must reparse options
FossilOrigin-Name: 7a4169603246baa42e24eca59517253be703abdaf3eeac79829e4e8db0341506
Diffstat (limited to 'src/u_utils.c')
-rw-r--r--src/u_utils.c61
1 files changed, 31 insertions, 30 deletions
diff --git a/src/u_utils.c b/src/u_utils.c
index 4af6579..4c1a9ed 100644
--- a/src/u_utils.c
+++ b/src/u_utils.c
@@ -79,6 +79,19 @@ u_dump_errno_path(const char path[])
);
}
+void
+u_del_nargv(char** nargv)
+{
+ char** ptr;
+
+ ptr = nargv;
+ while (*ptr != NULL) {
+ u_memdel((void*)&nargv[ptr - nargv]);
+ ptr++;
+ }
+ u_memdel((void*)&nargv);
+}
+
static char
u_get_extra_args(char args[], struct opts_s* opts)
{
@@ -112,19 +125,6 @@ u_get_extra_args(char args[], struct opts_s* opts)
return (i);
}
-static void
-u_del_nargv(char** nargv)
-{
- char** ptr;
-
- ptr = nargv;
- while (*ptr != NULL) {
- u_memdel((void*)&nargv[ptr - nargv]);
- ptr++;
- }
- u_memdel((void*)&nargv);
-}
-
char**
u_get_nargv(struct opts_s* opts)
{
@@ -134,12 +134,12 @@ u_get_nargv(struct opts_s* opts)
char* tok;
i = u_get_extra_args(args, opts) + 2;
- nargv = (char**)malloc((i + 1) * sizeof(char*));
+ nargv = (char**)malloc((i + 2) * sizeof(char*));
if (nargv == NULL) {
u_dump_errno();
return (NULL);
}
- nargv[0] = strdup("unixize");
+ nargv[0] = strdup("r");
nargv[1] = NULL;
if (nargv[0] == NULL) {
u_memdel((void*)&nargv);
@@ -152,24 +152,25 @@ u_get_nargv(struct opts_s* opts)
u_memdel((void*)&nargv);
return (NULL);
}
- if (i > 2) {
- tok = strtok(args, ":");
- nargv[3] = strdup(tok);
- if (nargv[3] == NULL) {
+ if (i <= 3) {
+ return (nargv);
+ }
+ tok = strtok(args, ":");
+ nargv[2] = strdup(tok);
+ if (nargv[2] == NULL) {
+ u_del_nargv(nargv);
+ return (NULL);
+ }
+ nargv[3] = NULL;
+ i = 3;
+ while ((tok = strtok(NULL, ":")) != NULL) {
+ nargv[i] = strdup(tok);
+ if (nargv[i] == NULL) {
u_del_nargv(nargv);
return (NULL);
}
- nargv[4] = NULL;
- i = 4;
- while ((tok = strtok(NULL, ":")) != NULL) {
- nargv[i] = strdup(tok);
- if (nargv[i] != NULL) {
- u_del_nargv(nargv);
- return (NULL);
- }
- nargv[i + 1] = NULL;
- i++;
- }
+ nargv[i + 1] = NULL;
+ i++;
}
return (nargv);
}