diff options
Diffstat (limited to 'src/libexpr/gc-alloc.cc')
-rw-r--r-- | src/libexpr/gc-alloc.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/libexpr/gc-alloc.cc b/src/libexpr/gc-alloc.cc new file mode 100644 index 000000000..558a2f2bc --- /dev/null +++ b/src/libexpr/gc-alloc.cc @@ -0,0 +1,23 @@ +#include "gc-alloc.hh" + +#include <cstring> +#include <string_view> + +namespace nix +{ + +char const * gcCopyStringIfNeeded(std::string_view toCopyFrom) +{ + if (toCopyFrom.empty()) { + return ""; + } + + size_t const size = toCopyFrom.size(); + char * cstr = gcAllocString(size + 1); + memcpy(cstr, toCopyFrom.data(), size); + cstr[size] = '\0'; + + return cstr; +} + +} |