mirror of
https://github.com/NixOS/nix
synced 2025-06-26 20:01:15 +02:00
Build a minimized Nix with MinGW
At this point many features are stripped out, but this works: - Can run libnix{util,store,expr} unit tests - Can run some Nix commands Co-Authored-By volth <volth@volth.com> Co-Authored-By Brian McKenna <brian@brianmckenna.org>
This commit is contained in:
parent
2248a3f545
commit
8433027e35
111 changed files with 1162 additions and 140 deletions
52
src/libutil/windows/file-path.cc
Normal file
52
src/libutil/windows/file-path.cc
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include <algorithm>
|
||||
#include <codecvt>
|
||||
#include <iostream>
|
||||
#include <locale>
|
||||
|
||||
#include "file-path.hh"
|
||||
#include "file-path-impl.hh"
|
||||
#include "util.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
std::string os_string_to_string(PathViewNG::string_view path)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
return converter.to_bytes(PathNG::string_type { path });
|
||||
}
|
||||
|
||||
PathNG::string_type string_to_os_string(std::string_view s)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
return converter.from_bytes(std::string { s });
|
||||
}
|
||||
|
||||
std::optional<PathNG> maybePathNG(PathView path)
|
||||
{
|
||||
if (path.length() >= 3 && (('A' <= path[0] && path[0] <= 'Z') || ('a' <= path[0] && path[0] <= 'z')) && path[1] == ':' && WindowsPathTrait<char>::isPathSep(path[2])) {
|
||||
PathNG::string_type sw = string_to_os_string(
|
||||
std::string { "\\\\?\\" } + path);
|
||||
std::replace(sw.begin(), sw.end(), '/', '\\');
|
||||
return sw;
|
||||
}
|
||||
if (path.length() >= 7 && path[0] == '\\' && path[1] == '\\' && (path[2] == '.' || path[2] == '?') && path[3] == '\\' &&
|
||||
('A' <= path[4] && path[4] <= 'Z') && path[5] == ':' && WindowsPathTrait<char>::isPathSep(path[6])) {
|
||||
PathNG::string_type sw = string_to_os_string(path);
|
||||
std::replace(sw.begin(), sw.end(), '/', '\\');
|
||||
return sw;
|
||||
}
|
||||
return std::optional<PathNG::string_type>();
|
||||
}
|
||||
|
||||
PathNG pathNG(PathView path)
|
||||
{
|
||||
std::optional<PathNG::string_type> sw = maybePathNG(path);
|
||||
if (!sw) {
|
||||
// FIXME why are we not using the regular error handling?
|
||||
std::cerr << "invalid path for WinAPI call ["<<path<<"]"<<std::endl;
|
||||
_exit(111);
|
||||
}
|
||||
return *sw;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue