aboutsummaryrefslogtreecommitdiffstats
path: root/liblfjail/argv.cc
blob: e4e6592c686d6370931aee4bfc36d9391c533334 (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
/*
 * This source code is released into the public domain.
 */

#include "argv.hh"

namespace lfjail {

argv::~argv() {
	for (auto *arg : _args)
		delete[] arg;
}

auto argv::_add_arg(this argv &self, std::string_view arg) -> void {
	// Create a nul-terminated C string.
	auto ptr = std::make_unique<char[]>(arg.size() + 1);
	std::ranges::copy(arg, ptr.get());
	ptr[arg.size()] = '\0';

	// Ensure we won't throw when emplacing the pointer.
	self._args.reserve(self._args.size() + 1);
	self._args.emplace_back(ptr.release());
}

} // namespace lfjail