summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Murphy <tylerm@tylerm.dev>2023-05-01 18:53:44 -0400
committerTyler Murphy <tylerm@tylerm.dev>2023-05-01 18:53:44 -0400
commit14c7e194422e7a459189ed6d631a15835a2cbbb8 (patch)
treedf9c86e8272033219905ab6d2c4a837cfb511031
parentrefactor and xargs (diff)
downloadlazysphere-14c7e194422e7a459189ed6d631a15835a2cbbb8.tar.gz
lazysphere-14c7e194422e7a459189ed6d631a15835a2cbbb8.tar.bz2
lazysphere-14c7e194422e7a459189ed6d631a15835a2cbbb8.zip
use n flag in xargs
-rw-r--r--src/commands/xargs.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/commands/xargs.c b/src/commands/xargs.c
index 3b96bb6..01fb6ce 100644
--- a/src/commands/xargs.c
+++ b/src/commands/xargs.c
@@ -47,6 +47,7 @@ static int short_arg(char c, char* next) {
if (n < 1) {
error("error: max arg count must be at least 1");
}
+ flags.max_args = n;
return ARG_USED;
}
return ARG_UNUSED;
@@ -54,7 +55,7 @@ static int short_arg(char c, char* next) {
char* read_next(FILE* file, int arg_count) {
- if (arg_count == flags.max_args) return NULL;
+ if (flags.max_args != -1 && arg_count == flags.max_args) return NULL;
int size = 0;
int capacity = 8;
@@ -83,12 +84,14 @@ char* read_next(FILE* file, int arg_count) {
void read_args(FILE* file, char*** args, int* size, int* capacity) {
char* arg;
- while (arg = read_next(file, *size), true) {
+ static int read = 0;
+ while (arg = read_next(file, read), true) {
if (*size == *capacity) {
*capacity *= 2;
*args = realloc(*args, sizeof(char*) * *capacity);
}
(*args)[(*size)++] = arg;
+ read++;
if (arg == NULL) break;
}
}