ctpv/shell.c

32 lines
599 B
C
Raw Normal View History

#include <string.h>
#include "shell.h"
#include "error.h"
#include "gen/helpers.h"
/*
* Returns string with helpers.sh prepended
*
* User must call free()
*/
char *prepend_helpers(char *str, size_t len)
{
char *buf, *b;
2022-05-29 18:33:20 +02:00
size_t l, helpers_len = LEN(scr_helpers_sh) - 1;
2022-05-29 18:33:20 +02:00
if (!(buf = malloc(sizeof(*buf) * (helpers_len + len)))) {
PRINTINTERR(FUNCFAILED("malloc"), ERRNOS);
abort();
}
b = buf;
2022-05-29 18:33:20 +02:00
l = helpers_len;
memcpy(b, scr_helpers_sh, l * sizeof(*b));
2022-05-29 18:33:20 +02:00
b += l * sizeof(*str);
l = len;
memcpy(b, str, l * sizeof(*b));
return buf;
}