aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-05-05 17:56:50 +0200
committerMattias Andrée <maandree@kth.se>2024-05-05 17:59:12 +0200
commit924f443d62bfabf8761da31ed890791d5893463a (patch)
treeaa544535fca95a653844aea8d233b2450246d88a
parentFirst commit (diff)
downloadlibexec-924f443d62bfabf8761da31ed890791d5893463a.tar.gz
libexec-924f443d62bfabf8761da31ed890791d5893463a.tar.bz2
libexec-924f443d62bfabf8761da31ed890791d5893463a.tar.xz
Remove libexec_init_command, doc stuff, make functions inline, and fix a bug
libexec_init_command was a huge oversight, it cannot be used as it would set .library_version to the libraries version of LIBEXEC_VERSION rather than the application's; instead LIBEXEC_COMMAND_INIT should be used. Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--LIBEXEC_COMMAND_INIT.c (renamed from libexec_init_command.c)19
-rw-r--r--Makefile5
-rw-r--r--common.h6
-rw-r--r--libexec.h396
-rw-r--r--libexec_clear_environ.c2
-rw-r--r--libexec_construct_command.c11
-rw-r--r--libexec_getenv.c2
-rw-r--r--libexec_getenv_last.c2
-rw-r--r--libexec_input_text_copy.c10
-rw-r--r--libexec_input_text_gift.c10
-rw-r--r--libexec_open.c6
-rw-r--r--libexec_openat2.c2
-rw-r--r--libexec_pipe_commands.c11
-rw-r--r--libexec_pipe_commandsv.c13
-rw-r--r--libexec_pipe_commandsvn.c3
-rw-r--r--libexec_put_arguments.c13
-rw-r--r--libexec_putenv.c9
-rw-r--r--libexec_putenv_append.c10
-rw-r--r--libexec_putenv_noclobber.c10
-rw-r--r--libexec_putenv_noreplace.c10
-rw-r--r--libexec_putenv_prepend.c10
-rw-r--r--libexec_putenv_replace.c10
-rw-r--r--libexec_putenvf.c13
-rw-r--r--libexec_putenvf_append.c15
-rw-r--r--libexec_putenvf_noclobber.c15
-rw-r--r--libexec_putenvf_noreplace.c15
-rw-r--r--libexec_putenvf_prepend.c15
-rw-r--r--libexec_putenvf_replace.c15
-rw-r--r--libexec_run.c11
-rw-r--r--libexec_setenv.c2
-rw-r--r--libexec_setenv_append.c10
-rw-r--r--libexec_setenv_noclobber.c10
-rw-r--r--libexec_setenv_noreplace.c10
-rw-r--r--libexec_setenv_prepend.c10
-rw-r--r--libexec_setenv_replace.c10
-rw-r--r--libexec_setenvf.c13
-rw-r--r--libexec_setenvf_append.c15
-rw-r--r--libexec_setenvf_noclobber.c15
-rw-r--r--libexec_setenvf_noreplace.c15
-rw-r--r--libexec_setenvf_prepend.c15
-rw-r--r--libexec_setenvf_replace.c15
-rw-r--r--libexec_unsetenv.c2
-rw-r--r--libexec_vputenvf_append.c6
-rw-r--r--libexec_vputenvf_noclobber.c6
-rw-r--r--libexec_vputenvf_noreplace.c6
-rw-r--r--libexec_vputenvf_prepend.c6
-rw-r--r--libexec_vputenvf_replace.c6
-rw-r--r--libexec_vrun.c2
-rw-r--r--libexec_vsetenvf_append.c6
-rw-r--r--libexec_vsetenvf_noclobber.c6
-rw-r--r--libexec_vsetenvf_noreplace.c6
-rw-r--r--libexec_vsetenvf_prepend.c6
-rw-r--r--libexec_vsetenvf_replace.c6
53 files changed, 444 insertions, 429 deletions
diff --git a/libexec_init_command.c b/LIBEXEC_COMMAND_INIT.c
index c49af27..e211995 100644
--- a/libexec_init_command.c
+++ b/LIBEXEC_COMMAND_INIT.c
@@ -1,19 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include "common.h"
-#ifndef TEST
-
-
-void
-libexec_init_command(struct libexec_command *cmd)
-{
- if (!cmd)
- return;
-
- *cmd = LIBEXEC_COMMAND_INIT;
-}
-
-
-#else
+#ifdef TEST
int
@@ -22,7 +9,7 @@ main(void)
struct libexec_command cmd;
memset(&cmd, 127, sizeof(cmd));
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
ASSERT_EQ_INT(cmd.library_version, LIBEXEC_VERSION);
ASSERT_EQ_ENUM(cmd.exec_how, LIBEXEC_ALLOW_NAME);
@@ -34,8 +21,6 @@ main(void)
ASSERT_EQ_UINT(cmd.nplumings, 0);
ASSERT_IS_NULL(cmd.environ);
- libexec_init_command(NULL);
-
return 0;
}
diff --git a/Makefile b/Makefile
index d159bef..5b63d46 100644
--- a/Makefile
+++ b/Makefile
@@ -33,7 +33,6 @@ OBJ =\
libexec_get_documents.o\
libexec_getenv.o\
libexec_getenv_last.o\
- libexec_init_command.o\
libexec_input_data_copy.o\
libexec_input_data_gift.o\
libexec_input_text_copy.o\
@@ -105,8 +104,8 @@ HDR =\
common.h
LOBJ = $(OBJ:.o=.lo)
-TOBJ = $(OBJ:.o=.to)
-TEST = $(OBJ:.o=.test)
+TOBJ = $(OBJ:.o=.to) LIBEXEC_COMMAND_INIT.to
+TEST = $(TOBJ:.to=.test)
all: libexec.a libexec.$(LIBEXT) $(TEST)
diff --git a/common.h b/common.h
index 66a8ded..e2ac828 100644
--- a/common.h
+++ b/common.h
@@ -12,7 +12,11 @@
#include <string.h>
#include <unistd.h>
-#if !defined(__linux__)
+
+#if defined(__linux__)
+# define STRUCT_OPEN_HOW struct open_how
+#else
+# define STRUCT_OPEN_HOW void
int libexec_openat2(struct libexec_command *cmd, int fd, int dirfd, const char *file, void *how, size_t size);
#endif
diff --git a/libexec.h b/libexec.h
index 5f7b2d0..8492890 100644
--- a/libexec.h
+++ b/libexec.h
@@ -6,14 +6,16 @@
#if defined(__linux__)
# include <linux/openat2.h>
#endif
+#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
+#include <string.h>
-/* For internal use only { */
+/* For internal use only (may be removed in the future) { */
#if defined(__GNUC__)
# define LIBEXEC_PURE__ __attribute__((__pure__))
# define LIBEXEC_CONST__ __attribute__((__const__))
@@ -25,50 +27,228 @@
# define LIBEXEC_PRINTF__(FMTIDX)
# define LIBEXEC_VPRINTF__(FMTIDX)
#endif
+#define LIBEXEC_VA_IMPL__(LAST, FUNC, ...)\
+ int ret;\
+ va_list args;\
+ va_start(args, LAST);\
+ ret = FUNC(__VA_ARGS__, args);\
+ va_end(args);\
+ return ret
/* } */
+/**
+ * Used to specify which version of the library
+ * the application is compiled against, so that
+ * the library knowns the layout of structures
+ * that may be modified in future versions
+ *
+ * This is currently used for:
+ * - `struct libexec_command`
+ */
#define LIBEXEC_VERSION 0U
+/**
+ * Specifies how an element should be inserted
+ * into a list
+ *
+ * This is currently used for:
+ * - `libexec_putenv`
+ * - `libexec_putenvf`
+ * - `libexec_vputenvf`
+ * - `libexec_setenv`
+ * - `libexec_setenvf`
+ * - `libexec_vsetenvf`
+ */
enum libexec_insert_mode {
+ /**
+ * Append to list, but if the an element with the same
+ * key is used, replace the first occurrence of it
+ */
LIBEXEC_REPLACE, /* replace existing definition if any */
- LIBEXEC_NOREPLACE, /* do nothing if definition already exists */
- LIBEXEC_NOCLOBBER, /* fail if definition already exists an differs */
- LIBEXEC_APPEND, /* add, to end of list, even if definition already exists, but also keep old */
- LIBEXEC_PREPEND /* add, to beginning of list, even if definition already exists, but also keep old */
- /* Either LIBEXEC_APPEND or LIBEXEC_PREPEND is required to put something missing '=' in the environment */
-#define LIBEXEC_INSERT_MODE__COUNT__ 5
+
+ /**
+ * Append to list except if the an element with the same
+ * key is used, then do nothing
+ */
+ LIBEXEC_NOREPLACE,
+
+ /**
+ * Append to list except if the an element with the same
+ * key is used, then do nothing but indicate fail
+ */
+ LIBEXEC_NOCLOBBER,
+
+ /**
+ * Add to the end of the list regardless of whether
+ * there already is an element with the same key in he list
+ *
+ * If used in `libexec_putenv`, `libexec_putenvf`, or
+ * `libexec_vputenvf`, that function will accept the
+ * new element even if it doesn't use a key–value
+ * construction
+ */
+ LIBEXEC_APPEND,
+
+ /**
+ * Add to the beginning of the list regardless of whether
+ * there already is an element with the same key in he list
+ *
+ * If used in `libexec_putenv`, `libexec_putenvf`, or
+ * `libexec_vputenvf`, that function will accept the
+ * new element even if it doesn't use a key–value
+ * construction
+ */
+ LIBEXEC_PREPEND
+
+#define LIBEXEC_INSERT_MODE__COUNT__ 5 /* For internal use only (may be removed in the future) */
};
+
+/**
+ * Modification to command's set of file descriptors
+ */
enum libexec_pluming_type {
+ /**
+ * Perform an openat(3) call, and change the
+ * number of the new file descriptor to a
+ * desired number
+ */
LIBEXEC_PLUMING_OPENAT,
+
+ /**
+ * Perform an openat2(2) call, and change the
+ * number of the new file descriptor to a
+ * desired number
+ */
LIBEXEC_PLUMING_OPENAT2,
+
+ /**
+ * Close a specific file descriptor
+ */
LIBEXEC_PLUMING_CLOSE,
+
+ /**
+ * Perform an dup2(3) call to duplicate
+ * a file descriptor
+ */
LIBEXEC_PLUMING_DUP2,
+
+ /**
+ * Pass text from the application's memory
+ * into the child process via a pipe, whose
+ * read-end will have a selected number;
+ * the write-end will not be exposed to the
+ * child process
+ */
LIBEXEC_PLUMING_DOCUMENT,
+
+ /**
+ * Expose a file descriptor from the application
+ * using a selected file descriptor number
+ *
+ * Note that unless a file descriptor from the
+ * application is explicitly close it will
+ * still be exposed to the child process; this
+ * merely changes the file descriptor number
+ */
LIBEXEC_PLUMING_PIPE
-#define LIBEXEC_PLUMING_TYPE__COUNT__ 6
+
+#define LIBEXEC_PLUMING_TYPE__COUNT__ 6 /* For internal use only (may be removed in the future) */
};
+
+/**
+ * Specifies how two commands shall be connected
+ *
+ * The value should be `LIBEXEC_PIPE`, `LIBEXEC_SOCK_STREAM`,
+ * `LIBEXEC_SOCK_SEQPACKET`, `LIBEXEC_SOCK_DGRAM, or
+ * `LIBEXEC_DIRECT_PIPE`, optionally OR'ed with
+ * `LIBEXEC_PIPE_CIRCULARLY`
+ */
enum libexec_pipe {
+ /**
+ * Use a normal pipe(7) to connect the two commands
+ */
LIBEXEC_PIPE = 0,
+
+ /**
+ * Use a unix(7) socketpair(3) with the type `SOCK_STREAM`
+ */
LIBEXEC_SOCK_STREAM = 1,
+
+ /**
+ * Use a unix(7) socketpair(3) with the type `SOCK_SEQPACKET`
+ */
LIBEXEC_SOCK_SEQPACKET = 2,
+
+ /**
+ * Use a unix(7) socketpair(3) with the type `SOCK_DGRAM`
+ */
LIBEXEC_SOCK_DGRAM = 3,
+
+ /**
+ * Use a pipe(7) created with `O_DIRECT` (see pipe2(2))
+ * to connect the two commands
+ */
LIBEXEC_DIRECT_PIPE = 4,
+
+ /**
+ * Pipe the standard output of the last command to
+ * the standard input of the first command, in addition
+ * to piping the standard output of each command to
+ * the standard input of the next command
+ */
LIBEXEC_PIPE_CIRCULARLY = 0x8000
-#define LIBEXEC_PIPE__COUNT__ 5
+
+#define LIBEXEC_PIPE__COUNT__ 5 /* For internal use only (may be removed in the future) */
};
+
+/**
+ * Specifies which exec(3) function should be used
+ */
enum libexec_locate_method {
+ /**
+ * p-class exec(3) function shall be used,
+ * that is, the executable may either be
+ * a relative or absolute path, but it may
+ * also be the name of a program that can
+ * be found in PATH. PATH is used, if and
+ * only if, the specified executable contains
+ * a slash
+ */
LIBEXEC_ALLOW_NAME,
+
+ /**
+ * non-p-class exec(3) function shall be used,
+ * that is, the executable must be a relative
+ * or absolute path
+ */
LIBEXEC_REQUIRE_PATH,
+
+ /**
+ * f-class exec(3) function shall be used,
+ * that is, a file descriptor to the executable
+ * is used
+ */
LIBEXEC_EXEC_FD,
+
+ /**
+ * at-class exec(3) function shall be used,
+ * that is, a function like execveat(2),
+ * where the executable is specified via
+ * a directory file descriptor (or `AT_FDCWD`)
+ * paired with a pathname, and AT_-flags,
+ * is used
+ */
LIBEXEC_EXEC_AT
-#define LIBEXEC_LOCATE_METHOD__COUNT__ 4
+
+#define LIBEXEC_LOCATE_METHOD__COUNT__ 4 /* For internal use only (may be removed in the future) */
};
+
enum libexec_run_instruction {
LIBEXEC_RUN_END, /* required to mark end if arguments for libexec_run */
LIBEXEC_RUN_END_CIRCULAR_PIPE, /* alternative to LIBEXEC_RUN_END */
@@ -101,7 +281,7 @@ enum libexec_run_instruction {
LIBEXEC_RUN_SET_ATFORK, /* ditto */
LIBEXEC_RUN_SET_MUTEX, /* ditto */
LIBEXEC_RUN_SET_INTERRUPT_CALLBACK /* ditto */
-#define LIBEXEC_RUN_INSTRUCTION__COUNT__ 31
+#define LIBEXEC_RUN_INSTRUCTION__COUNT__ 31 /* For internal use only (may be removed in the future) */
};
#define LIBEXEC_RUN_END() LIBEXEC_RUN_END
#define LIBEXEC_RUN_END_CIRCULAR_PIPE(TYPE) LIBEXEC_RUN_END_CIRCULAR_PIPE, TYPE
@@ -177,8 +357,6 @@ struct libexec_pluming {
} target;
};
-#define LIBEXEC_COMMAND_INIT\
- ((struct libexec_command){LIBEXEC_VERSION, LIBEXEC_ALLOW_NAME, -1, NULL, NULL, 0, NULL, 0, NULL})
struct libexec_command {
unsigned library_version;
enum libexec_locate_method exec_how;
@@ -209,24 +387,38 @@ struct libexec_result {
};
-void libexec_init_command(struct libexec_command *cmd);
+#define LIBEXEC_COMMAND_INIT\
+ ((struct libexec_command){LIBEXEC_VERSION, LIBEXEC_ALLOW_NAME, -1, NULL, NULL, 0, NULL, 0, NULL})
+
void libexec_destroy_command(struct libexec_command *cmd);
void libexec_destroy_pluming(struct libexec_pluming *pluming);
int libexec_destroy_document(struct libexec_document *doc);
void libexec_destroy_result(struct libexec_result *result);
int libexec_vconstruct_command(struct libexec_command *cmd, const char *fmt, va_list args);
-int libexec_construct_command(struct libexec_command *cmd, const char *fmt, ...);
+inline int libexec_construct_command(struct libexec_command *cmd, const char *fmt, ...)
+{ LIBEXEC_VA_IMPL__(fmt, libexec_vconstruct_command, cmd, fmt); }
int libexec_put_argumentsn(struct libexec_command *cmd, const char *const *args, size_t nargs);
-int libexec_put_arguments(struct libexec_command *cmd, const char *const *args);
+inline int libexec_put_arguments(struct libexec_command *cmd, const char *const *args)
+{
+ size_t n = 0;
+ if (!args) {
+ errno = EINVAL;
+ return -1;
+ }
+ while (args[n])
+ n += 1;
+ return libexec_put_argumentsn(cmd, args, n);
+}
int libexec_set_executable(struct libexec_command *cmd, const char *executable /* NULL = use first argument in command */);
void libexec_set_require_path(struct libexec_command *cmd, int require);
int libexec_set_exec_fd(struct libexec_command *cmd, int fd);
int libexec_set_exec_path(struct libexec_command *cmd, int dirfd, const char *path /* NULL = use first argument in command */);
int libexec_add_pluming(struct libexec_command *cmd, const struct libexec_pluming *pluming);
-int libexec_open(struct libexec_command *cmd, int fd, const char *file, int flags, mode_t mode);
int libexec_openat(struct libexec_command *cmd, int fd, int dirfd, const char *file, int flags, mode_t mode);
+inline int libexec_open(struct libexec_command *cmd, int fd, const char *file, int flags, mode_t mode)
+{ return libexec_openat(cmd, fd, AT_FDCWD, file, flags, mode); }
#if defined(__linux__)
int libexec_openat2(struct libexec_command *cmd, int fd, int dirfd, const char *file, struct open_how *how, size_t size);
#endif
@@ -235,8 +427,22 @@ int libexec_close(struct libexec_command *cmd, int fd);
int libexec_renumber_fd(struct libexec_command *cmd, int fd, int old_fd);
int libexec_input_data_copy(struct libexec_command *cmd, int fd, const char *data, size_t len);
int libexec_input_data_gift(struct libexec_command *cmd, int fd, char *data, size_t len);
-int libexec_input_text_copy(struct libexec_command *cmd, int fd, const char *text);
-int libexec_input_text_gift(struct libexec_command *cmd, int fd, char *text);
+inline int libexec_input_text_copy(struct libexec_command *cmd, int fd, const char *text)
+{
+ if (!text) {
+ errno = EINVAL;
+ return -1;
+ }
+ return libexec_input_data_copy(cmd, fd, text, strlen(text));
+}
+inline int libexec_input_text_gift(struct libexec_command *cmd, int fd, char *text)
+{
+ if (!text) {
+ errno = EINVAL;
+ return -1;
+ }
+ return libexec_input_data_gift(cmd, fd, text, strlen(text));
+}
int libexec_add_output_fd(struct libexec_command *cmd, int fd, int wr_fd);
int libexec_add_output_document(struct libexec_command *cmd, int fd, struct libexec_document *doc /* .fd will be set */, int flags);
@@ -516,7 +722,9 @@ LIBEXEC_VPRINTF__(3) int libexec_vputenvf(struct libexec_command *, enum libexec
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_PRINTF__(3) int libexec_putenvf(struct libexec_command *, enum libexec_insert_mode, const char *, ...);
+LIBEXEC_PRINTF__(3) inline int
+libexec_putenvf(struct libexec_command *cmd, enum libexec_insert_mode how, const char *fmt, ...)
+{ LIBEXEC_VA_IMPL__(fmt, libexec_vputenvf, cmd, how, fmt); }
/**
* Put an environment variable into a command's environment
@@ -633,7 +841,9 @@ LIBEXEC_VPRINTF__(4) int libexec_vsetenvf(struct libexec_command *, enum libexec
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_PRINTF__(4) int libexec_setenvf(struct libexec_command *, enum libexec_insert_mode, const char *, const char *, ...);
+LIBEXEC_PRINTF__(4) inline int
+libexec_setenvf(struct libexec_command *cmd, enum libexec_insert_mode how, const char *name, const char *value_fmt, ...)
+{ LIBEXEC_VA_IMPL__(value_fmt, libexec_vsetenvf, cmd, how, name, value_fmt); }
/**
@@ -657,7 +867,9 @@ LIBEXEC_PRINTF__(4) int libexec_setenvf(struct libexec_command *, enum libexec_i
* @throws EINVAL Invalid argument input
* @throws ENOMEM Failed to allocate enough memory to modify the command's environment
*/
-int libexec_putenv_replace(struct libexec_command *, const char *);
+inline int
+libexec_putenv_replace(struct libexec_command *cmd, const char *string)
+{ return libexec_putenv(cmd, LIBEXEC_REPLACE, string); }
/**
* Put an environment variable into a command's environment,
@@ -685,7 +897,9 @@ int libexec_putenv_replace(struct libexec_command *, const char *);
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_VPRINTF__(2) int libexec_vputenvf_replace(struct libexec_command *, const char *, va_list);
+LIBEXEC_VPRINTF__(2) inline int
+libexec_vputenvf_replace(struct libexec_command *cmd, const char *fmt, va_list args)
+{ return libexec_vputenvf(cmd, LIBEXEC_REPLACE, fmt, args); }
/**
* Put an environment variable into a command's environment,
@@ -713,7 +927,9 @@ LIBEXEC_VPRINTF__(2) int libexec_vputenvf_replace(struct libexec_command *, cons
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_PRINTF__(2) int libexec_putenvf_replace(struct libexec_command *, const char *, ...);
+LIBEXEC_PRINTF__(2) inline int
+libexec_putenvf_replace(struct libexec_command *cmd, const char *fmt, ...)
+{ LIBEXEC_VA_IMPL__(fmt, libexec_vputenvf_replace, cmd, fmt); }
/**
* Put an environment variable into a command's environment,
@@ -737,7 +953,9 @@ LIBEXEC_PRINTF__(2) int libexec_putenvf_replace(struct libexec_command *, const
* @throws EINVAL Invalid argument input
* @throws ENOMEM Failed to allocate enough memory to modify the command's environment
*/
-int libexec_setenv_replace(struct libexec_command *, const char *, const char *);
+inline int
+libexec_setenv_replace(struct libexec_command *cmd, const char *name, const char *value)
+{ return libexec_setenv(cmd, LIBEXEC_REPLACE, name, value); }
/**
* Put an environment variable into a command's environment,
@@ -764,7 +982,9 @@ int libexec_setenv_replace(struct libexec_command *, const char *, const char *)
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_VPRINTF__(3) int libexec_vsetenvf_replace(struct libexec_command *, const char *, const char *, va_list);
+LIBEXEC_VPRINTF__(3) inline int
+libexec_vsetenvf_replace(struct libexec_command *cmd, const char *name, const char *value_fmt, va_list args)
+{ return libexec_vsetenvf(cmd, LIBEXEC_REPLACE, name, value_fmt, args); }
/**
* Put an environment variable into a command's environment,
@@ -791,7 +1011,9 @@ LIBEXEC_VPRINTF__(3) int libexec_vsetenvf_replace(struct libexec_command *, cons
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_PRINTF__(3) int libexec_setenvf_replace(struct libexec_command *, const char *, const char *, ...);
+LIBEXEC_PRINTF__(3) inline int
+libexec_setenvf_replace(struct libexec_command *cmd, const char *name, const char *value_fmt, ...)
+{ LIBEXEC_VA_IMPL__(value_fmt, libexec_vsetenvf_replace, cmd, name, value_fmt); }
/**
@@ -818,7 +1040,9 @@ LIBEXEC_PRINTF__(3) int libexec_setenvf_replace(struct libexec_command *, const
* @throws EINVAL Invalid argument input
* @throws ENOMEM Failed to allocate enough memory to modify the command's environment
*/
-int libexec_putenv_noreplace(struct libexec_command *, const char *);
+inline int
+libexec_putenv_noreplace(struct libexec_command *cmd, const char *string)
+{ return libexec_putenv(cmd, LIBEXEC_NOREPLACE, string); }
/**
* Put an environment variable into a command's environment
@@ -849,7 +1073,9 @@ int libexec_putenv_noreplace(struct libexec_command *, const char *);
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_VPRINTF__(2) int libexec_vputenvf_noreplace(struct libexec_command *, const char *, va_list);
+LIBEXEC_VPRINTF__(2) inline int
+libexec_vputenvf_noreplace(struct libexec_command *cmd, const char *fmt, va_list args)
+{ return libexec_vputenvf(cmd, LIBEXEC_NOREPLACE, fmt, args); }
/**
* Put an environment variable into a command's environment
@@ -880,7 +1106,9 @@ LIBEXEC_VPRINTF__(2) int libexec_vputenvf_noreplace(struct libexec_command *, co
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_PRINTF__(2) int libexec_putenvf_noreplace(struct libexec_command *, const char *, ...);
+LIBEXEC_PRINTF__(2) inline int
+libexec_putenvf_noreplace(struct libexec_command *cmd, const char *fmt, ...)
+{ LIBEXEC_VA_IMPL__(fmt, libexec_vputenvf_noreplace, cmd, fmt); }
/**
* Put an environment variable into a command's environment
@@ -907,7 +1135,9 @@ LIBEXEC_PRINTF__(2) int libexec_putenvf_noreplace(struct libexec_command *, cons
* @throws EINVAL Invalid argument input
* @throws ENOMEM Failed to allocate enough memory to modify the command's environment
*/
-int libexec_setenv_noreplace(struct libexec_command *, const char *, const char *);
+inline int
+libexec_setenv_noreplace(struct libexec_command *cmd, const char *name, const char *value)
+{ return libexec_setenv(cmd, LIBEXEC_NOREPLACE, name, value); }
/**
* Put an environment variable into a command's environment
@@ -937,7 +1167,9 @@ int libexec_setenv_noreplace(struct libexec_command *, const char *, const char
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_VPRINTF__(3) int libexec_vsetenvf_noreplace(struct libexec_command *, const char *, const char *, va_list);
+LIBEXEC_VPRINTF__(3) inline int
+libexec_vsetenvf_noreplace(struct libexec_command *cmd, const char *name, const char *value_fmt, va_list args)
+{ return libexec_vsetenvf(cmd, LIBEXEC_NOREPLACE, name, value_fmt, args); }
/**
* Put an environment variable into a command's environment
@@ -967,7 +1199,9 @@ LIBEXEC_VPRINTF__(3) int libexec_vsetenvf_noreplace(struct libexec_command *, co
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_PRINTF__(3) int libexec_setenvf_noreplace(struct libexec_command *, const char *, const char *, ...);
+LIBEXEC_PRINTF__(3) inline int
+libexec_setenvf_noreplace(struct libexec_command *cmd, const char *name, const char *value_fmt, ...)
+{ LIBEXEC_VA_IMPL__(value_fmt, libexec_vsetenvf_noreplace, cmd, name, value_fmt); }
/**
@@ -994,7 +1228,9 @@ LIBEXEC_PRINTF__(3) int libexec_setenvf_noreplace(struct libexec_command *, cons
* @throws EINVAL Invalid argument input
* @throws ENOMEM Failed to allocate enough memory to modify the command's environment
*/
-int libexec_putenv_noclobber(struct libexec_command *, const char *);
+inline int
+libexec_putenv_noclobber(struct libexec_command *cmd, const char *string)
+{ return libexec_putenv(cmd, LIBEXEC_NOCLOBBER, string); }
/**
* Put an environment variable into a command's environment
@@ -1025,7 +1261,9 @@ int libexec_putenv_noclobber(struct libexec_command *, const char *);
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_VPRINTF__(2) int libexec_vputenvf_noclobber(struct libexec_command *, const char *, va_list);
+LIBEXEC_VPRINTF__(2) inline int
+libexec_vputenvf_noclobber(struct libexec_command *cmd, const char *fmt, va_list args)
+{ return libexec_vputenvf(cmd, LIBEXEC_NOCLOBBER, fmt, args); }
/**
* Put an environment variable into a command's environment
@@ -1056,7 +1294,9 @@ LIBEXEC_VPRINTF__(2) int libexec_vputenvf_noclobber(struct libexec_command *, co
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_PRINTF__(2) int libexec_putenvf_noclobber(struct libexec_command *, const char *, ...);
+LIBEXEC_PRINTF__(2) inline int
+libexec_putenvf_noclobber(struct libexec_command *cmd, const char *fmt, ...)
+{ LIBEXEC_VA_IMPL__(fmt, libexec_vputenvf_noclobber, cmd, fmt); }
/**
* Put an environment variable into a command's environment
@@ -1083,7 +1323,9 @@ LIBEXEC_PRINTF__(2) int libexec_putenvf_noclobber(struct libexec_command *, cons
* @throws EINVAL Invalid argument input
* @throws ENOMEM Failed to allocate enough memory to modify the command's environment
*/
-int libexec_setenv_noclobber(struct libexec_command *, const char *, const char *);
+inline int
+libexec_setenv_noclobber(struct libexec_command *cmd, const char *name, const char *value)
+{ return libexec_setenv(cmd, LIBEXEC_NOCLOBBER, name, value); }
/**
* Put an environment variable into a command's environment
@@ -1113,7 +1355,9 @@ int libexec_setenv_noclobber(struct libexec_command *, const char *, const char
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_VPRINTF__(3) int libexec_vsetenvf_noclobber(struct libexec_command *, const char *, const char *, va_list);
+LIBEXEC_VPRINTF__(3) inline int
+libexec_vsetenvf_noclobber(struct libexec_command *cmd, const char *name, const char *value_fmt, va_list args)
+{ return libexec_vsetenvf(cmd, LIBEXEC_NOCLOBBER, name, value_fmt, args); }
/**
* Put an environment variable into a command's environment
@@ -1143,7 +1387,9 @@ LIBEXEC_VPRINTF__(3) int libexec_vsetenvf_noclobber(struct libexec_command *, co
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_PRINTF__(3) int libexec_setenvf_noclobber(struct libexec_command *, const char *, const char *, ...);
+LIBEXEC_PRINTF__(3) inline int
+libexec_setenvf_noclobber(struct libexec_command *cmd, const char *name, const char *value_fmt, ...)
+{ LIBEXEC_VA_IMPL__(value_fmt, libexec_vsetenvf_noclobber, cmd, name, value_fmt); }
/**
@@ -1167,7 +1413,9 @@ LIBEXEC_PRINTF__(3) int libexec_setenvf_noclobber(struct libexec_command *, cons
* @throws EINVAL Invalid argument input
* @throws ENOMEM Failed to allocate enough memory to modify the command's environment
*/
-int libexec_putenv_append(struct libexec_command *, const char *);
+inline int
+libexec_putenv_append(struct libexec_command *cmd, const char *string)
+{ return libexec_putenv(cmd, LIBEXEC_APPEND, string); }
/**
* Put an environment variable into a command's environment,
@@ -1194,7 +1442,9 @@ int libexec_putenv_append(struct libexec_command *, const char *);
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_VPRINTF__(2) int libexec_vputenvf_append(struct libexec_command *, const char *, va_list);
+LIBEXEC_VPRINTF__(2) inline int
+libexec_vputenvf_append(struct libexec_command *cmd, const char *fmt, va_list args)
+{ return libexec_vputenvf(cmd, LIBEXEC_APPEND, fmt, args); }
/**
* Put an environment variable into a command's environment,
@@ -1221,7 +1471,9 @@ LIBEXEC_VPRINTF__(2) int libexec_vputenvf_append(struct libexec_command *, const
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_PRINTF__(2) int libexec_putenvf_append(struct libexec_command *, const char *, ...);
+LIBEXEC_PRINTF__(2) inline int
+libexec_putenvf_append(struct libexec_command *cmd, const char *fmt, ...)
+{ LIBEXEC_VA_IMPL__(fmt, libexec_vputenvf_append, cmd, fmt); }
/**
* Put an environment variable into a command's environment,
@@ -1245,7 +1497,9 @@ LIBEXEC_PRINTF__(2) int libexec_putenvf_append(struct libexec_command *, const c
* @throws EINVAL Invalid argument input
* @throws ENOMEM Failed to allocate enough memory to modify the command's environment
*/
-int libexec_setenv_append(struct libexec_command *, const char *, const char *);
+inline int
+libexec_setenv_append(struct libexec_command *cmd, const char *name, const char *value)
+{ return libexec_setenv(cmd, LIBEXEC_APPEND, name, value); }
/**
* Put an environment variable into a command's environment,
@@ -1272,7 +1526,9 @@ int libexec_setenv_append(struct libexec_command *, const char *, const char *);
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_VPRINTF__(3) int libexec_vsetenvf_append(struct libexec_command *, const char *, const char *, va_list);
+LIBEXEC_VPRINTF__(3) inline int
+libexec_vsetenvf_append(struct libexec_command *cmd, const char *name, const char *value_fmt, va_list args)
+{ return libexec_vsetenvf(cmd, LIBEXEC_APPEND, name, value_fmt, args); }
/**
* Put an environment variable into a command's environment,
@@ -1299,7 +1555,9 @@ LIBEXEC_VPRINTF__(3) int libexec_vsetenvf_append(struct libexec_command *, const
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_PRINTF__(3) int libexec_setenvf_append(struct libexec_command *, const char *, const char *, ...);
+LIBEXEC_PRINTF__(3) inline int
+libexec_setenvf_append(struct libexec_command *cmd, const char *name, const char *value_fmt, ...)
+{ LIBEXEC_VA_IMPL__(value_fmt, libexec_vsetenvf_append, cmd, name, value_fmt); }
/**
@@ -1323,7 +1581,9 @@ LIBEXEC_PRINTF__(3) int libexec_setenvf_append(struct libexec_command *, const c
* @throws EINVAL Invalid argument input
* @throws ENOMEM Failed to allocate enough memory to modify the command's environment
*/
-int libexec_putenv_prepend(struct libexec_command *, const char *);
+inline int
+libexec_putenv_prepend(struct libexec_command *cmd, const char *string)
+{ return libexec_putenv(cmd, LIBEXEC_PREPEND, string); }
/**
* Put an environment variable into a command's environment,
@@ -1350,7 +1610,9 @@ int libexec_putenv_prepend(struct libexec_command *, const char *);
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_VPRINTF__(2) int libexec_vputenvf_prepend(struct libexec_command *, const char *, va_list);
+LIBEXEC_VPRINTF__(2) inline int
+libexec_vputenvf_prepend(struct libexec_command *cmd, const char *fmt, va_list args)
+{ return libexec_vputenvf(cmd, LIBEXEC_PREPEND, fmt, args); }
/**
* Put an environment variable into a command's environment,
@@ -1377,7 +1639,9 @@ LIBEXEC_VPRINTF__(2) int libexec_vputenvf_prepend(struct libexec_command *, cons
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_PRINTF__(2) int libexec_putenvf_prepend(struct libexec_command *, const char *, ...);
+LIBEXEC_PRINTF__(2) inline int
+libexec_putenvf_prepend(struct libexec_command *cmd, const char *fmt, ...)
+{ LIBEXEC_VA_IMPL__(fmt, libexec_vputenvf_prepend, cmd, fmt); }
/**
* Put an environment variable into a command's environment,
@@ -1401,7 +1665,9 @@ LIBEXEC_PRINTF__(2) int libexec_putenvf_prepend(struct libexec_command *, const
* @throws EINVAL Invalid argument input
* @throws ENOMEM Failed to allocate enough memory to modify the command's environment
*/
-int libexec_setenv_prepend(struct libexec_command *, const char *, const char *);
+inline int
+libexec_setenv_prepend(struct libexec_command *cmd, const char *name, const char *value)
+{ return libexec_setenv(cmd, LIBEXEC_PREPEND, name, value); }
/**
* Put an environment variable into a command's environment,
@@ -1428,7 +1694,9 @@ int libexec_setenv_prepend(struct libexec_command *, const char *, const char *)
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_VPRINTF__(3) int libexec_vsetenvf_prepend(struct libexec_command *, const char *, const char *, va_list);
+LIBEXEC_VPRINTF__(3) inline int
+libexec_vsetenvf_prepend(struct libexec_command *cmd, const char *name, const char *value_fmt, va_list args)
+{ return libexec_vsetenvf(cmd, LIBEXEC_PREPEND, name, value_fmt, args); }
/**
* Put an environment variable into a command's environment,
@@ -1455,7 +1723,9 @@ LIBEXEC_VPRINTF__(3) int libexec_vsetenvf_prepend(struct libexec_command *, cons
* @throws EILSEQ According to printf(3)
* @throws EOVERFLOW According to printf(3)
*/
-LIBEXEC_PRINTF__(3) int libexec_setenvf_prepend(struct libexec_command *, const char *, const char *, ...);
+LIBEXEC_PRINTF__(3) inline int
+libexec_setenvf_prepend(struct libexec_command *cmd, const char *name, const char *value_fmt, ...)
+{ LIBEXEC_VA_IMPL__(value_fmt, libexec_vsetenvf_prepend, cmd, name, value_fmt); }
/**
@@ -1490,7 +1760,7 @@ LIBEXEC_PRINTF__(3) int libexec_setenvf_prepend(struct libexec_command *, const
* @throws EINVAL Invalid argument input
* @throws ENOMEM Failed to allocate enough memory
*/
-int libexec_pipe_commandsvn(enum libexec_pipe how, struct libexec_command *const *cmds, size_t n);
+int libexec_pipe_commandsvn(enum libexec_pipe, struct libexec_command *const *, size_t);
/**
* Put a series of commands in a pipeline, piping each's
@@ -1523,7 +1793,18 @@ int libexec_pipe_commandsvn(enum libexec_pipe how, struct libexec_command *const
* @throws EINVAL Invalid argument input
* @throws ENOMEM Failed to allocate enough memory
*/
-int libexec_pipe_commandsv(enum libexec_pipe how, struct libexec_command *const *cmds);
+inline int
+libexec_pipe_commandsv(enum libexec_pipe how, struct libexec_command *const *cmds)
+{
+ size_t n = 0;
+ if (!cmds) {
+ errno = EINVAL;
+ return -1;
+ }
+ while (cmds[n])
+ n++;
+ return libexec_pipe_commandsvn(how, cmds, n);
+}
/**
* Put a series of commands in a pipeline, piping each's
@@ -1556,7 +1837,7 @@ int libexec_pipe_commandsv(enum libexec_pipe how, struct libexec_command *const
* @throws EINVAL Invalid argument input
* @throws ENOMEM Failed to allocate enough memory
*/
-int libexec_vpipe_commands(enum libexec_pipe how, va_list args);
+int libexec_vpipe_commands(enum libexec_pipe, va_list);
/**
* Put a series of commands in a pipeline, piping each's
@@ -1589,7 +1870,9 @@ int libexec_vpipe_commands(enum libexec_pipe how, va_list args);
* @throws EINVAL Invalid argument input
* @throws ENOMEM Failed to allocate enough memory
*/
-int libexec_pipe_commands(enum libexec_pipe how, ...);
+inline int
+libexec_pipe_commands(enum libexec_pipe how, ...)
+{ LIBEXEC_VA_IMPL__(how, libexec_vpipe_commands, how); }
int libexec_get_documents(struct libexec_command *cmd, struct libexec_document **docsp, size_t *ndocsp, int flags);
@@ -1627,7 +1910,8 @@ int libexec_run_pipeline(int (*on_alien_epoll)(int alien_epoll, uint32_t events,
LIBEXEC_RUN_PIPELINE_NO_OUTPUT
int libexec_vrun(struct libexec_result *out, va_list args);
-int libexec_run(struct libexec_result *out, ...);
+inline int libexec_run(struct libexec_result *out, ...)
+{ LIBEXEC_VA_IMPL__(out, libexec_vrun, out); }
#endif
diff --git a/libexec_clear_environ.c b/libexec_clear_environ.c
index 9f09561..df0c7ce 100644
--- a/libexec_clear_environ.c
+++ b/libexec_clear_environ.c
@@ -38,7 +38,7 @@ check_clear_from_default(void)
struct libexec_command cmd, ref;
char **old_env;
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
ASSERT_IS_NULL(cmd.environ);
diff --git a/libexec_construct_command.c b/libexec_construct_command.c
index 36b18f9..6fc91dc 100644
--- a/libexec_construct_command.c
+++ b/libexec_construct_command.c
@@ -3,16 +3,7 @@
#ifndef TEST
-int
-libexec_construct_command(struct libexec_command *cmd, const char *fmt, ...)
-{
- int ret;
- va_list args;
- va_start(args, fmt);
- ret = libexec_vconstruct_command(cmd, fmt, args);
- va_end(args);
- return ret;
-}
+extern inline int libexec_construct_command(struct libexec_command *, const char *, ...);
#else
diff --git a/libexec_getenv.c b/libexec_getenv.c
index 5099b28..cc93341 100644
--- a/libexec_getenv.c
+++ b/libexec_getenv.c
@@ -37,7 +37,7 @@ main(void)
struct libexec_command cmd, ref;
char **env;
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
env = environ;
diff --git a/libexec_getenv_last.c b/libexec_getenv_last.c
index 1de318e..f19465a 100644
--- a/libexec_getenv_last.c
+++ b/libexec_getenv_last.c
@@ -38,7 +38,7 @@ main(void)
struct libexec_command cmd, ref;
char **env;
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
env = environ;
diff --git a/libexec_input_text_copy.c b/libexec_input_text_copy.c
index da12bfd..cabf809 100644
--- a/libexec_input_text_copy.c
+++ b/libexec_input_text_copy.c
@@ -3,15 +3,7 @@
#ifndef TEST
-int
-libexec_input_text_copy(struct libexec_command *cmd, int fd, const char *text)
-{
- if (!text) {
- errno = EINVAL;
- return -1;
- }
- return libexec_input_data_copy(cmd, fd, text, strlen(text));
-}
+extern inline int libexec_input_text_copy(struct libexec_command *, int, const char *);
#else
diff --git a/libexec_input_text_gift.c b/libexec_input_text_gift.c
index 94b09c3..05dc5ef 100644
--- a/libexec_input_text_gift.c
+++ b/libexec_input_text_gift.c
@@ -3,15 +3,7 @@
#ifndef TEST
-int
-libexec_input_text_gift(struct libexec_command *cmd, int fd, char *text)
-{
- if (!text) {
- errno = EINVAL;
- return -1;
- }
- return libexec_input_data_gift(cmd, fd, text, strlen(text));
-}
+extern inline int libexec_input_text_gift(struct libexec_command *, int, char *);
#else
diff --git a/libexec_open.c b/libexec_open.c
index 7aa2698..77d05ed 100644
--- a/libexec_open.c
+++ b/libexec_open.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_open(struct libexec_command *cmd, int fd, const char *file, int flags, mode_t mode)
-{
- return libexec_openat(cmd, fd, AT_FDCWD, file, flags, mode);
-}
+extern inline int libexec_open(struct libexec_command *, int, const char *, int, mode_t);
#else
diff --git a/libexec_openat2.c b/libexec_openat2.c
index ff97bff..417a7e5 100644
--- a/libexec_openat2.c
+++ b/libexec_openat2.c
@@ -4,7 +4,7 @@
int
-libexec_openat2(struct libexec_command *cmd, int fd, int dirfd, const char *file, struct open_how *how, size_t size)
+libexec_openat2(struct libexec_command *cmd, int fd, int dirfd, const char *file, STRUCT_OPEN_HOW *how, size_t size)
{
#if defined(__linux__)
diff --git a/libexec_pipe_commands.c b/libexec_pipe_commands.c
index 580bf86..2dfd3bb 100644
--- a/libexec_pipe_commands.c
+++ b/libexec_pipe_commands.c
@@ -3,16 +3,7 @@
#ifndef TEST
-int
-libexec_pipe_commands(enum libexec_pipe how, ...)
-{
- int ret;
- va_list args;
- va_start(args, how);
- ret = libexec_vpipe_commands(how, args);
- va_end(args);
- return ret;
-}
+extern inline int libexec_pipe_commands(enum libexec_pipe, ...);
#else
diff --git a/libexec_pipe_commandsv.c b/libexec_pipe_commandsv.c
index ee96b7d..c1df257 100644
--- a/libexec_pipe_commandsv.c
+++ b/libexec_pipe_commandsv.c
@@ -3,18 +3,7 @@
#ifndef TEST
-int
-libexec_pipe_commandsv(enum libexec_pipe how, struct libexec_command *const *cmds)
-{
- size_t n = 0;
- if (!cmds) {
- errno = EINVAL;
- return -1;
- }
- while (cmds[n])
- n++;
- return libexec_pipe_commandsvn(how, cmds, n);
-}
+extern inline int libexec_pipe_commandsv(enum libexec_pipe, struct libexec_command *const *);
#else
diff --git a/libexec_pipe_commandsvn.c b/libexec_pipe_commandsvn.c
index d6aa1d5..8b0dbe2 100644
--- a/libexec_pipe_commandsvn.c
+++ b/libexec_pipe_commandsvn.c
@@ -59,6 +59,9 @@ pipe_two_commands(enum libexec_pipe how, struct libexec_command *left, struct li
}
right->plumings[right->nplumings - 1].type = LIBEXEC_PLUMING_PIPE;
+ /* TOOD should `fds[0]` be closed from `left`, and `fds[1]` close from `right`
+ * (isn't this a problem in general with LIBEXEC_PLUMING_PIPE) */
+
/* pluming shall be at the front */
tmp = left->plumings[left->nplumings - 1];
memcpy(&left->plumings[1], &left->plumings[0], (left->nplumings - 1) * sizeof(*left->plumings));
diff --git a/libexec_put_arguments.c b/libexec_put_arguments.c
index 45f7f1a..54af507 100644
--- a/libexec_put_arguments.c
+++ b/libexec_put_arguments.c
@@ -3,18 +3,7 @@
#ifndef TEST
-int
-libexec_put_arguments(struct libexec_command *cmd, const char *const *args)
-{
- size_t n = 0;
- if (!args) {
- errno = EINVAL;
- return -1;
- }
- while (args[n])
- n += 1;
- return libexec_put_argumentsn(cmd, args, n);
-}
+extern inline int libexec_put_arguments(struct libexec_command *, const char *const *);
#else
diff --git a/libexec_putenv.c b/libexec_putenv.c
index 366f5fb..c72a153 100644
--- a/libexec_putenv.c
+++ b/libexec_putenv.c
@@ -79,12 +79,9 @@ libexec_putenv(struct libexec_command *cmd, enum libexec_insert_mode how, const
}
if (how == LIBEXEC_NOREPLACE || !strcmp(env[i], string)) {
- if (!cmd->environ) {
- if (libexec_copy_environ(cmd, NULL)) {
- free(copy);
+ if (!cmd->environ)
+ if (libexec_copy_environ(cmd, NULL))
return -1;
- }
- }
return 0;
}
if (how == LIBEXEC_NOCLOBBER)
@@ -124,7 +121,7 @@ main(void)
struct libexec_command cmd, ref;
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
diff --git a/libexec_putenv_append.c b/libexec_putenv_append.c
index bb45e1c..028b54d 100644
--- a/libexec_putenv_append.c
+++ b/libexec_putenv_append.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_putenv_append(struct libexec_command *cmd, const char *string)
-{
- return libexec_putenv(cmd, LIBEXEC_APPEND, string);
-}
+extern inline int libexec_putenv_append(struct libexec_command *, const char *);
#else
@@ -23,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_putenv_append(NULL, "X=Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
ASSERT_ZERO(libexec_clear_environ(&cmd));
@@ -121,7 +117,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_putenv_noclobber.c b/libexec_putenv_noclobber.c
index e9cf3ed..1c21a55 100644
--- a/libexec_putenv_noclobber.c
+++ b/libexec_putenv_noclobber.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_putenv_noclobber(struct libexec_command *cmd, const char *string)
-{
- return libexec_putenv(cmd, LIBEXEC_NOCLOBBER, string);
-}
+extern inline int libexec_putenv_noclobber(struct libexec_command *, const char *);
#else
@@ -23,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_putenv_noclobber(NULL, "X=Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
@@ -97,7 +93,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_putenv_noreplace.c b/libexec_putenv_noreplace.c
index b33708a..e85db00 100644
--- a/libexec_putenv_noreplace.c
+++ b/libexec_putenv_noreplace.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_putenv_noreplace(struct libexec_command *cmd, const char *string)
-{
- return libexec_putenv(cmd, LIBEXEC_NOREPLACE, string);
-}
+extern inline int libexec_putenv_noreplace(struct libexec_command *, const char *);
#else
@@ -23,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_putenv_noreplace(NULL, "X=Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
@@ -95,7 +91,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_putenv_prepend.c b/libexec_putenv_prepend.c
index 840978d..1ea6801 100644
--- a/libexec_putenv_prepend.c
+++ b/libexec_putenv_prepend.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_putenv_prepend(struct libexec_command *cmd, const char *string)
-{
- return libexec_putenv(cmd, LIBEXEC_PREPEND, string);
-}
+extern inline int libexec_putenv_prepend(struct libexec_command *, const char *);
#else
@@ -23,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_putenv_prepend(NULL, "X=Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
ASSERT_ZERO(libexec_clear_environ(&cmd));
@@ -121,7 +117,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_putenv_replace.c b/libexec_putenv_replace.c
index c62ad01..8f46451 100644
--- a/libexec_putenv_replace.c
+++ b/libexec_putenv_replace.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_putenv_replace(struct libexec_command *cmd, const char *string)
-{
- return libexec_putenv(cmd, LIBEXEC_REPLACE, string);
-}
+extern inline int libexec_putenv_replace(struct libexec_command *, const char *);
#else
@@ -23,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_putenv_replace(NULL, "X=Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
@@ -95,7 +91,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_putenvf.c b/libexec_putenvf.c
index 7729fc4..73cd4d2 100644
--- a/libexec_putenvf.c
+++ b/libexec_putenvf.c
@@ -3,16 +3,7 @@
#ifndef TEST
-int
-libexec_putenvf(struct libexec_command *cmd, enum libexec_insert_mode how, const char *fmt, ...)
-{
- int ret;
- va_list args;
- va_start(args, fmt);
- ret = libexec_vputenvf(cmd, how, fmt, args);
- va_end(args);
- return ret;
-}
+extern inline int libexec_putenvf(struct libexec_command *, enum libexec_insert_mode, const char *, ...);
#else
@@ -30,7 +21,7 @@ main(void)
struct libexec_command cmd, ref;
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
diff --git a/libexec_putenvf_append.c b/libexec_putenvf_append.c
index 8ceb806..bdfa7fc 100644
--- a/libexec_putenvf_append.c
+++ b/libexec_putenvf_append.c
@@ -3,16 +3,7 @@
#ifndef TEST
-int
-libexec_putenvf_append(struct libexec_command *cmd, const char *fmt, ...)
-{
- int ret;
- va_list args;
- va_start(args, fmt);
- ret = libexec_vputenvf_append(cmd, fmt, args);
- va_end(args);
- return ret;
-}
+extern inline int libexec_putenvf_append(struct libexec_command *, const char *, ...);
#else
@@ -28,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_putenvf_append(NULL, "X=Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
ASSERT_ZERO(libexec_clear_environ(&cmd));
@@ -126,7 +117,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_putenvf_noclobber.c b/libexec_putenvf_noclobber.c
index 988e381..9ab1509 100644
--- a/libexec_putenvf_noclobber.c
+++ b/libexec_putenvf_noclobber.c
@@ -3,16 +3,7 @@
#ifndef TEST
-int
-libexec_putenvf_noclobber(struct libexec_command *cmd, const char *fmt, ...)
-{
- int ret;
- va_list args;
- va_start(args, fmt);
- ret = libexec_vputenvf_noclobber(cmd, fmt, args);
- va_end(args);
- return ret;
-}
+extern inline int libexec_putenvf_noclobber(struct libexec_command *, const char *, ...);
#else
@@ -28,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_putenvf_noclobber(NULL, "X=Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
@@ -102,7 +93,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_putenvf_noreplace.c b/libexec_putenvf_noreplace.c
index bcde8a2..f1b4140 100644
--- a/libexec_putenvf_noreplace.c
+++ b/libexec_putenvf_noreplace.c
@@ -3,16 +3,7 @@
#ifndef TEST
-int
-libexec_putenvf_noreplace(struct libexec_command *cmd, const char *fmt, ...)
-{
- int ret;
- va_list args;
- va_start(args, fmt);
- ret = libexec_vputenvf_noreplace(cmd, fmt, args);
- va_end(args);
- return ret;
-}
+extern inline int libexec_putenvf_noreplace(struct libexec_command *, const char *, ...);
#else
@@ -28,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_putenvf_noreplace(NULL, "X=Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
@@ -100,7 +91,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_putenvf_prepend.c b/libexec_putenvf_prepend.c
index 2e51a72..0bccbfe 100644
--- a/libexec_putenvf_prepend.c
+++ b/libexec_putenvf_prepend.c
@@ -3,16 +3,7 @@
#ifndef TEST
-int
-libexec_putenvf_prepend(struct libexec_command *cmd, const char *fmt, ...)
-{
- int ret;
- va_list args;
- va_start(args, fmt);
- ret = libexec_vputenvf_prepend(cmd, fmt, args);
- va_end(args);
- return ret;
-}
+extern inline int libexec_putenvf_prepend(struct libexec_command *, const char *, ...);
#else
@@ -28,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_putenvf_prepend(NULL, "X=Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
ASSERT_ZERO(libexec_clear_environ(&cmd));
@@ -126,7 +117,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_putenvf_replace.c b/libexec_putenvf_replace.c
index 7cfd773..1ee0f52 100644
--- a/libexec_putenvf_replace.c
+++ b/libexec_putenvf_replace.c
@@ -3,16 +3,7 @@
#ifndef TEST
-int
-libexec_putenvf_replace(struct libexec_command *cmd, const char *fmt, ...)
-{
- int ret;
- va_list args;
- va_start(args, fmt);
- ret = libexec_vputenvf_replace(cmd, fmt, args);
- va_end(args);
- return ret;
-}
+extern inline int libexec_putenvf_replace(struct libexec_command *, const char *, ...);
#else
@@ -28,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_putenvf_replace(NULL, "X=Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
@@ -100,7 +91,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_run.c b/libexec_run.c
index ca1f629..939365d 100644
--- a/libexec_run.c
+++ b/libexec_run.c
@@ -3,16 +3,7 @@
#ifndef TEST
-int
-libexec_run(struct libexec_result *out, ...)
-{
- int ret;
- va_list args;
- va_start(args, out);
- ret = libexec_vrun(out, args);
- va_end(args);
- return ret;
-}
+extern inline int libexec_run(struct libexec_result *, ...);
#else
diff --git a/libexec_setenv.c b/libexec_setenv.c
index 47bc8e9..9d0dc77 100644
--- a/libexec_setenv.c
+++ b/libexec_setenv.c
@@ -36,7 +36,7 @@ main(void)
struct libexec_command cmd, ref;
int i;
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
diff --git a/libexec_setenv_append.c b/libexec_setenv_append.c
index a35207d..eb90c0a 100644
--- a/libexec_setenv_append.c
+++ b/libexec_setenv_append.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_setenv_append(struct libexec_command *cmd, const char *name, const char *value)
-{
- return libexec_setenv(cmd, LIBEXEC_APPEND, name, value);
-}
+extern inline int libexec_setenv_append(struct libexec_command *, const char *, const char *);
#else
@@ -23,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_setenv_append(NULL, "X", "Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
@@ -118,7 +114,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_setenv_noclobber.c b/libexec_setenv_noclobber.c
index 6478a9e..2e9c1e7 100644
--- a/libexec_setenv_noclobber.c
+++ b/libexec_setenv_noclobber.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_setenv_noclobber(struct libexec_command *cmd, const char *name, const char *value)
-{
- return libexec_setenv(cmd, LIBEXEC_NOCLOBBER, name, value);
-}
+extern inline int libexec_setenv_noclobber(struct libexec_command *, const char *, const char *);
#else
@@ -23,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_setenv_noclobber(NULL, "X", "Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
@@ -102,7 +98,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_setenv_noreplace.c b/libexec_setenv_noreplace.c
index 26339e8..35aef28 100644
--- a/libexec_setenv_noreplace.c
+++ b/libexec_setenv_noreplace.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_setenv_noreplace(struct libexec_command *cmd, const char *name, const char *value)
-{
- return libexec_setenv(cmd, LIBEXEC_NOREPLACE, name, value);
-}
+extern inline int libexec_setenv_noreplace(struct libexec_command *, const char *, const char *);
#else
@@ -23,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_setenv_noreplace(NULL, "X", "Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
@@ -100,7 +96,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_setenv_prepend.c b/libexec_setenv_prepend.c
index 9c7a02b..b661abd 100644
--- a/libexec_setenv_prepend.c
+++ b/libexec_setenv_prepend.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_setenv_prepend(struct libexec_command *cmd, const char *name, const char *value)
-{
- return libexec_setenv(cmd, LIBEXEC_PREPEND, name, value);
-}
+extern inline int libexec_setenv_prepend(struct libexec_command *, const char *, const char *);
#else
@@ -23,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_setenv_prepend(NULL, "X", "Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
@@ -118,7 +114,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_setenv_replace.c b/libexec_setenv_replace.c
index f8191c1..edbdde3 100644
--- a/libexec_setenv_replace.c
+++ b/libexec_setenv_replace.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_setenv_replace(struct libexec_command *cmd, const char *name, const char *value)
-{
- return libexec_setenv(cmd, LIBEXEC_REPLACE, name, value);
-}
+extern inline int libexec_setenv_replace(struct libexec_command *, const char *, const char *);
#else
@@ -23,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_setenv_replace(NULL, "X", "Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
@@ -100,7 +96,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_setenvf.c b/libexec_setenvf.c
index 7589dca..d7af3f8 100644
--- a/libexec_setenvf.c
+++ b/libexec_setenvf.c
@@ -3,16 +3,7 @@
#ifndef TEST
-int
-libexec_setenvf(struct libexec_command *cmd, enum libexec_insert_mode how, const char *name, const char *value_fmt, ...)
-{
- int ret;
- va_list args;
- va_start(args, value_fmt);
- ret = libexec_vsetenvf(cmd, how, name, value_fmt, args);
- va_end(args);
- return ret;
-}
+extern inline int libexec_setenvf(struct libexec_command *, enum libexec_insert_mode, const char *, const char *, ...);
#else
@@ -30,7 +21,7 @@ main(void)
struct libexec_command cmd, ref;
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
diff --git a/libexec_setenvf_append.c b/libexec_setenvf_append.c
index b0b6a4e..9c89a0e 100644
--- a/libexec_setenvf_append.c
+++ b/libexec_setenvf_append.c
@@ -3,16 +3,7 @@
#ifndef TEST
-int
-libexec_setenvf_append(struct libexec_command *cmd, const char *name, const char *value_fmt, ...)
-{
- int ret;
- va_list args;
- va_start(args, value_fmt);
- ret = libexec_vsetenvf_append(cmd, name, value_fmt, args);
- va_end(args);
- return ret;
-}
+extern inline int libexec_setenvf_append(struct libexec_command *, const char *, const char *, ...);
#else
@@ -28,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_setenvf_append(NULL, "X", "Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
@@ -123,7 +114,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_setenvf_noclobber.c b/libexec_setenvf_noclobber.c
index f40b367..d851239 100644
--- a/libexec_setenvf_noclobber.c
+++ b/libexec_setenvf_noclobber.c
@@ -3,16 +3,7 @@
#ifndef TEST
-int
-libexec_setenvf_noclobber(struct libexec_command *cmd, const char *name, const char *value_fmt, ...)
-{
- int ret;
- va_list args;
- va_start(args, value_fmt);
- ret = libexec_vsetenvf_noclobber(cmd, name, value_fmt, args);
- va_end(args);
- return ret;
-}
+extern inline int libexec_setenvf_noclobber(struct libexec_command *, const char *, const char *, ...);
#else
@@ -28,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_setenvf_noclobber(NULL, "X", "Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
@@ -107,7 +98,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_setenvf_noreplace.c b/libexec_setenvf_noreplace.c
index 9480c7f..0385fff 100644
--- a/libexec_setenvf_noreplace.c
+++ b/libexec_setenvf_noreplace.c
@@ -3,16 +3,7 @@
#ifndef TEST
-int
-libexec_setenvf_noreplace(struct libexec_command *cmd, const char *name, const char *value_fmt, ...)
-{
- int ret;
- va_list args;
- va_start(args, value_fmt);
- ret = libexec_vsetenvf_noreplace(cmd, name, value_fmt, args);
- va_end(args);
- return ret;
-}
+extern inline int libexec_setenvf_noreplace(struct libexec_command *, const char *, const char *, ...);
#else
@@ -28,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_setenvf_noreplace(NULL, "X", "Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
@@ -105,7 +96,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_setenvf_prepend.c b/libexec_setenvf_prepend.c
index 3a8a197..a77acf1 100644
--- a/libexec_setenvf_prepend.c
+++ b/libexec_setenvf_prepend.c
@@ -3,16 +3,7 @@
#ifndef TEST
-int
-libexec_setenvf_prepend(struct libexec_command *cmd, const char *name, const char *value_fmt, ...)
-{
- int ret;
- va_list args;
- va_start(args, value_fmt);
- ret = libexec_vsetenvf_prepend(cmd, name, value_fmt, args);
- va_end(args);
- return ret;
-}
+extern inline int libexec_setenvf_prepend(struct libexec_command *, const char *, const char *, ...);
#else
@@ -28,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_setenvf_prepend(NULL, "X", "Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
@@ -123,7 +114,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_setenvf_replace.c b/libexec_setenvf_replace.c
index 9be28db..e1a38aa 100644
--- a/libexec_setenvf_replace.c
+++ b/libexec_setenvf_replace.c
@@ -3,16 +3,7 @@
#ifndef TEST
-int
-libexec_setenvf_replace(struct libexec_command *cmd, const char *name, const char *value_fmt, ...)
-{
- int ret;
- va_list args;
- va_start(args, value_fmt);
- ret = libexec_vsetenvf_replace(cmd, name, value_fmt, args);
- va_end(args);
- return ret;
-}
+extern inline int libexec_setenvf_replace(struct libexec_command *, const char *, const char *, ...);
#else
@@ -28,7 +19,7 @@ main(void)
ASSERT_EQ_INT(libexec_setenvf_replace(NULL, "X", "Y"), -1);
ASSERT_EQ_INT(errno, EINVAL);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
memcpy(&ref, &cmd, sizeof(cmd));
errno = 0;
@@ -105,7 +96,7 @@ main(void)
libexec_destroy_command(&cmd);
- libexec_init_command(&cmd);
+ cmd = LIBEXEC_COMMAND_INIT;
env = environ;
environ = calloc(2, sizeof(*environ));
ASSERT_NOT_NULL(environ);
diff --git a/libexec_unsetenv.c b/libexec_unsetenv.c
index 48ec645..f6a71e2 100644
--- a/libexec_unsetenv.c
+++ b/libexec_unsetenv.c
@@ -31,7 +31,7 @@ libexec_unsetenv(struct libexec_command *cmd, const char *name)
return -1;
env = cmd->environ;
}
- free(env);
+ free(env[i]);
memmove(&env[i], &env[i + 1], (n - i - 1) * sizeof(*env));
n--;
} else {
diff --git a/libexec_vputenvf_append.c b/libexec_vputenvf_append.c
index ca0d564..2ce4699 100644
--- a/libexec_vputenvf_append.c
+++ b/libexec_vputenvf_append.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_vputenvf_append(struct libexec_command *cmd, const char *fmt, va_list args)
-{
- return libexec_vputenvf(cmd, LIBEXEC_APPEND, fmt, args);
-}
+extern inline int libexec_vputenvf_append(struct libexec_command *, const char *, va_list);
#else
diff --git a/libexec_vputenvf_noclobber.c b/libexec_vputenvf_noclobber.c
index 61a1e74..77ba2cd 100644
--- a/libexec_vputenvf_noclobber.c
+++ b/libexec_vputenvf_noclobber.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_vputenvf_noclobber(struct libexec_command *cmd, const char *fmt, va_list args)
-{
- return libexec_vputenvf(cmd, LIBEXEC_NOCLOBBER, fmt, args);
-}
+extern inline int libexec_vputenvf_noclobber(struct libexec_command *, const char *, va_list);
#else
diff --git a/libexec_vputenvf_noreplace.c b/libexec_vputenvf_noreplace.c
index 6998742..8c858dd 100644
--- a/libexec_vputenvf_noreplace.c
+++ b/libexec_vputenvf_noreplace.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_vputenvf_noreplace(struct libexec_command *cmd, const char *fmt, va_list args)
-{
- return libexec_vputenvf(cmd, LIBEXEC_NOREPLACE, fmt, args);
-}
+extern inline int libexec_vputenvf_noreplace(struct libexec_command *, const char *, va_list);
#else
diff --git a/libexec_vputenvf_prepend.c b/libexec_vputenvf_prepend.c
index e1b9614..b235962 100644
--- a/libexec_vputenvf_prepend.c
+++ b/libexec_vputenvf_prepend.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_vputenvf_prepend(struct libexec_command *cmd, const char *fmt, va_list args)
-{
- return libexec_vputenvf(cmd, LIBEXEC_PREPEND, fmt, args);
-}
+extern inline int libexec_vputenvf_prepend(struct libexec_command *, const char *, va_list);
#else
diff --git a/libexec_vputenvf_replace.c b/libexec_vputenvf_replace.c
index 10c22d2..8cc8524 100644
--- a/libexec_vputenvf_replace.c
+++ b/libexec_vputenvf_replace.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_vputenvf_replace(struct libexec_command *cmd, const char *fmt, va_list args)
-{
- return libexec_vputenvf(cmd, LIBEXEC_REPLACE, fmt, args);
-}
+extern inline int libexec_vputenvf_replace(struct libexec_command *, const char *, va_list);
#else
diff --git a/libexec_vrun.c b/libexec_vrun.c
index 99822c2..00a5f82 100644
--- a/libexec_vrun.c
+++ b/libexec_vrun.c
@@ -50,7 +50,7 @@ new_command:
CMD = malloc(sizeof(CMD));
if (!CMD)
goto fail;
- libexec_init_command(CMD);
+ *CMD = LIBEXEC_COMMAND_INIT;
fmt = va_arg(args, const char *);
if (libexec_vconstruct_command(CMD, fmt, args))
goto fail;
diff --git a/libexec_vsetenvf_append.c b/libexec_vsetenvf_append.c
index c00f8b6..fd8ef36 100644
--- a/libexec_vsetenvf_append.c
+++ b/libexec_vsetenvf_append.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_vsetenvf_append(struct libexec_command *cmd, const char *name, const char *value_fmt, va_list args)
-{
- return libexec_vsetenvf(cmd, LIBEXEC_APPEND, name, value_fmt, args);
-}
+extern inline int libexec_vsetenvf_append(struct libexec_command *, const char *, const char *, va_list);
#else
diff --git a/libexec_vsetenvf_noclobber.c b/libexec_vsetenvf_noclobber.c
index 5164e8b..0c85856 100644
--- a/libexec_vsetenvf_noclobber.c
+++ b/libexec_vsetenvf_noclobber.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_vsetenvf_noclobber(struct libexec_command *cmd, const char *name, const char *value_fmt, va_list args)
-{
- return libexec_vsetenvf(cmd, LIBEXEC_NOCLOBBER, name, value_fmt, args);
-}
+extern inline int libexec_vsetenvf_noclobber(struct libexec_command *, const char *, const char *, va_list);
#else
diff --git a/libexec_vsetenvf_noreplace.c b/libexec_vsetenvf_noreplace.c
index 1fb1476..6910bf3 100644
--- a/libexec_vsetenvf_noreplace.c
+++ b/libexec_vsetenvf_noreplace.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_vsetenvf_noreplace(struct libexec_command *cmd, const char *name, const char *value_fmt, va_list args)
-{
- return libexec_vsetenvf(cmd, LIBEXEC_NOREPLACE, name, value_fmt, args);
-}
+extern inline int libexec_vsetenvf_noreplace(struct libexec_command *, const char *, const char *, va_list);
#else
diff --git a/libexec_vsetenvf_prepend.c b/libexec_vsetenvf_prepend.c
index 63daaae..ad09ce2 100644
--- a/libexec_vsetenvf_prepend.c
+++ b/libexec_vsetenvf_prepend.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_vsetenvf_prepend(struct libexec_command *cmd, const char *name, const char *value_fmt, va_list args)
-{
- return libexec_vsetenvf(cmd, LIBEXEC_PREPEND, name, value_fmt, args);
-}
+extern inline int libexec_vsetenvf_prepend(struct libexec_command *, const char *, const char *, va_list);
#else
diff --git a/libexec_vsetenvf_replace.c b/libexec_vsetenvf_replace.c
index d1e8788..6cbd04b 100644
--- a/libexec_vsetenvf_replace.c
+++ b/libexec_vsetenvf_replace.c
@@ -3,11 +3,7 @@
#ifndef TEST
-int
-libexec_vsetenvf_replace(struct libexec_command *cmd, const char *name, const char *value_fmt, va_list args)
-{
- return libexec_vsetenvf(cmd, LIBEXEC_REPLACE, name, value_fmt, args);
-}
+extern inline int libexec_vsetenvf_replace(struct libexec_command *, const char *, const char *, va_list);
#else