mirror of
https://github.com/transmission/transmission.git
synced 2026-04-19 08:20:22 +01:00
fix: bugprone-narrowing-conversions surrounding error codes (#8716)
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <cstdint>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
@@ -17,6 +18,14 @@
|
||||
#define TR_ERROR_EINVAL ERROR_INVALID_PARAMETER
|
||||
#define TR_ERROR_EISDIR ERROR_DIRECTORY_NOT_SUPPORTED
|
||||
|
||||
// Smallest integer type that can represent all values returned
|
||||
// by `DWORD GetLastError()` and `int WSAGetLastError()`.
|
||||
//
|
||||
// N.B. DWORD is an unsigned 32-bit integer, so int64_t is the next
|
||||
// smallest signed integer type that can represent all its values.
|
||||
using tr_error_code_t = int64_t;
|
||||
static_assert(sizeof(int) <= sizeof(int64_t));
|
||||
|
||||
#else /* _WIN32 */
|
||||
|
||||
#include <cerrno>
|
||||
@@ -24,9 +33,11 @@
|
||||
#define TR_ERROR_EINVAL EINVAL
|
||||
#define TR_ERROR_EISDIR EISDIR
|
||||
|
||||
using tr_error_code_t = int;
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
constexpr bool tr_error_is_enoent(int code) noexcept
|
||||
constexpr bool tr_error_is_enoent(tr_error_code_t code) noexcept
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return code == ERROR_FILE_NOT_FOUND || code == ERROR_PATH_NOT_FOUND;
|
||||
@@ -35,7 +46,7 @@ constexpr bool tr_error_is_enoent(int code) noexcept
|
||||
#endif
|
||||
}
|
||||
|
||||
constexpr bool tr_error_is_enospc(int code) noexcept
|
||||
constexpr bool tr_error_is_enospc(tr_error_code_t code) noexcept
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return code == ERROR_DISK_FULL;
|
||||
|
||||
Reference in New Issue
Block a user