mirror of
https://github.com/NixOS/nix
synced 2025-07-06 00:51:47 +02:00
Clean up standard stream logic
Now we have enough portability stuff
This commit is contained in:
parent
0ed5af164f
commit
372353722e
9 changed files with 44 additions and 18 deletions
|
@ -106,8 +106,25 @@ void drainFD(
|
|||
#endif
|
||||
);
|
||||
|
||||
/**
|
||||
* Get [Standard Input](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin))
|
||||
*/
|
||||
[[gnu::always_inline]]
|
||||
inline Descriptor getStandardOut() {
|
||||
inline Descriptor getStandardInput()
|
||||
{
|
||||
#ifndef _WIN32
|
||||
return STDIN_FILENO;
|
||||
#else
|
||||
return GetStdHandle(STD_INPUT_HANDLE);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Get [Standard Output](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout))
|
||||
*/
|
||||
[[gnu::always_inline]]
|
||||
inline Descriptor getStandardOutput()
|
||||
{
|
||||
#ifndef _WIN32
|
||||
return STDOUT_FILENO;
|
||||
#else
|
||||
|
@ -115,6 +132,19 @@ inline Descriptor getStandardOut() {
|
|||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Get [Standard Error](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr))
|
||||
*/
|
||||
[[gnu::always_inline]]
|
||||
inline Descriptor getStandardError()
|
||||
{
|
||||
#ifndef _WIN32
|
||||
return STDERR_FILENO;
|
||||
#else
|
||||
return GetStdHandle(STD_ERROR_HANDLE);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatic cleanup of resources.
|
||||
*/
|
||||
|
|
|
@ -38,7 +38,7 @@ void Logger::warn(const std::string & msg)
|
|||
|
||||
void Logger::writeToStdout(std::string_view s)
|
||||
{
|
||||
Descriptor standard_out = getStandardOut();
|
||||
Descriptor standard_out = getStandardOutput();
|
||||
writeFull(standard_out, s);
|
||||
writeFull(standard_out, "\n");
|
||||
}
|
||||
|
@ -118,11 +118,7 @@ void writeToStderr(std::string_view s)
|
|||
{
|
||||
try {
|
||||
writeFull(
|
||||
#ifdef _WIN32
|
||||
GetStdHandle(STD_ERROR_HANDLE),
|
||||
#else
|
||||
STDERR_FILENO,
|
||||
#endif
|
||||
getStandardError(),
|
||||
s, false);
|
||||
} catch (SystemError & e) {
|
||||
/* Ignore failing writes to stderr. We need to ignore write
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue