fish-shell/src/null_terminated_array.cpp
ridiculousfish 10ee87eb28 Reimplement owning_null_terminated_array in Rust
owning_null_terminated_array is used for environment variables, where we need to
provide envp for child processes. This switches the implementation from C++ to
Rust.

We retain the C++ owning_null_terminated_array_t; it simply wraps the Rust
version now.
2023-05-07 15:15:56 -07:00

19 lines
674 B
C++

#include "null_terminated_array.h"
std::vector<std::string> wide_string_list_to_narrow(const std::vector<wcstring> &strs) {
std::vector<std::string> res;
res.reserve(strs.size());
for (const wcstring &s : strs) {
res.push_back(wcs2zstring(s));
}
return res;
}
const char **owning_null_terminated_array_t::get() { return impl_->get(); }
owning_null_terminated_array_t::owning_null_terminated_array_t(std::vector<std::string> &&strings)
: impl_(new_owning_null_terminated_array(strings)) {}
owning_null_terminated_array_t::owning_null_terminated_array_t(
rust::Box<OwningNullTerminatedArrayRefFFI> impl)
: impl_(std::move(impl)) {}