This commit is contained in:
Nikita Ivanov 2022-05-29 21:33:20 +05:00
parent d2f87bc22f
commit ee85f98008
No known key found for this signature in database
GPG Key ID: 6E656AC5B97B5133
2 changed files with 8 additions and 11 deletions

View File

@ -123,7 +123,7 @@ static int run(Preview *p, int *exitcode)
int sp_arg[] = { pipe_fds[0], pipe_fds[1], STDERR_FILENO };
char *script = prepend_helpers(p->script, p->script_len - 1);
char *script = prepend_helpers(p->script, p->script_len);
char *args[] = SHELL_ARGS(script);
int ret = spawn(args, NULL, exitcode, spawn_redirect, sp_arg);

17
shell.c
View File

@ -12,23 +12,20 @@
char *prepend_helpers(char *str, size_t len)
{
char *buf, *b;
size_t mlen;
size_t l, helpers_len = LEN(scr_helpers_sh) - 1;
if (!(buf = malloc(sizeof(*buf) * (LEN(scr_helpers_sh) + len)))) {
if (!(buf = malloc(sizeof(*buf) * (helpers_len + len)))) {
PRINTINTERR(FUNCFAILED("malloc"), ERRNOS);
abort();
}
b = buf;
mlen = LEN(scr_helpers_sh);
memcpy(b, scr_helpers_sh, mlen);
l = helpers_len;
memcpy(b, scr_helpers_sh, l * sizeof(*b));
b += (mlen - 1) * sizeof(*str);
mlen = len;
memcpy(b, str, mlen);
b += mlen * sizeof(*str);
b[0] = '\0';
b += l * sizeof(*str);
l = len;
memcpy(b, str, l * sizeof(*b));
return buf;
}