1 /* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */
2
3 #include "lib.h"
4 #include "execv-const.h"
5
6 #include <unistd.h>
7
argv_drop_const(const char * const argv[])8 static char **argv_drop_const(const char *const argv[])
9 {
10 char **ret;
11 unsigned int i, count;
12
13 for (count = 0; argv[count] != NULL; count++) ;
14
15 ret = t_new(char *, count + 1);
16 for (i = 0; i < count; i++)
17 ret[i] = t_strdup_noconst(argv[i]);
18 return ret;
19 }
20
execv_const(const char * path,const char * const argv[])21 void execv_const(const char *path, const char *const argv[])
22 {
23 (void)execv(path, argv_drop_const(argv));
24 i_fatal_status(errno == ENOMEM ? FATAL_OUTOFMEM : FATAL_EXEC,
25 "execv(%s) failed: %m", path);
26 }
27
execvp_const(const char * file,const char * const argv[])28 void execvp_const(const char *file, const char *const argv[])
29 {
30 (void)execvp(file, argv_drop_const(argv));
31 i_fatal_status(errno == ENOMEM ? FATAL_OUTOFMEM : FATAL_EXEC,
32 "execvp(%s) failed: %m", file);
33 }
34