1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-07 01:21:00 +01:00
nix/src/libutil/windows/windows-error.cc
Graham Christensen e4f62e4608 Apply clang-format universally.
* It is tough to contribute to a project that doesn't use a formatter,
* It is extra hard to contribute to a project which has configured the formatter, but ignores it for some files
* Code formatting makes it harder to hide obscure / weird bugs by accident or on purpose,

Let's rip the bandaid off?

Note that PRs currently in flight should be able to be merged relatively easily by applying `clang-format` to their tip prior to merge.
2025-07-18 12:47:27 -04:00

34 lines
1.1 KiB
C++

#ifdef _WIN32
# include "nix/util/windows-error.hh"
# include <error.h>
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
namespace nix::windows {
std::string WinError::renderError(DWORD lastError)
{
LPSTR errorText = NULL;
FormatMessageA(
FORMAT_MESSAGE_FROM_SYSTEM // use system message tables to retrieve error text
| FORMAT_MESSAGE_ALLOCATE_BUFFER // allocate buffer on local heap for error text
| FORMAT_MESSAGE_IGNORE_INSERTS, // Important! will fail otherwise, since we're not (and CANNOT) pass
// insertion parameters
NULL, // unused with FORMAT_MESSAGE_FROM_SYSTEM
lastError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &errorText, // output
0, // minimum size for output buffer
NULL); // arguments - see note
if (NULL != errorText) {
std::string s2{errorText};
LocalFree(errorText);
return s2;
}
return fmt("CODE=%d", lastError);
}
} // namespace nix::windows
#endif