From: Timo Sirainen Date: Fri, 26 Mar 2010 23:33:33 +0000 (+0200) Subject: Added execv_const() and execvp_const() helper functions. X-Git-Tag: 2.0.beta5~279 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=74179667f4325e7d7f5b49bc040741c6edc2dad2;p=thirdparty%2Fdovecot%2Fcore.git Added execv_const() and execvp_const() helper functions. --HG-- branch : HEAD --- diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 85b515d8ac..b916ad805b 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -24,6 +24,7 @@ liblib_la_SOURCES = \ data-stack.c \ eacces-error.c \ env-util.c \ + execv-const.c \ failures.c \ fd-close-on-exec.c \ fd-set-nonblock.c \ @@ -131,6 +132,7 @@ headers = \ data-stack.h \ eacces-error.h \ env-util.h \ + execv-const.h \ failures.h \ fd-close-on-exec.h \ fd-set-nonblock.h \ diff --git a/src/lib/execv-const.c b/src/lib/execv-const.c new file mode 100644 index 0000000000..c89dcb6415 --- /dev/null +++ b/src/lib/execv-const.c @@ -0,0 +1,20 @@ +/* Copyright (c) 2010 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "execv-const.h" + +#include + +void execv_const(const char *path, const char *const argv[]) +{ + (void)execv(path, (void *)argv); + i_fatal_status(errno == ENOMEM ? FATAL_OUTOFMEM : FATAL_EXEC, + "execv(%s) failed: %m", path); +} + +void execvp_const(const char *file, const char *const argv[]) +{ + (void)execvp(file, (void *)argv); + i_fatal_status(errno == ENOMEM ? FATAL_OUTOFMEM : FATAL_EXEC, + "execvp(%s) failed: %m", file); +} diff --git a/src/lib/execv-const.h b/src/lib/execv-const.h new file mode 100644 index 0000000000..f112ceca06 --- /dev/null +++ b/src/lib/execv-const.h @@ -0,0 +1,9 @@ +#ifndef EXECV_CONST_H +#define EXECV_CONST_H + +/* Just like execv() and execvp(), except argv points to const strings. + Also if calling execv*() fails, these functions call i_fatal(). */ +void execv_const(const char *path, const char *const argv[]) ATTR_NORETURN; +void execvp_const(const char *file, const char *const argv[]) ATTR_NORETURN; + +#endif