aboutsummaryrefslogtreecommitdiffstats
path: root/libexec.h
diff options
context:
space:
mode:
Diffstat (limited to 'libexec.h')
-rw-r--r--libexec.h396
1 files changed, 340 insertions, 56 deletions
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