mirror of
https://github.com/NixOS/nix
synced 2025-07-05 20:41:47 +02:00
Put some file descriptor functions in unix and windows namespaces
It is misleading when platform-specific functions are in the overall `nix` namespace. More namespaces also makes for nicer doxygen.
This commit is contained in:
parent
afdd12be5e
commit
ff87c1a318
7 changed files with 19 additions and 15 deletions
|
@ -140,6 +140,7 @@ public:
|
|||
};
|
||||
|
||||
#ifndef _WIN32 // Not needed on Windows, where we don't fork
|
||||
namespace unix {
|
||||
|
||||
/**
|
||||
* Close all file descriptors except those listed in the given set.
|
||||
|
@ -152,13 +153,16 @@ void closeMostFDs(const std::set<Descriptor> & exceptions);
|
|||
*/
|
||||
void closeOnExec(Descriptor fd);
|
||||
|
||||
} // namespace unix
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
# if _WIN32_WINNT >= 0x0600
|
||||
#if defined(_WIN32) && _WIN32_WINNT >= 0x0600
|
||||
namespace windows (
|
||||
|
||||
Path handleToPath(Descriptor handle);
|
||||
std::wstring handleToFileName(Descriptor handle);
|
||||
# endif
|
||||
|
||||
} // namespace windows
|
||||
#endif
|
||||
|
||||
MakeError(EndOfFile, Error);
|
||||
|
|
|
@ -546,7 +546,7 @@ std::pair<AutoCloseFD, Path> createTempFile(const Path & prefix)
|
|||
if (!fd)
|
||||
throw SysError("creating temporary file '%s'", tmpl);
|
||||
#ifndef _WIN32
|
||||
closeOnExec(fd.get());
|
||||
unix::closeOnExec(fd.get());
|
||||
#endif
|
||||
return {std::move(fd), tmpl};
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ AutoCloseFD createUnixDomainSocket()
|
|||
if (!fdSocket)
|
||||
throw SysError("cannot create Unix domain socket");
|
||||
#ifndef _WIN32
|
||||
closeOnExec(fdSocket.get());
|
||||
unix::closeOnExec(fdSocket.get());
|
||||
#endif
|
||||
return fdSocket;
|
||||
}
|
||||
|
|
|
@ -110,8 +110,8 @@ void Pipe::create()
|
|||
if (pipe2(fds, O_CLOEXEC) != 0) throw SysError("creating pipe");
|
||||
#else
|
||||
if (pipe(fds) != 0) throw SysError("creating pipe");
|
||||
closeOnExec(fds[0]);
|
||||
closeOnExec(fds[1]);
|
||||
unix::closeOnExec(fds[0]);
|
||||
unix::closeOnExec(fds[1]);
|
||||
#endif
|
||||
readSide = fds[0];
|
||||
writeSide = fds[1];
|
||||
|
@ -120,7 +120,7 @@ void Pipe::create()
|
|||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
void closeMostFDs(const std::set<int> & exceptions)
|
||||
void unix::closeMostFDs(const std::set<int> & exceptions)
|
||||
{
|
||||
#if __linux__
|
||||
try {
|
||||
|
@ -146,7 +146,7 @@ void closeMostFDs(const std::set<int> & exceptions)
|
|||
}
|
||||
|
||||
|
||||
void closeOnExec(int fd)
|
||||
void unix::closeOnExec(int fd)
|
||||
{
|
||||
int prev;
|
||||
if ((prev = fcntl(fd, F_GETFD, 0)) == -1 ||
|
||||
|
|
|
@ -122,7 +122,7 @@ void Pipe::create()
|
|||
|
||||
#if _WIN32_WINNT >= 0x0600
|
||||
|
||||
std::wstring handleToFileName(HANDLE handle) {
|
||||
std::wstring windows::handleToFileName(HANDLE handle) {
|
||||
std::vector<wchar_t> buf(0x100);
|
||||
DWORD dw = GetFinalPathNameByHandleW(handle, buf.data(), buf.size(), FILE_NAME_OPENED);
|
||||
if (dw == 0) {
|
||||
|
@ -141,7 +141,7 @@ std::wstring handleToFileName(HANDLE handle) {
|
|||
}
|
||||
|
||||
|
||||
Path handleToPath(HANDLE handle) {
|
||||
Path windows::handleToPath(HANDLE handle) {
|
||||
return os_string_to_string(handleToFileName(handle));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue