/*
 * libexec.h
 *
 * Small wrapper for execve()
 *
 * (c) 2024 Dario Rodriguez <antartica@whereismybit.com>
 * This file is in the public domain.
 */

typedef struct exec_t {
        char *name;
        char **envp;
        char *prebuf;
        char *postbuf;
        int has_param;
        int fdin;
        int fdout;
        int fderr;
        int pid;
        int laststatus;
} exec_t;

exec_t *exec_init(char *name, char *commandwithstringsub, char **envp);
void exec_free(exec_t *exec);

int exec_open(exec_t *exec, char *stringsub);
int exec_close(exec_t *exec);

#ifndef __GNUC__
int exec_reap(exec_t *exec1, /* exec_t *exec2, */ ...);
#else
        int exec_reap(exec_t *exec1, /* exec_t *exec2, */ ...) __attribute__((sentinel));
#endif

int executil_installsignal(int sig, void (*f)(int));
int executil_queued(int fd);
#ifndef __GNUC__
exec_t *executil_fd2exec(int fd, exec_t *exec1, /* exec_t *exec2, */ ...);
#else
        exec_t *executil_fd2exec(int fd, exec_t *exec1, ...) __attribute__((sentinel));
#endif