Skip to content

Commit

Permalink
system/Error: remove unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Aug 4, 2023
1 parent 6c8449e commit c13e7d6
Showing 1 changed file with 1 addition and 71 deletions.
72 changes: 1 addition & 71 deletions src/system/Error.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,10 @@
#include <system_error> // IWYU pragma: export
#include <utility>

#include <stdio.h>

template<typename... Args>
static inline std::system_error
FormatSystemError(std::error_code code, const char *fmt,
Args&&... args) noexcept
{
char buffer[1024];
snprintf(buffer, sizeof(buffer), fmt, std::forward<Args>(args)...);
return std::system_error(code, buffer);
}

#ifdef _WIN32

#include <errhandlingapi.h> // for GetLastError()
#include <windef.h> // for HWND (needed by winbase.h)
#include <winbase.h> // for FormatMessageA()
#include <winerror.h>

/**
* Returns the error_category to be used to wrap WIN32 GetLastError()
Expand Down Expand Up @@ -59,38 +46,10 @@ MakeLastError(const char *msg) noexcept
return MakeLastError(GetLastError(), msg);
}

template<typename... Args>
static inline std::system_error
FormatLastError(DWORD code, const char *fmt, Args&&... args) noexcept
{
char buffer[512];
const auto end = buffer + sizeof(buffer);
size_t length = snprintf(buffer, sizeof(buffer) - 128,
fmt, std::forward<Args>(args)...);
char *p = buffer + length;
*p++ = ':';
*p++ = ' ';

FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, code, 0, p, end - p, nullptr);
return MakeLastError(code, buffer);
}

template<typename... Args>
static inline std::system_error
FormatLastError(const char *fmt, Args&&... args) noexcept
{
return FormatLastError(GetLastError(), fmt,
std::forward<Args>(args)...);
}

#endif /* _WIN32 */

#include <cerrno> // IWYU pragma: export

#include <string.h>

/**
* Returns the error_category to be used to wrap errno values. The
* C++ standard does not define this well, so this code is based on
Expand Down Expand Up @@ -127,35 +86,6 @@ MakeErrno(const char *msg) noexcept
return MakeErrno(errno, msg);
}

template<typename... Args>
static inline std::system_error
FormatErrno(int code, const char *fmt, Args&&... args) noexcept
{
char buffer[512];
snprintf(buffer, sizeof(buffer),
fmt, std::forward<Args>(args)...);
return MakeErrno(code, buffer);
}

template<typename... Args>
static inline std::system_error
FormatErrno(const char *fmt, Args&&... args) noexcept
{
return FormatErrno(errno, fmt, std::forward<Args>(args)...);
}

template<typename... Args>
static inline std::system_error
FormatFileNotFound(const char *fmt, Args&&... args) noexcept
{
#ifdef _WIN32
return FormatLastError(ERROR_FILE_NOT_FOUND, fmt,
std::forward<Args>(args)...);
#else
return FormatErrno(ENOENT, fmt, std::forward<Args>(args)...);
#endif
}

[[gnu::pure]]
inline bool
IsErrno(const std::system_error &e, int code) noexcept
Expand Down

0 comments on commit c13e7d6

Please sign in to comment.