kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit b3802d186d1b93f01dd25a2a6cf85d410c170701
parent f9e64ea5f06d9411fb6338468729ed9c24b5d140
Author: Alibek Omarov <a1ba.omarov@gmail.com>
Date:   Wed, 22 Mar 2023 15:14:33 +0300

kodev: split generating compiler commandline to separate function

args array is supposed to hold 34 + CFLAGS_MAX pointers and like the original
function lacks any checks

Diffstat:
src/cli.c | 26+++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/cli.c b/src/cli.c @@ -139,6 +139,8 @@ static char *cli_read_line(FILE *, char *, size_t); static long long cli_strtonum(const char *, long long, long long); static int cli_split_string(char *, const char *, char **, size_t); +static int cli_generate_compiler_args(char **, char **, struct cfile *); + static void usage(void) __attribute__((noreturn)); static void fatal(const char *, ...) __attribute__((noreturn)) __attribute__((format (printf, 1, 2))); @@ -1554,17 +1556,13 @@ cli_generate_certs(void) } #endif -static void -cli_compile_source_file(void *arg) +static int +cli_generate_compiler_args(char **compiler_out, char **args, struct cfile *cf) { - struct cfile *cf; int idx, i; char **flags; char *compiler; int flags_count; - char *args[34 + CFLAGS_MAX]; - - cf = arg; switch (cf->build) { case BUILD_C: @@ -1584,7 +1582,8 @@ cli_compile_source_file(void *arg) } idx = 0; - args[idx++] = compiler; + + *compiler_out = args[idx++] = compiler; for (i = 0; i < flags_count; i++) args[idx++] = flags[i]; @@ -1597,6 +1596,19 @@ cli_compile_source_file(void *arg) args[idx++] = cf->opath; args[idx] = NULL; + return idx; +} + +static void +cli_compile_source_file(void *arg) +{ + struct cfile *cf; + char *compiler; + char *args[34 + CFLAGS_MAX]; + + cf = arg; + cli_generate_compiler_args(&compiler, args, cf); + execvp(compiler, args); fatal("failed to start '%s': %s", compiler, errno_s); }