mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 00:03:58 +01:00
Global: replaces __attribute__ to C23 [[attribute]]
This commit is contained in:
@@ -273,7 +273,7 @@ const char* ffBinaryExtractStrings(const char* machoFile, bool (*cb)(const char*
|
||||
return "Failed to stat file";
|
||||
}
|
||||
|
||||
FF_A_CLEANUP(wrapMunmap) FFMemoryMapping mapping = {
|
||||
[[gnu::cleanup(wrapMunmap)]] FFMemoryMapping mapping = {
|
||||
.data = mmap(nullptr, (size_t) st.st_size, PROT_READ, MAP_PRIVATE, fd, 0),
|
||||
.length = (size_t) st.st_size,
|
||||
};
|
||||
|
||||
@@ -82,7 +82,7 @@ void ffPrepareCommandOption(FFdata* data) {
|
||||
case 'D':
|
||||
case 'd':
|
||||
FF_IF_MODULE_MATCH(FF_DISKIO_MODULE_NAME) {
|
||||
FF_A_CLEANUP(ffDestroyDiskIOOptions) FFDiskIOOptions options;
|
||||
[[gnu::cleanup(ffDestroyDiskIOOptions)]] FFDiskIOOptions options;
|
||||
ffInitDiskIOOptions(&options);
|
||||
ffPrepareDiskIO(&options);
|
||||
}
|
||||
@@ -93,7 +93,7 @@ void ffPrepareCommandOption(FFdata* data) {
|
||||
case 'N':
|
||||
case 'n':
|
||||
FF_IF_MODULE_MATCH(FF_NETIO_MODULE_NAME) {
|
||||
FF_A_CLEANUP(ffDestroyNetIOOptions) FFNetIOOptions options;
|
||||
[[gnu::cleanup(ffDestroyNetIOOptions)]] FFNetIOOptions options;
|
||||
ffInitNetIOOptions(&options);
|
||||
ffPrepareNetIO(&options);
|
||||
}
|
||||
@@ -104,7 +104,7 @@ void ffPrepareCommandOption(FFdata* data) {
|
||||
case 'P':
|
||||
case 'p':
|
||||
FF_IF_MODULE_MATCH(FF_PUBLICIP_MODULE_NAME) {
|
||||
FF_A_CLEANUP(ffDestroyPublicIpOptions) FFPublicIPOptions options;
|
||||
[[gnu::cleanup(ffDestroyPublicIpOptions)]] FFPublicIPOptions options;
|
||||
ffInitPublicIpOptions(&options);
|
||||
ffPreparePublicIp(&options);
|
||||
}
|
||||
@@ -115,7 +115,7 @@ void ffPrepareCommandOption(FFdata* data) {
|
||||
case 'W':
|
||||
case 'w':
|
||||
FF_IF_MODULE_MATCH(FF_WEATHER_MODULE_NAME) {
|
||||
FF_A_CLEANUP(ffDestroyWeatherOptions) FFWeatherOptions options;
|
||||
[[gnu::cleanup(ffDestroyWeatherOptions)]] FFWeatherOptions options;
|
||||
ffInitWeatherOptions(&options);
|
||||
ffPrepareWeather(&options);
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ static inline bool formatArgSet(const FFformatarg* arg) {
|
||||
return arg->value != nullptr && ((arg->type == FF_ARG_TYPE_DOUBLE && *(double*) arg->value > 0.0) || (arg->type == FF_ARG_TYPE_FLOAT && *(float*) arg->value > 0.0) || (arg->type == FF_ARG_TYPE_INT && *(int32_t*) arg->value > 0) || (arg->type == FF_ARG_TYPE_STRBUF && ((FFstrbuf*) arg->value)->length > 0) || (arg->type == FF_ARG_TYPE_STRING && ffStrSet((char*) arg->value)) || (arg->type == FF_ARG_TYPE_UINT8 && *(uint8_t*) arg->value > 0) || (arg->type == FF_ARG_TYPE_UINT16 && *(uint16_t*) arg->value > 0) || (arg->type == FF_ARG_TYPE_UINT && *(uint32_t*) arg->value > 0) || (arg->type == FF_ARG_TYPE_UINT64 && *(uint64_t*) arg->value > 0) || (arg->type == FF_ARG_TYPE_BOOL && *(bool*) arg->value) || (arg->type == FF_ARG_TYPE_LIST && ((FFlist*) arg->value)->length > 0));
|
||||
}
|
||||
|
||||
FF_A_UNUSED static inline void normalizeArgName(FFstrbuf* dst, const char* src) {
|
||||
[[maybe_unused]] static inline void normalizeArgName(FFstrbuf* dst, const char* src) {
|
||||
ffStrbufClear(dst);
|
||||
bool flag = false;
|
||||
for (const char* p = src; *p; ++p) {
|
||||
|
||||
@@ -105,12 +105,12 @@ static void resetConsole(void) {
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
BOOL WINAPI consoleHandler(FF_A_UNUSED DWORD signal) {
|
||||
BOOL WINAPI consoleHandler([[maybe_unused]] DWORD signal) {
|
||||
resetConsole();
|
||||
exit(0);
|
||||
}
|
||||
#else
|
||||
static void exitSignalHandler(FF_A_UNUSED int signal) {
|
||||
static void exitSignalHandler([[maybe_unused]] int signal) {
|
||||
resetConsole();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data) {
|
||||
int openFlagsModes = O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC;
|
||||
mode_t openFlagsRights = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
|
||||
|
||||
int FF_AUTO_CLOSE_FD fd = open(fileName, openFlagsModes, openFlagsRights);
|
||||
FF_AUTO_CLOSE_FD int fd = open(fileName, openFlagsModes, openFlagsRights);
|
||||
if (fd == -1) {
|
||||
if (errno == ENOENT) {
|
||||
createSubfolders(fileName);
|
||||
|
||||
@@ -157,7 +157,7 @@ bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data) {
|
||||
}
|
||||
}
|
||||
|
||||
HANDLE FF_AUTO_CLOSE_FD handle = CreateFileW(fileNameW, GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
FF_AUTO_CLOSE_FD HANDLE handle = CreateFileW(fileNameW, GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
if (handle == INVALID_HANDLE_VALUE) {
|
||||
if (GetLastError() == ERROR_PATH_NOT_FOUND) {
|
||||
if (!createSubfolders(fileNameW)) {
|
||||
|
||||
@@ -139,7 +139,7 @@ static void prepareModuleJsonObject(const char* type, yyjson_val* module) {
|
||||
if (ffStrEqualsIgnCase(type, FF_CPUUSAGE_MODULE_NAME)) {
|
||||
ffPrepareCPUUsage();
|
||||
} else if (ffStrEqualsIgnCase(type, FF_COMMAND_MODULE_NAME)) {
|
||||
FF_A_CLEANUP(ffDestroyCommandOptions) FFCommandOptions options;
|
||||
[[gnu::cleanup(ffDestroyCommandOptions)]] FFCommandOptions options;
|
||||
ffInitCommandOptions(&options);
|
||||
if (module) {
|
||||
ffCommandModuleInfo.parseJsonObject(&options, module);
|
||||
@@ -154,7 +154,7 @@ static void prepareModuleJsonObject(const char* type, yyjson_val* module) {
|
||||
case 'd':
|
||||
case 'D': {
|
||||
if (ffStrEqualsIgnCase(type, FF_DISKIO_MODULE_NAME)) {
|
||||
FF_A_CLEANUP(ffDestroyDiskIOOptions) FFDiskIOOptions options;
|
||||
[[gnu::cleanup(ffDestroyDiskIOOptions)]] FFDiskIOOptions options;
|
||||
ffInitDiskIOOptions(&options);
|
||||
if (module) {
|
||||
ffDiskIOModuleInfo.parseJsonObject(&options, module);
|
||||
@@ -169,7 +169,7 @@ static void prepareModuleJsonObject(const char* type, yyjson_val* module) {
|
||||
case 'n':
|
||||
case 'N': {
|
||||
if (ffStrEqualsIgnCase(type, FF_NETIO_MODULE_NAME)) {
|
||||
FF_A_CLEANUP(ffDestroyNetIOOptions) FFNetIOOptions options;
|
||||
[[gnu::cleanup(ffDestroyNetIOOptions)]] FFNetIOOptions options;
|
||||
ffInitNetIOOptions(&options);
|
||||
if (module) {
|
||||
ffNetIOModuleInfo.parseJsonObject(&options, module);
|
||||
@@ -184,7 +184,7 @@ static void prepareModuleJsonObject(const char* type, yyjson_val* module) {
|
||||
case 'p':
|
||||
case 'P': {
|
||||
if (ffStrEqualsIgnCase(type, FF_PUBLICIP_MODULE_NAME)) {
|
||||
FF_A_CLEANUP(ffDestroyPublicIpOptions) FFPublicIPOptions options;
|
||||
[[gnu::cleanup(ffDestroyPublicIpOptions)]] FFPublicIPOptions options;
|
||||
ffInitPublicIpOptions(&options);
|
||||
if (module) {
|
||||
ffPublicIPModuleInfo.parseJsonObject(&options, module);
|
||||
@@ -199,7 +199,7 @@ static void prepareModuleJsonObject(const char* type, yyjson_val* module) {
|
||||
case 'w':
|
||||
case 'W': {
|
||||
if (ffStrEqualsIgnCase(type, FF_WEATHER_MODULE_NAME)) {
|
||||
FF_A_CLEANUP(ffDestroyWeatherOptions) FFWeatherOptions options;
|
||||
[[gnu::cleanup(ffDestroyWeatherOptions)]] FFWeatherOptions options;
|
||||
ffInitWeatherOptions(&options);
|
||||
if (module) {
|
||||
ffWeatherModuleInfo.parseJsonObject(&options, module);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <sys/module.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
typedef struct FF_A_PACKED FFNbsdModList {
|
||||
typedef struct [[gnu::packed]] FFNbsdModList {
|
||||
int len;
|
||||
modstat_t mods[];
|
||||
} FFNbsdModList;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "common/kmod.h"
|
||||
|
||||
bool ffKmodLoaded(FF_A_UNUSED const char* modName) {
|
||||
bool ffKmodLoaded([[maybe_unused]] const char* modName) {
|
||||
return true; // Don't generate kernel module related errors
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ void* ffLibraryLoadMulti(const char* path, int maxVersion, ...) {
|
||||
|
||||
#if _WIN32
|
||||
|
||||
void* dlopen(const char* path, FF_A_UNUSED int mode) {
|
||||
void* dlopen(const char* path, [[maybe_unused]] int mode) {
|
||||
wchar_t pathW[MAX_PATH + 1];
|
||||
ULONG pathWBytes = 0;
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ bool ffNetifGetDefaultRouteImplV4(FFNetifDefaultRouteResult* result) {
|
||||
|
||||
uint32_t pid = ffNetifGetNetlinkPortId(sock_fd);
|
||||
|
||||
struct FF_A_PACKED {
|
||||
struct [[gnu::packed]] {
|
||||
struct nlmsghdr nlh;
|
||||
struct rtmsg rtm;
|
||||
struct rtattr rta;
|
||||
@@ -97,7 +97,7 @@ bool ffNetifGetDefaultRouteImplV4(FFNetifDefaultRouteResult* result) {
|
||||
|
||||
uint8_t buffer[1024 * 16]; // 16 KB buffer should be sufficient
|
||||
uint32_t minMetric = UINT32_MAX;
|
||||
FF_A_UNUSED int routeCount = 0;
|
||||
[[maybe_unused]] int routeCount = 0;
|
||||
|
||||
while (true) {
|
||||
ssize_t received = recvfrom(sock_fd, buffer, sizeof(buffer), 0, (struct sockaddr*) &src_addr, &src_addr_len);
|
||||
@@ -254,7 +254,7 @@ bool ffNetifGetDefaultRouteImplV6(FFNetifDefaultRouteResult* result) {
|
||||
|
||||
uint32_t pid = ffNetifGetNetlinkPortId(sock_fd);
|
||||
|
||||
struct FF_A_PACKED {
|
||||
struct [[gnu::packed]] {
|
||||
struct nlmsghdr nlh;
|
||||
struct rtmsg rtm;
|
||||
struct rtattr rta;
|
||||
@@ -307,7 +307,7 @@ bool ffNetifGetDefaultRouteImplV6(FFNetifDefaultRouteResult* result) {
|
||||
|
||||
uint8_t buffer[1024 * 16]; // 16 KB buffer should be sufficient
|
||||
uint32_t minMetric = UINT32_MAX;
|
||||
FF_A_UNUSED int routeCount = 0;
|
||||
[[maybe_unused]] int routeCount = 0;
|
||||
|
||||
while (true) {
|
||||
ssize_t received = recvfrom(sock_fd, buffer, sizeof(buffer), 0, (struct sockaddr*) &src_addr, &src_addr_len);
|
||||
@@ -382,7 +382,7 @@ bool ffNetifGetDefaultRouteImplV6(FFNetifDefaultRouteResult* result) {
|
||||
switch (rta->rta_type) {
|
||||
case RTA_DST:
|
||||
if (RTA_PAYLOAD(rta) >= sizeof(struct in6_addr)) {
|
||||
FF_A_UNUSED char str[INET6_ADDRSTRLEN];
|
||||
[[maybe_unused]] char str[INET6_ADDRSTRLEN];
|
||||
FF_DEBUG("Unexpected RTA_DST: %s", inet_ntop(AF_INET6, RTA_DATA(rta), str, sizeof(str)));
|
||||
goto next;
|
||||
}
|
||||
@@ -399,7 +399,7 @@ bool ffNetifGetDefaultRouteImplV6(FFNetifDefaultRouteResult* result) {
|
||||
if (IN6_IS_ADDR_UNSPECIFIED(gw)) {
|
||||
goto next;
|
||||
}
|
||||
FF_A_UNUSED char str[INET6_ADDRSTRLEN];
|
||||
[[maybe_unused]] char str[INET6_ADDRSTRLEN];
|
||||
FF_DEBUG("Found gateway: %s", inet_ntop(AF_INET6, gw, str, sizeof(str)));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -261,7 +261,7 @@ static const char* initNetworkingState(FFNetworkingState* state, const char* hos
|
||||
|
||||
if (state->timeout > 0) {
|
||||
FF_DEBUG("Setting connection timeout: %u ms", state->timeout);
|
||||
FF_A_UNUSED uint32_t sec = state->timeout / 1000;
|
||||
[[maybe_unused]] uint32_t sec = state->timeout / 1000;
|
||||
if (sec == 0) {
|
||||
sec = 1;
|
||||
}
|
||||
@@ -417,7 +417,7 @@ const char* ffNetworkingRecvHttpResponse(FFNetworkingState* state, FFstrbuf* buf
|
||||
}
|
||||
|
||||
FF_DEBUG("Starting data reception");
|
||||
FF_A_UNUSED int recvCount = 0;
|
||||
[[maybe_unused]] int recvCount = 0;
|
||||
uint32_t contentLength = 0;
|
||||
uint32_t headerEnd = 0;
|
||||
|
||||
|
||||
@@ -275,7 +275,7 @@ const char* ffNetworkingRecvHttpResponse(FFNetworkingState* state, FFstrbuf* buf
|
||||
}
|
||||
|
||||
FF_DEBUG("Starting data reception");
|
||||
FF_A_UNUSED int recvCount = 0;
|
||||
[[maybe_unused]] int recvCount = 0;
|
||||
uint32_t contentLength = 0;
|
||||
uint32_t headerEnd = 0;
|
||||
|
||||
|
||||
@@ -603,7 +603,7 @@ bool ffSettingsGetEnlightenmentProperty(ffEnlightenmentSettings* result) {
|
||||
return !!parsed;
|
||||
}
|
||||
#else
|
||||
bool ffSettingsGetEnlightenmentProperty(FF_A_UNUSED ffEnlightenmentSettings* result) {
|
||||
bool ffSettingsGetEnlightenmentProperty([[maybe_unused]] ffEnlightenmentSettings* result) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -66,7 +66,7 @@ static bool parseSmbiosTable(const uint8_t* data, uint32_t length) {
|
||||
const FFSmbiosHeader* endOfTable = nullptr;
|
||||
|
||||
FF_DEBUG("Parsing SMBIOS table structures with length %u bytes", length);
|
||||
FF_A_UNUSED int structureCount = 0, totalCount = 0;
|
||||
[[maybe_unused]] int structureCount = 0, totalCount = 0;
|
||||
for (
|
||||
const FFSmbiosHeader* header = (const FFSmbiosHeader*) data;
|
||||
(const uint8_t*) header + sizeof(FFSmbiosHeader) < (const uint8_t*) data + length;
|
||||
@@ -228,7 +228,7 @@ static bool readPhysicalMemory(int fd, off_t address, size_t length, void* buffe
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef struct FFSmbios20EntryPoint {
|
||||
typedef struct [[gnu::packed]] FFSmbios20EntryPoint {
|
||||
uint8_t AnchorString[4];
|
||||
uint8_t EntryPointStructureChecksum;
|
||||
uint8_t EntryPointLength;
|
||||
@@ -243,11 +243,11 @@ typedef struct FFSmbios20EntryPoint {
|
||||
uint32_t StructureTableAddress;
|
||||
uint16_t NumberOfSmbiosStructures;
|
||||
uint8_t SmbiosBcdRevision;
|
||||
} FF_A_PACKED FFSmbios20EntryPoint;
|
||||
} FFSmbios20EntryPoint;
|
||||
static_assert(offsetof(FFSmbios20EntryPoint, SmbiosBcdRevision) == 0x1E,
|
||||
"FFSmbios20EntryPoint: Wrong struct alignment");
|
||||
|
||||
typedef struct FFSmbios30EntryPoint {
|
||||
typedef struct [[gnu::packed]] FFSmbios30EntryPoint {
|
||||
uint8_t AnchorString[5];
|
||||
uint8_t EntryPointStructureChecksum;
|
||||
uint8_t EntryPointLength;
|
||||
@@ -258,7 +258,7 @@ typedef struct FFSmbios30EntryPoint {
|
||||
uint8_t Reversed;
|
||||
uint32_t StructureTableMaximumSize;
|
||||
uint64_t StructureTableAddress;
|
||||
} FF_A_PACKED FFSmbios30EntryPoint;
|
||||
} FFSmbios30EntryPoint;
|
||||
|
||||
static_assert(offsetof(FFSmbios30EntryPoint, StructureTableAddress) == 0x10,
|
||||
"FFSmbios30EntryPoint: Wrong struct alignment");
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "common/strutil.h"
|
||||
#include "common/wcwidth.h"
|
||||
|
||||
uint8_t ffUtf8CharLenWidth(const char* str, uint32_t length, uint8_t* width) {
|
||||
if (__builtin_expect(length == 0 || *str == '\0', false)) {
|
||||
|
||||
@@ -89,7 +89,7 @@ FFTimeGetAgeResult ffTimeGetAge(uint64_t birthMs, uint64_t nowMs) {
|
||||
#ifdef _WIN32
|
||||
double ffQpcMultiplier;
|
||||
|
||||
__attribute__((constructor)) static void ffTimeInitQpcMultiplier(void) {
|
||||
[[gnu::constructor]] static void ffTimeInitQpcMultiplier(void) {
|
||||
LARGE_INTEGER frequency;
|
||||
RtlQueryPerformanceFrequency(&frequency);
|
||||
ffQpcMultiplier = 1000. / (double) frequency.QuadPart;
|
||||
|
||||
@@ -30,7 +30,7 @@ static struct trace_event {
|
||||
} events[4 * 1024 * 1024]; // 4M events, 96 MiB memory usage
|
||||
static _Atomic uint32_t event_count;
|
||||
|
||||
__attribute__((no_instrument_function, always_inline)) static inline uint64_t get_time_us() {
|
||||
[[gnu::no_instrument_function, gnu::always_inline]] static inline uint64_t get_time_us() {
|
||||
#if !_WIN32
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
@@ -43,12 +43,12 @@ __attribute__((no_instrument_function, always_inline)) static inline uint64_t ge
|
||||
}
|
||||
|
||||
#if _WIN32
|
||||
__attribute__((constructor, no_instrument_function)) void trace_init() {
|
||||
[[gnu::constructor, gnu::no_instrument_function]] void trace_init() {
|
||||
QueryPerformanceFrequency(&freq);
|
||||
}
|
||||
#endif
|
||||
|
||||
__attribute__((destructor, no_instrument_function)) void trace_fini() {
|
||||
[[gnu::destructor, gnu::no_instrument_function]] void trace_fini() {
|
||||
#if _WIN32
|
||||
uint32_t pid = (uint32_t) GetCurrentProcessId();
|
||||
#else
|
||||
@@ -115,7 +115,7 @@ __attribute__((destructor, no_instrument_function)) void trace_fini() {
|
||||
#endif
|
||||
}
|
||||
|
||||
__attribute__((no_instrument_function)) static void write_event(void* this_fn, bool is_exit) {
|
||||
[[gnu::no_instrument_function]] static void write_event(void* this_fn, bool is_exit) {
|
||||
uint32_t idx = atomic_fetch_add_explicit(&event_count, 1, memory_order_relaxed);
|
||||
if (__builtin_expect(idx >= sizeof(events) / sizeof(events[0]), false)) {
|
||||
abort();
|
||||
@@ -137,12 +137,12 @@ __attribute__((no_instrument_function)) static void write_event(void* this_fn, b
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((no_instrument_function)) void __cyg_profile_func_enter(void* this_fn, void* call_site) {
|
||||
[[gnu::no_instrument_function]] void __cyg_profile_func_enter(void* this_fn, void* call_site) {
|
||||
(void) call_site;
|
||||
write_event(this_fn, false);
|
||||
}
|
||||
|
||||
__attribute__((no_instrument_function)) void __cyg_profile_func_exit(void* this_fn, void* call_site) {
|
||||
[[gnu::no_instrument_function]] void __cyg_profile_func_exit(void* this_fn, void* call_site) {
|
||||
(void) call_site;
|
||||
write_event(this_fn, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user