Debian Codegraph @

Utilities/KWSys/Status.cxx

raw
1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
3 #include "kwsysPrivate.h"
4 #include KWSYS_HEADER(Status.hxx)
5
6 // Work-around CMake dependency scanning limitation. This must
7 // duplicate the above list of headers.
8 #if 0
9 # include "Status.hxx.in"
10 #endif
11
12 #include <cerrno>
13 #include <cstring>
14 #include <string>
15
16 #if defined(_WIN32)
17 # include <windows.h>
18 #endif
19
20 namespace KWSYS_NAMESPACE {
21
22 Status Status::POSIX_errno()
23 {
24 return Status::POSIX(errno);
25 }
26
27 #ifdef _WIN32
28 Status Status::Windows_GetLastError()
29 {
30 return Status::Windows(GetLastError());
31 }
32 #endif
33
34 std::string Status::GetString() const
35 {
36 std::string err;
37 switch (this->Kind_) {
38 case Kind::Success:
39 err = "Success";
40 break;
41 case Kind::POSIX:
42 err = strerror(this->POSIX_);
43 break;
44 #ifdef _WIN32
45 case Kind::Windows: {
46 LPSTR message = NULL;
47 DWORD size = FormatMessageA(
48 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
49 FORMAT_MESSAGE_IGNORE_INSERTS,
50 NULL, this->Windows_, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
51 (LPSTR)&message, 0, NULL);
52 err = std::string(message, size);
53 LocalFree(message);
54 } break;
55 #endif
56 }
57 return err;
58 }
59
60 } // namespace KWSYS_NAMESPACE