mirror of
https://github.com/Atmosphere-NX/Atmosphere-libs.git
synced 2025-06-21 11:02:45 +02:00
libstrat: remove sizeof() /sizeof([0])
This commit is contained in:
parent
d6eacecce9
commit
c9dc24cce1
@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <iterator>
|
||||
|
||||
/* Any broadly useful language defines should go here. */
|
||||
|
||||
@ -28,3 +29,22 @@
|
||||
|
||||
#define ALIGNED(algn) __attribute__((aligned(algn)))
|
||||
#define WEAK __attribute__((weak))
|
||||
|
||||
namespace sts::util {
|
||||
|
||||
/* std::size() does not support zero-size C arrays. We're fixing that. */
|
||||
template<class C>
|
||||
constexpr auto size(const C& c) -> decltype(c.size()) {
|
||||
return std::size(c);
|
||||
}
|
||||
|
||||
template<class C>
|
||||
constexpr std::size_t size(const C& c) {
|
||||
if constexpr (sizeof(C) == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return std::size(c);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -30,7 +30,7 @@ namespace sts::cfg {
|
||||
sm::ServiceName::Encode("pinmux"),
|
||||
sm::ServiceName::Encode("psc:c")
|
||||
};
|
||||
constexpr size_t NumRequiredServicesForSdCardAccess = sizeof(RequiredServicesForSdCardAccess) / sizeof(RequiredServicesForSdCardAccess[0]);
|
||||
constexpr size_t NumRequiredServicesForSdCardAccess = util::size(RequiredServicesForSdCardAccess);
|
||||
|
||||
/* SD card globals. */
|
||||
HosMutex g_sd_card_lock;
|
||||
|
@ -67,12 +67,12 @@ namespace sts::updater {
|
||||
case BootImageUpdateType::Erista:
|
||||
{
|
||||
constexpr const char *candidates[] = {BctPathNx};
|
||||
return ChooseCandidatePath(candidates, sizeof(candidates) / sizeof(candidates[0]));
|
||||
return ChooseCandidatePath(candidates, util::size(candidates));
|
||||
}
|
||||
case BootImageUpdateType::Mariko:
|
||||
{
|
||||
constexpr const char *candidates[] = {BctPathA, BctPathNx};
|
||||
return ChooseCandidatePath(candidates, sizeof(candidates) / sizeof(candidates[0]));
|
||||
return ChooseCandidatePath(candidates, util::size(candidates));
|
||||
}
|
||||
default:
|
||||
std::abort();
|
||||
@ -84,12 +84,12 @@ namespace sts::updater {
|
||||
case BootImageUpdateType::Erista:
|
||||
{
|
||||
constexpr const char *candidates[] = {Package1PathNx};
|
||||
return ChooseCandidatePath(candidates, sizeof(candidates) / sizeof(candidates[0]));
|
||||
return ChooseCandidatePath(candidates, util::size(candidates));
|
||||
}
|
||||
case BootImageUpdateType::Mariko:
|
||||
{
|
||||
constexpr const char *candidates[] = {Package1PathA, Package1PathNx};
|
||||
return ChooseCandidatePath(candidates, sizeof(candidates) / sizeof(candidates[0]));
|
||||
return ChooseCandidatePath(candidates, util::size(candidates));
|
||||
}
|
||||
default:
|
||||
std::abort();
|
||||
@ -101,12 +101,12 @@ namespace sts::updater {
|
||||
case BootImageUpdateType::Erista:
|
||||
{
|
||||
constexpr const char *candidates[] = {Package2PathNx};
|
||||
return ChooseCandidatePath(candidates, sizeof(candidates) / sizeof(candidates[0]));
|
||||
return ChooseCandidatePath(candidates, util::size(candidates));
|
||||
}
|
||||
case BootImageUpdateType::Mariko:
|
||||
{
|
||||
constexpr const char *candidates[] = {Package2PathA, Package2PathNx};
|
||||
return ChooseCandidatePath(candidates, sizeof(candidates) / sizeof(candidates[0]));
|
||||
return ChooseCandidatePath(candidates, util::size(candidates));
|
||||
}
|
||||
default:
|
||||
std::abort();
|
||||
|
Loading…
Reference in New Issue
Block a user