sfm

simple file manager
git clone git://git.afify.dev/sfm
Log | Files | Refs | README | LICENSE

commit 20aa6eeed051846f2859ffe0cee9b8d9aa393175
parent fc58bc50bf165d2ed5efd1dd3ae2e9d4f5f2d4f3
Author: afify <hassan@afify.dev>
Date:   Tue, 25 May 2021 10:11:21 +0300

[ref] spawn use memcpy instead of for loops

- merge command array and files array with memcpy

Diffstat:
Msfm.c | 12+++---------
1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/sfm.c b/sfm.c @@ -1124,20 +1124,14 @@ spawn(const void *com_argv, size_t com_argc, const void *f_argv, size_t f_argc, char *fn) { int ws; - size_t i, argc, x; + size_t argc; pid_t pid, r; argc = com_argc + f_argc + 2; - x = com_argc; char *argv[argc]; - for (i = 0; i < com_argc; i++) /* get command */ - argv[i] = ((char **)com_argv)[i]; - - for (i = 0; i < f_argc; i++) { /* get files */ - argv[x] = ((char **)f_argv)[i]; - x++; - } + memcpy(argv, com_argv, com_argc * sizeof(char *)); /* command */ + memcpy(&argv[com_argc], f_argv, f_argc * sizeof(char *)); /* files */ argv[argc - 2] = fn; argv[argc - 1] = NULL;