diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-01-24 20:33:39 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-01-24 20:33:39 +0100 |
commit | 92b309989c683067e0585c2fa77f999e24108805 (patch) | |
tree | ca8c85e2168724f33a92dca610c2c23b67637cba /src | |
parent | aa9f12ff8ea3fe215ef0a819cdd193e3088d9b86 (diff) |
Move arguments to git-grep into static array
Diffstat (limited to 'src')
-rw-r--r-- | src/grab.c | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -33,6 +33,8 @@ #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) +#define lengthof(a) (sizeof(a) / sizeof(*(a))) + #define die(...) err(EXIT_FAILURE, __VA_ARGS__) #define diex(...) errx(EXIT_FAILURE, __VA_ARGS__) #define warn(...) \ @@ -804,8 +806,13 @@ getfstream(int argc, char *argv[argc]) case -1: die("fork"); case 0:; - size_t len = argc + 6; + size_t len; char **args; + static const char *git_grep_args[] = { + "git", "grep", "--cached", "-Ilz", "", + }; + + len = argc + lengthof(git_grep_args) + 1; close(fds[FD_R]); if (dup2(fds[FD_W], STDOUT_FILENO) == -1) @@ -814,11 +821,7 @@ getfstream(int argc, char *argv[argc]) if (!(args = malloc(len * sizeof(char *)))) die("malloc"); - args[0] = "git"; - args[1] = "grep"; - args[2] = "--cached"; - args[3] = "-Ilz"; - args[4] = ""; + memcpy(args, git_grep_args, sizeof(git_grep_args)); memcpy(args + 5, argv, argc * sizeof(char *)); args[len - 1] = nullptr; |