mirror of
https://github.com/NixOS/nix.git
synced 2025-12-17 22:41:08 +01:00
Move /src to /subprojects
This will facilitate breaking up Nix into multiple packages for each component with Meson.
This commit is contained in:
parent
4db9487823
commit
84e2963f8e
737 changed files with 504 additions and 505 deletions
52
subprojects/libutil/windows/users.cc
Normal file
52
subprojects/libutil/windows/users.cc
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#include "util.hh"
|
||||
#include "users.hh"
|
||||
#include "environment-variables.hh"
|
||||
#include "file-system.hh"
|
||||
#include "windows-error.hh"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
namespace nix {
|
||||
|
||||
using namespace nix::windows;
|
||||
|
||||
std::string getUserName()
|
||||
{
|
||||
// Get the required buffer size
|
||||
DWORD size = 0;
|
||||
if (!GetUserNameA(nullptr, &size)) {
|
||||
auto lastError = GetLastError();
|
||||
if (lastError != ERROR_INSUFFICIENT_BUFFER)
|
||||
throw WinError(lastError, "cannot figure out size of user name");
|
||||
}
|
||||
|
||||
std::string name;
|
||||
// Allocate a buffer of sufficient size
|
||||
//
|
||||
// - 1 because no need for null byte
|
||||
name.resize(size - 1);
|
||||
|
||||
// Retrieve the username
|
||||
if (!GetUserNameA(&name[0], &size))
|
||||
throw WinError("cannot figure out user name");
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
Path getHome()
|
||||
{
|
||||
static Path homeDir = []()
|
||||
{
|
||||
Path homeDir = getEnv("USERPROFILE").value_or("C:\\Users\\Default");
|
||||
assert(!homeDir.empty());
|
||||
return canonPath(homeDir);
|
||||
}();
|
||||
return homeDir;
|
||||
}
|
||||
|
||||
bool isRootUser() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue