1/* See LICENSE file for copyright and license details. */
2#ifndef ARUU_WEXEC_H
3#define ARUU_WEXEC_H
4
5#include <stdio.h>
6#include <sys/types.h>
7
8typedef int (*wexec_fn)(int argc, char **argv);
9
10int wexec_register(const char *name, wexec_fn fn);
11int wexec_is_builtin(const char *name);
12void wexec_register_env_lookup(char *(*fn)(const char *name));
13#if FEATURE_NOEXEC || FEATURE_NOFORK
14int wexec_call_builtin(const char *name, char *const *argv);
15void wexec_exit(int code) __attribute__((noreturn));
16#endif
17
18/* search path for name, returns emallocd absolute path or null if not found
19 * when feature_noexec is compiled in and builtin dispatch is enabled,
20 * returns null for registered builtins (they have no filesystem path) */
21char *wwhich(const char *name);
22
23int wexec_is_nofork(const char *name);
24
25#if FEATURE_NOEXEC
26void wexec_set_noexec(int enabled);
27int wexec_get_noexec(void);
28#else
29#define wexec_get_noexec() 0
30#endif
31
32#if FEATURE_NOFORK
33void wexec_set_nofork(int enabled);
34int wexec_get_nofork(void);
35#else
36#define wexec_get_nofork() 0
37#endif
38
39int wexecvp(const char *name, char *const *argv);
40int wexecv(const char *path, char *const *argv);
41
42FILE *wpopen(const char *name, char *const *argv, const char *mode);
43int wpclose(FILE *fp);
44
45int wsystem(const char *cmd);
46
47void wexecvp_self(const char *name, char *const *argv) __attribute__((noreturn));
48void wexecv_self(const char *path, char *const *argv) __attribute__((noreturn));
49
50int wpopen_track(FILE *fp, pid_t pid);
51pid_t wpopen_untrack(FILE *fp);
52
53#endif