aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.posix/exec.ccm
blob: cd031176029cdf3caa52a0e58fddd4428584b6f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * This source code is released into the public domain.
 */

module;

/*
 * Exec providers, mostly used for spawn().
 */

#include <expected>
#include <string>

#include "nihil.hh"

export module nihil.posix:exec;

import nihil.error;
import :execv;
import :fexecv;
import :argv;
import :fd;

namespace nihil {

/*
 * The lowest-level executor type, which is returned by other executors.
 * Prefer fexecve() if it's available, otherwise use execve().
 */
#ifdef NIHIL_HAVE_FEXECVE
using base_executor_type = fexecv;
#else
using base_executor_type = execv;
#endif

/*
 * execl: equivalent to execv, except the arguments are passed as a
 * variadic pack of string-like objects.
 */
export [[nodiscard]] auto execl(std::string_view path, auto &&...args)
	-> std::expected<base_executor_type, error>
{
	return execv(path, argv({std::string_view(args)...}));
}

/*
 * shell: run the process by invoking /bin/sh -c with the single argument,
 * equivalent to system(3).
 */
export [[nodiscard]] auto shell(std::string_view const &command)
	-> std::expected<base_executor_type, error>;

} // namespace nihil