mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-06 13:14:21 +01:00
Global: replaces __attribute__ to C23 [[attribute]]
This commit is contained in:
+6
-8
@@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/attributes.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
@@ -32,24 +30,24 @@ static inline void ffListInitA(FFlist* list, uint32_t elementSize, uint32_t capa
|
||||
list->data = __builtin_expect(capacity == 0, 0) ? nullptr : (uint8_t*) malloc((size_t) capacity * elementSize);
|
||||
}
|
||||
|
||||
FF_A_NODISCARD static inline FFlist ffListCreate() {
|
||||
[[nodiscard]] static inline FFlist ffListCreate() {
|
||||
FFlist result;
|
||||
ffListInit(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
FF_A_NODISCARD static inline FFlist ffListCreateA(uint32_t elementSize, uint32_t capacity) {
|
||||
[[nodiscard]] static inline FFlist ffListCreateA(uint32_t elementSize, uint32_t capacity) {
|
||||
FFlist result;
|
||||
ffListInitA(&result, elementSize, capacity);
|
||||
return result;
|
||||
}
|
||||
|
||||
FF_A_NODISCARD static inline void* ffListGet(const FFlist* list, uint32_t elementSize, uint32_t index) {
|
||||
[[nodiscard]] static inline void* ffListGet(const FFlist* list, uint32_t elementSize, uint32_t index) {
|
||||
assert(list->capacity > index);
|
||||
return list->data + (index * elementSize);
|
||||
}
|
||||
|
||||
FF_A_NODISCARD static inline uint32_t ffListFirstIndexComp(const FFlist* list, uint32_t elementSize, void* compElement, bool (*compFunc)(const void*, const void*)) {
|
||||
[[nodiscard]] static inline uint32_t ffListFirstIndexComp(const FFlist* list, uint32_t elementSize, void* compElement, bool (*compFunc)(const void*, const void*)) {
|
||||
for (uint32_t i = 0; i < list->length; i++) {
|
||||
if (compFunc(ffListGet(list, elementSize, i), compElement)) {
|
||||
return i;
|
||||
@@ -59,7 +57,7 @@ FF_A_NODISCARD static inline uint32_t ffListFirstIndexComp(const FFlist* list, u
|
||||
return list->length;
|
||||
}
|
||||
|
||||
FF_A_NODISCARD static inline bool ffListContains(const FFlist* list, uint32_t elementSize, void* compElement, bool (*compFunc)(const void*, const void*)) {
|
||||
[[nodiscard]] static inline bool ffListContains(const FFlist* list, uint32_t elementSize, void* compElement, bool (*compFunc)(const void*, const void*)) {
|
||||
return ffListFirstIndexComp(list, elementSize, compElement, compFunc) != list->length;
|
||||
}
|
||||
|
||||
@@ -117,7 +115,7 @@ static inline void* ffListAdd(FFlist* list, uint32_t elementSize) {
|
||||
itemVarName - (itemType*) (listVar).data < (intptr_t) (listVar).length; \
|
||||
++itemVarName)
|
||||
|
||||
#define FF_LIST_AUTO_DESTROY FFlist FF_A_CLEANUP(ffListDestroy)
|
||||
#define FF_LIST_AUTO_DESTROY [[gnu::cleanup(ffListDestroy)]] FFlist
|
||||
|
||||
#define FF_LIST_GET(itemType, listVar, index) \
|
||||
({ \
|
||||
|
||||
+52
-54
@@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/attributes.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
@@ -37,15 +35,15 @@ static inline void ffStrbufInit(FFstrbuf* strbuf);
|
||||
void ffStrbufInitA(FFstrbuf* strbuf, uint32_t allocate);
|
||||
void ffStrbufInitVF(FFstrbuf* strbuf, const char* format, va_list arguments);
|
||||
void ffStrbufInitMoveNS(FFstrbuf* strbuf, uint32_t length, char* heapStr);
|
||||
FF_A_PRINTF(2, 3) void ffStrbufInitF(FFstrbuf* strbuf, const char* format, ...);
|
||||
FF_A_PRINTF(1, 2) FF_A_NODISCARD FFstrbuf ffStrbufCreateF(const char* format, ...);
|
||||
[[gnu::format(printf, 2, 3)]] void ffStrbufInitF(FFstrbuf* strbuf, const char* format, ...);
|
||||
[[gnu::format(printf, 1, 2)]] [[nodiscard]] FFstrbuf ffStrbufCreateF(const char* format, ...);
|
||||
|
||||
void ffStrbufEnsureFixedLengthFree(FFstrbuf* strbuf, uint32_t free);
|
||||
void ffStrbufEnsureFreeNoCheck(FFstrbuf* strbuf, uint32_t free);
|
||||
|
||||
static inline void ffStrbufAppend(FFstrbuf* __restrict strbuf, const FFstrbuf* __restrict value);
|
||||
void ffStrbufAppendTransformS(FFstrbuf* strbuf, const char* value, int (*transformFunc)(int));
|
||||
FF_A_PRINTF(2, 3) void ffStrbufAppendF(FFstrbuf* strbuf, const char* format, ...);
|
||||
[[gnu::format(printf, 2, 3)]] void ffStrbufAppendF(FFstrbuf* strbuf, const char* format, ...);
|
||||
void ffStrbufAppendVF(FFstrbuf* strbuf, const char* format, va_list arguments);
|
||||
const char* ffStrbufAppendSUntilC(FFstrbuf* strbuf, const char* value, char until);
|
||||
|
||||
@@ -58,7 +56,7 @@ void ffStrbufInsertNC(FFstrbuf* strbuf, uint32_t index, uint32_t num, char c);
|
||||
// NOTE: Unlike ffStrbufAppend*, ffStrbufSet* functions may NOT reserve extra space
|
||||
void ffStrbufSet(FFstrbuf* strbuf, const FFstrbuf* value);
|
||||
void ffStrbufSetNS(FFstrbuf* strbuf, uint32_t length, const char* value);
|
||||
FF_A_PRINTF(2, 3) void ffStrbufSetF(FFstrbuf* strbuf, const char* format, ...);
|
||||
[[gnu::format(printf, 2, 3)]] void ffStrbufSetF(FFstrbuf* strbuf, const char* format, ...);
|
||||
|
||||
void ffStrbufTrimLeft(FFstrbuf* strbuf, char c);
|
||||
void ffStrbufTrimRight(FFstrbuf* strbuf, char c);
|
||||
@@ -79,7 +77,7 @@ bool ffStrbufSubstrAfterFirstS(FFstrbuf* strbuf, const char* str);
|
||||
bool ffStrbufSubstrAfterLastC(FFstrbuf* strbuf, char c);
|
||||
bool ffStrbufSubstr(FFstrbuf* strbuf, uint32_t start, uint32_t end);
|
||||
|
||||
FF_A_NODISCARD uint32_t ffStrbufCountC(const FFstrbuf* strbuf, char c);
|
||||
[[nodiscard]] uint32_t ffStrbufCountC(const FFstrbuf* strbuf, char c);
|
||||
|
||||
bool ffStrbufRemoveIgnCaseEndS(FFstrbuf* strbuf, const char* end);
|
||||
|
||||
@@ -135,7 +133,7 @@ void ffStrbufAppendUInt(FFstrbuf* strbuf, uint64_t value);
|
||||
// if `precision < 0`, let yyjson decide the precision
|
||||
void ffStrbufAppendDouble(FFstrbuf* strbuf, double value, int8_t precision, bool trailingZeros);
|
||||
|
||||
FF_A_NODISCARD static inline FFstrbuf ffStrbufCreateA(uint32_t allocate) {
|
||||
[[nodiscard]] static inline FFstrbuf ffStrbufCreateA(uint32_t allocate) {
|
||||
FFstrbuf strbuf;
|
||||
ffStrbufInitA(&strbuf, allocate);
|
||||
return strbuf;
|
||||
@@ -150,7 +148,7 @@ static inline void ffStrbufInitCopy(FFstrbuf* __restrict strbuf, const FFstrbuf*
|
||||
}
|
||||
}
|
||||
|
||||
FF_A_NODISCARD static inline FFstrbuf ffStrbufCreateCopy(const FFstrbuf* src) {
|
||||
[[nodiscard]] static inline FFstrbuf ffStrbufCreateCopy(const FFstrbuf* src) {
|
||||
FFstrbuf strbuf;
|
||||
ffStrbufInitCopy(&strbuf, src);
|
||||
return strbuf;
|
||||
@@ -166,7 +164,7 @@ static inline void ffStrbufInitMove(FFstrbuf* strbuf, FFstrbuf* src) {
|
||||
}
|
||||
}
|
||||
|
||||
FF_A_NODISCARD static inline FFstrbuf ffStrbufCreateMove(FFstrbuf* src) {
|
||||
[[nodiscard]] static inline FFstrbuf ffStrbufCreateMove(FFstrbuf* src) {
|
||||
FFstrbuf strbuf;
|
||||
ffStrbufInitMove(&strbuf, src);
|
||||
return strbuf;
|
||||
@@ -185,7 +183,7 @@ static inline void ffStrbufDestroy(FFstrbuf* strbuf) {
|
||||
ffStrbufInit(strbuf);
|
||||
}
|
||||
|
||||
FF_A_NODISCARD static inline uint32_t ffStrbufGetFree(const FFstrbuf* strbuf) {
|
||||
[[nodiscard]] static inline uint32_t ffStrbufGetFree(const FFstrbuf* strbuf) {
|
||||
assert(strbuf != nullptr);
|
||||
if (strbuf->allocated == 0) {
|
||||
return 0;
|
||||
@@ -311,7 +309,7 @@ static inline void ffStrbufInit(FFstrbuf* strbuf) {
|
||||
strbuf->chars = CHAR_NULL_PTR;
|
||||
}
|
||||
|
||||
FF_A_NODISCARD static inline FFstrbuf ffStrbufCreate(void) {
|
||||
[[nodiscard]] static inline FFstrbuf ffStrbufCreate(void) {
|
||||
FFstrbuf strbuf;
|
||||
ffStrbufInit(&strbuf);
|
||||
return strbuf;
|
||||
@@ -328,7 +326,7 @@ static inline void ffStrbufInitStatic(FFstrbuf* strbuf, const char* str) {
|
||||
strbuf->chars = (char*) str;
|
||||
}
|
||||
|
||||
FF_A_NODISCARD static inline FFstrbuf ffStrbufCreateStatic(const char* str) {
|
||||
[[nodiscard]] static inline FFstrbuf ffStrbufCreateStatic(const char* str) {
|
||||
FFstrbuf strbuf;
|
||||
ffStrbufInitStatic(&strbuf, str);
|
||||
return strbuf;
|
||||
@@ -351,7 +349,7 @@ static inline void ffStrbufInitNS(FFstrbuf* strbuf, uint32_t length, const char*
|
||||
ffStrbufAppendNS(strbuf, length, str);
|
||||
}
|
||||
|
||||
FF_A_NODISCARD static inline FFstrbuf ffStrbufCreateNS(uint32_t length, const char* str) {
|
||||
[[nodiscard]] static inline FFstrbuf ffStrbufCreateNS(uint32_t length, const char* str) {
|
||||
FFstrbuf strbuf;
|
||||
ffStrbufInitNS(&strbuf, length, str);
|
||||
return strbuf;
|
||||
@@ -367,7 +365,7 @@ static inline void ffStrbufInitS(FFstrbuf* strbuf, const char* str) {
|
||||
ffStrbufAppendS(strbuf, str);
|
||||
}
|
||||
|
||||
FF_A_NODISCARD static inline FFstrbuf ffStrbufCreateS(const char* str) {
|
||||
[[nodiscard]] static inline FFstrbuf ffStrbufCreateS(const char* str) {
|
||||
FFstrbuf strbuf;
|
||||
ffStrbufInitS(&strbuf, str);
|
||||
return strbuf;
|
||||
@@ -387,93 +385,93 @@ static inline void ffStrbufPrependS(FFstrbuf* strbuf, const char* value) {
|
||||
ffStrbufPrependNS(strbuf, (uint32_t) strlen(value), value);
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD int ffStrbufComp(const FFstrbuf* strbuf, const FFstrbuf* comp) {
|
||||
[[nodiscard]] static inline int ffStrbufComp(const FFstrbuf* strbuf, const FFstrbuf* comp) {
|
||||
uint32_t length = strbuf->length > comp->length ? comp->length : strbuf->length;
|
||||
return memcmp(strbuf->chars, comp->chars, length + 1);
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufEqual(const FFstrbuf* strbuf, const FFstrbuf* comp) {
|
||||
[[nodiscard]] static inline bool ffStrbufEqual(const FFstrbuf* strbuf, const FFstrbuf* comp) {
|
||||
return ffStrbufComp(strbuf, comp) == 0;
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD int ffStrbufCompS(const FFstrbuf* strbuf, const char* comp) {
|
||||
[[nodiscard]] static inline int ffStrbufCompS(const FFstrbuf* strbuf, const char* comp) {
|
||||
return strcmp(strbuf->chars, comp);
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufEqualS(const FFstrbuf* strbuf, const char* comp) {
|
||||
[[nodiscard]] static inline bool ffStrbufEqualS(const FFstrbuf* strbuf, const char* comp) {
|
||||
return ffStrbufCompS(strbuf, comp) == 0;
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD int ffStrbufIgnCaseCompS(const FFstrbuf* strbuf, const char* comp) {
|
||||
[[nodiscard]] static inline int ffStrbufIgnCaseCompS(const FFstrbuf* strbuf, const char* comp) {
|
||||
return strcasecmp(strbuf->chars, comp);
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufIgnCaseEqualS(const FFstrbuf* strbuf, const char* comp) {
|
||||
[[nodiscard]] static inline bool ffStrbufIgnCaseEqualS(const FFstrbuf* strbuf, const char* comp) {
|
||||
return ffStrbufIgnCaseCompS(strbuf, comp) == 0;
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD int ffStrbufIgnCaseComp(const FFstrbuf* strbuf, const FFstrbuf* comp) {
|
||||
[[nodiscard]] static inline int ffStrbufIgnCaseComp(const FFstrbuf* strbuf, const FFstrbuf* comp) {
|
||||
return ffStrbufIgnCaseCompS(strbuf, comp->chars);
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufIgnCaseEqual(const FFstrbuf* strbuf, const FFstrbuf* comp) {
|
||||
[[nodiscard]] static inline bool ffStrbufIgnCaseEqual(const FFstrbuf* strbuf, const FFstrbuf* comp) {
|
||||
return ffStrbufIgnCaseComp(strbuf, comp) == 0;
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufContainC(const FFstrbuf* strbuf, char c) {
|
||||
[[nodiscard]] static inline bool ffStrbufContainC(const FFstrbuf* strbuf, char c) {
|
||||
return memchr(strbuf->chars, c, strbuf->length) != nullptr;
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufContainS(const FFstrbuf* strbuf, const char* str) {
|
||||
[[nodiscard]] static inline bool ffStrbufContainS(const FFstrbuf* strbuf, const char* str) {
|
||||
return strstr(strbuf->chars, str) != nullptr;
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufContain(const FFstrbuf* strbuf, const FFstrbuf* str) {
|
||||
[[nodiscard]] static inline bool ffStrbufContain(const FFstrbuf* strbuf, const FFstrbuf* str) {
|
||||
return ffStrbufContainS(strbuf, str->chars);
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufContainIgnCaseS(const FFstrbuf* strbuf, const char* str) {
|
||||
[[nodiscard]] static inline bool ffStrbufContainIgnCaseS(const FFstrbuf* strbuf, const char* str) {
|
||||
return strcasestr(strbuf->chars, str) != nullptr;
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufContainIgnCase(const FFstrbuf* strbuf, const FFstrbuf* str) {
|
||||
[[nodiscard]] static inline bool ffStrbufContainIgnCase(const FFstrbuf* strbuf, const FFstrbuf* str) {
|
||||
return ffStrbufContainIgnCaseS(strbuf, str->chars);
|
||||
}
|
||||
|
||||
FF_A_NODISCARD static inline uint32_t ffStrbufNextIndexC(const FFstrbuf* strbuf, uint32_t start, char c) {
|
||||
[[nodiscard]] static inline uint32_t ffStrbufNextIndexC(const FFstrbuf* strbuf, uint32_t start, char c) {
|
||||
assert(start <= strbuf->length);
|
||||
|
||||
const char* ptr = (const char*) memchr(strbuf->chars + start, c, strbuf->length - start);
|
||||
return ptr ? (uint32_t) (ptr - strbuf->chars) : strbuf->length;
|
||||
}
|
||||
|
||||
FF_A_NODISCARD static inline uint32_t ffStrbufNextIndexS(const FFstrbuf* strbuf, uint32_t start, const char* str) {
|
||||
[[nodiscard]] static inline uint32_t ffStrbufNextIndexS(const FFstrbuf* strbuf, uint32_t start, const char* str) {
|
||||
assert(start <= strbuf->length);
|
||||
|
||||
const char* ptr = strstr(strbuf->chars + start, str);
|
||||
return ptr ? (uint32_t) (ptr - strbuf->chars) : strbuf->length;
|
||||
}
|
||||
|
||||
FF_A_NODISCARD static inline uint32_t ffStrbufPreviousIndexC(const FFstrbuf* strbuf, uint32_t start, char c) {
|
||||
[[nodiscard]] static inline uint32_t ffStrbufPreviousIndexC(const FFstrbuf* strbuf, uint32_t start, char c) {
|
||||
assert(start <= strbuf->length);
|
||||
|
||||
const char* ptr = (const char*) memrchr(strbuf->chars, c, start + 1);
|
||||
return ptr ? (uint32_t) (ptr - strbuf->chars) : strbuf->length;
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD uint32_t ffStrbufFirstIndexC(const FFstrbuf* strbuf, char c) {
|
||||
[[nodiscard]] static inline uint32_t ffStrbufFirstIndexC(const FFstrbuf* strbuf, char c) {
|
||||
return ffStrbufNextIndexC(strbuf, 0, c);
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD uint32_t ffStrbufFirstIndex(const FFstrbuf* strbuf, const FFstrbuf* searched) {
|
||||
[[nodiscard]] static inline uint32_t ffStrbufFirstIndex(const FFstrbuf* strbuf, const FFstrbuf* searched) {
|
||||
return ffStrbufNextIndexS(strbuf, 0, searched->chars);
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD uint32_t ffStrbufFirstIndexS(const FFstrbuf* strbuf, const char* str) {
|
||||
[[nodiscard]] static inline uint32_t ffStrbufFirstIndexS(const FFstrbuf* strbuf, const char* str) {
|
||||
return ffStrbufNextIndexS(strbuf, 0, str);
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD uint32_t ffStrbufLastIndexC(const FFstrbuf* strbuf, char c) {
|
||||
[[nodiscard]] static inline uint32_t ffStrbufLastIndexC(const FFstrbuf* strbuf, char c) {
|
||||
if (strbuf->length == 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -489,11 +487,11 @@ static inline bool ffStrbufSubstrBeforeLastC(FFstrbuf* strbuf, char c) {
|
||||
return ffStrbufSubstrBefore(strbuf, ffStrbufLastIndexC(strbuf, c));
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufStartsWithC(const FFstrbuf* strbuf, char c) {
|
||||
[[nodiscard]] static inline bool ffStrbufStartsWithC(const FFstrbuf* strbuf, char c) {
|
||||
return strbuf->chars[0] == c;
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufStartsWithSN(const FFstrbuf* strbuf, const char* start, uint32_t length) {
|
||||
[[nodiscard]] static inline bool ffStrbufStartsWithSN(const FFstrbuf* strbuf, const char* start, uint32_t length) {
|
||||
if (length > strbuf->length) {
|
||||
return false;
|
||||
}
|
||||
@@ -501,34 +499,34 @@ static inline FF_A_NODISCARD bool ffStrbufStartsWithSN(const FFstrbuf* strbuf, c
|
||||
return memcmp(strbuf->chars, start, length) == 0;
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufStartsWithS(const FFstrbuf* strbuf, const char* start) {
|
||||
[[nodiscard]] static inline bool ffStrbufStartsWithS(const FFstrbuf* strbuf, const char* start) {
|
||||
return ffStrbufStartsWithSN(strbuf, start, (uint32_t) strlen(start));
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufStartsWith(const FFstrbuf* strbuf, const FFstrbuf* start) {
|
||||
[[nodiscard]] static inline bool ffStrbufStartsWith(const FFstrbuf* strbuf, const FFstrbuf* start) {
|
||||
return ffStrbufStartsWithSN(strbuf, start->chars, start->length);
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufStartsWithIgnCaseNS(const FFstrbuf* strbuf, uint32_t length, const char* start) {
|
||||
[[nodiscard]] static inline bool ffStrbufStartsWithIgnCaseNS(const FFstrbuf* strbuf, uint32_t length, const char* start) {
|
||||
if (length > strbuf->length) {
|
||||
return false;
|
||||
}
|
||||
return strncasecmp(strbuf->chars, start, length) == 0;
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufStartsWithIgnCaseS(const FFstrbuf* strbuf, const char* start) {
|
||||
[[nodiscard]] static inline bool ffStrbufStartsWithIgnCaseS(const FFstrbuf* strbuf, const char* start) {
|
||||
return ffStrbufStartsWithIgnCaseNS(strbuf, (uint32_t) strlen(start), start);
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufStartsWithIgnCase(const FFstrbuf* strbuf, const FFstrbuf* start) {
|
||||
[[nodiscard]] static inline bool ffStrbufStartsWithIgnCase(const FFstrbuf* strbuf, const FFstrbuf* start) {
|
||||
return ffStrbufStartsWithIgnCaseNS(strbuf, start->length, start->chars);
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufEndsWithC(const FFstrbuf* strbuf, char c) {
|
||||
[[nodiscard]] static inline bool ffStrbufEndsWithC(const FFstrbuf* strbuf, char c) {
|
||||
return strbuf->length == 0 ? false : strbuf->chars[strbuf->length - 1] == c;
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufEndsWithNS(const FFstrbuf* strbuf, uint32_t endLength, const char* end) {
|
||||
[[nodiscard]] static inline bool ffStrbufEndsWithNS(const FFstrbuf* strbuf, uint32_t endLength, const char* end) {
|
||||
if (endLength > strbuf->length) {
|
||||
return false;
|
||||
}
|
||||
@@ -536,30 +534,30 @@ static inline FF_A_NODISCARD bool ffStrbufEndsWithNS(const FFstrbuf* strbuf, uin
|
||||
return memcmp(strbuf->chars + strbuf->length - endLength, end, endLength) == 0;
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufEndsWithS(const FFstrbuf* strbuf, const char* end) {
|
||||
[[nodiscard]] static inline bool ffStrbufEndsWithS(const FFstrbuf* strbuf, const char* end) {
|
||||
return ffStrbufEndsWithNS(strbuf, (uint32_t) strlen(end), end);
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufEndsWithFn(const FFstrbuf* strbuf, int (*const fn)(int)) {
|
||||
[[nodiscard]] static inline bool ffStrbufEndsWithFn(const FFstrbuf* strbuf, int (*const fn)(int)) {
|
||||
return strbuf->length == 0 ? false : fn(strbuf->chars[strbuf->length - 1]);
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufEndsWith(const FFstrbuf* strbuf, const FFstrbuf* end) {
|
||||
[[nodiscard]] static inline bool ffStrbufEndsWith(const FFstrbuf* strbuf, const FFstrbuf* end) {
|
||||
return ffStrbufEndsWithNS(strbuf, end->length, end->chars);
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufEndsWithIgnCaseNS(const FFstrbuf* strbuf, uint32_t endLength, const char* end) {
|
||||
[[nodiscard]] static inline bool ffStrbufEndsWithIgnCaseNS(const FFstrbuf* strbuf, uint32_t endLength, const char* end) {
|
||||
if (endLength > strbuf->length) {
|
||||
return false;
|
||||
}
|
||||
return strcasecmp(strbuf->chars + strbuf->length - endLength, end) == 0;
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufEndsWithIgnCaseS(const FFstrbuf* strbuf, const char* end) {
|
||||
[[nodiscard]] static inline bool ffStrbufEndsWithIgnCaseS(const FFstrbuf* strbuf, const char* end) {
|
||||
return ffStrbufEndsWithIgnCaseNS(strbuf, (uint32_t) strlen(end), end);
|
||||
}
|
||||
|
||||
static inline FF_A_NODISCARD bool ffStrbufEndsWithIgnCase(const FFstrbuf* strbuf, const FFstrbuf* end) {
|
||||
[[nodiscard]] static inline bool ffStrbufEndsWithIgnCase(const FFstrbuf* strbuf, const FFstrbuf* end) {
|
||||
return ffStrbufEndsWithIgnCaseNS(strbuf, end->length, end->chars);
|
||||
}
|
||||
|
||||
@@ -614,19 +612,19 @@ static inline void ffStrbufPutTo(const FFstrbuf* strbuf, FILE* file) {
|
||||
fputc('\n', file);
|
||||
}
|
||||
|
||||
FF_A_NODISCARD static inline double ffStrbufToDouble(const FFstrbuf* strbuf, double defaultValue) {
|
||||
[[nodiscard]] static inline double ffStrbufToDouble(const FFstrbuf* strbuf, double defaultValue) {
|
||||
char* str_end;
|
||||
double result = strtod(strbuf->chars, &str_end);
|
||||
return str_end == strbuf->chars ? defaultValue : result;
|
||||
}
|
||||
|
||||
FF_A_NODISCARD static inline uint64_t ffStrbufToUInt(const FFstrbuf* strbuf, uint64_t defaultValue) {
|
||||
[[nodiscard]] static inline uint64_t ffStrbufToUInt(const FFstrbuf* strbuf, uint64_t defaultValue) {
|
||||
char* str_end;
|
||||
unsigned long long result = strtoull(strbuf->chars, &str_end, 10);
|
||||
return str_end == strbuf->chars ? defaultValue : (uint64_t) result;
|
||||
}
|
||||
|
||||
FF_A_NODISCARD static inline int64_t ffStrbufToSInt(const FFstrbuf* strbuf, int64_t defaultValue) {
|
||||
[[nodiscard]] static inline int64_t ffStrbufToSInt(const FFstrbuf* strbuf, int64_t defaultValue) {
|
||||
char* str_end;
|
||||
long long result = strtoll(strbuf->chars, &str_end, 10);
|
||||
return str_end == strbuf->chars ? defaultValue : (int64_t) result;
|
||||
@@ -635,4 +633,4 @@ FF_A_NODISCARD static inline int64_t ffStrbufToSInt(const FFstrbuf* strbuf, int6
|
||||
// Returns true if the strbuf is modified
|
||||
bool ffStrbufDecodeHexEscapeSequences(FFstrbuf* strbuf);
|
||||
|
||||
#define FF_STRBUF_AUTO_DESTROY FFstrbuf FF_A_CLEANUP(ffStrbufDestroy)
|
||||
#define FF_STRBUF_AUTO_DESTROY [[gnu::cleanup(ffStrbufDestroy)]] FFstrbuf
|
||||
|
||||
@@ -32,7 +32,7 @@ static inline void cfReleaseWrapper(void* type) {
|
||||
}
|
||||
}
|
||||
|
||||
#define FF_CFTYPE_AUTO_RELEASE FF_A_CLEANUP(cfReleaseWrapper)
|
||||
#define FF_CFTYPE_AUTO_RELEASE [[gnu::cleanup(cfReleaseWrapper)]]
|
||||
|
||||
static inline void wrapIoObjectRelease(io_object_t* service) {
|
||||
assert(service);
|
||||
@@ -40,4 +40,4 @@ static inline void wrapIoObjectRelease(io_object_t* service) {
|
||||
IOObjectRelease(*service);
|
||||
}
|
||||
}
|
||||
#define FF_IOOBJECT_AUTO_RELEASE FF_A_CLEANUP(wrapIoObjectRelease)
|
||||
#define FF_IOOBJECT_AUTO_RELEASE [[gnu::cleanup(wrapIoObjectRelease)]]
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef __has_attribute
|
||||
#error Unsupported compiler
|
||||
#define __attribute__(x)
|
||||
#endif
|
||||
|
||||
#define FF_A_FALLTHROUGH __attribute__((__fallthrough__))
|
||||
#define FF_A_DEPRECATED __attribute__((__deprecated__))
|
||||
#define FF_A_CLEANUP(func) __attribute__((__cleanup__(func)))
|
||||
#define FF_A_NODISCARD __attribute__((__warn_unused_result__))
|
||||
#define FF_A_PRINTF(formatStrIndex, argsStartIndex) __attribute__((__format__(printf, formatStrIndex, argsStartIndex)))
|
||||
#define FF_A_SCANF(formatStrIndex, argsStartIndex) __attribute__((__format__(scanf, formatStrIndex, argsStartIndex)))
|
||||
#define FF_A_NONNULL(argIndex, ...) __attribute__((__nonnull__(argIndex, ##__VA_ARGS__)))
|
||||
#define FF_A_RETURNS_NONNULL __attribute__((__returns_nonnull__))
|
||||
#define FF_A_UNUSED __attribute__((__unused__))
|
||||
#define FF_A_PACKED __attribute__((__packed__))
|
||||
#define FF_A_WEAK_IMPORT __attribute__((__weak_import__))
|
||||
#define FF_A_ALWAYS_INLINE __attribute__((__always_inline__))
|
||||
#define FF_A_COLD __attribute__((__cold__))
|
||||
+1
-1
@@ -41,6 +41,6 @@ static inline DBusMessage* ffDBusGetAllProperties(FFDBusData* dbus, const char*
|
||||
return ffDBusGetMethodReply(dbus, busName, objectPath, "org.freedesktop.DBus.Properties", "GetAll", interface, nullptr);
|
||||
}
|
||||
|
||||
#define FF_DBUS_AUTO_DESTROY_DATA FF_A_CLEANUP(ffDBusDestroyData)
|
||||
#define FF_DBUS_AUTO_DESTROY_DATA [[gnu::cleanup(ffDBusDestroyData)]]
|
||||
|
||||
#endif // FF_HAVE_DBUS
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
+33
-31
@@ -40,7 +40,6 @@ HANDLE openat(HANDLE dfd, const char* fileName, int oflag);
|
||||
HANDLE openatW(HANDLE dfd, const wchar_t* fileName, uint16_t fileNameLen, bool directory);
|
||||
#endif
|
||||
|
||||
FF_A_ALWAYS_INLINE
|
||||
static inline bool ffIsValidNativeFD(FFNativeFD fd) {
|
||||
#ifndef _WIN32
|
||||
return fd >= 0;
|
||||
@@ -50,7 +49,7 @@ static inline bool ffIsValidNativeFD(FFNativeFD fd) {
|
||||
#endif
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE FF_A_NONNULL(1)
|
||||
[[gnu::always_inline, gnu::nonnull(1)]]
|
||||
static inline void wrapClose(FFNativeFD* pfd) {
|
||||
assert(pfd);
|
||||
|
||||
@@ -62,7 +61,7 @@ static inline void wrapClose(FFNativeFD* pfd) {
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#define FF_AUTO_CLOSE_FD FF_A_CLEANUP(wrapClose)
|
||||
#define FF_AUTO_CLOSE_FD [[gnu::cleanup(wrapClose)]]
|
||||
|
||||
static inline FFNativeFD FFUnixFD2NativeFD(int unixfd) {
|
||||
#ifndef _WIN32
|
||||
@@ -72,7 +71,8 @@ static inline FFNativeFD FFUnixFD2NativeFD(int unixfd) {
|
||||
#endif
|
||||
}
|
||||
|
||||
FF_A_NONNULL(3) static inline bool ffWriteFDData(FFNativeFD fd, size_t dataSize, const void* data) {
|
||||
[[gnu::nonnull(3)]]
|
||||
static inline bool ffWriteFDData(FFNativeFD fd, size_t dataSize, const void* data) {
|
||||
#ifndef _WIN32
|
||||
return write(fd, data, dataSize) != -1;
|
||||
#else
|
||||
@@ -81,17 +81,21 @@ FF_A_NONNULL(3) static inline bool ffWriteFDData(FFNativeFD fd, size_t dataSize,
|
||||
#endif
|
||||
}
|
||||
|
||||
FF_A_NONNULL(2) static inline bool ffWriteFDBuffer(FFNativeFD fd, const FFstrbuf* content) {
|
||||
[[gnu::nonnull(2)]]
|
||||
static inline bool ffWriteFDBuffer(FFNativeFD fd, const FFstrbuf* content) {
|
||||
return ffWriteFDData(fd, content->length, content->chars);
|
||||
}
|
||||
|
||||
FF_A_NONNULL(1, 3) bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data);
|
||||
[[gnu::nonnull(1, 3)]]
|
||||
bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data);
|
||||
|
||||
FF_A_NONNULL(1, 2) static inline bool ffWriteFileBuffer(const char* fileName, const FFstrbuf* buffer) {
|
||||
[[gnu::nonnull(1, 2)]]
|
||||
static inline bool ffWriteFileBuffer(const char* fileName, const FFstrbuf* buffer) {
|
||||
return ffWriteFileData(fileName, buffer->length, buffer->chars);
|
||||
}
|
||||
|
||||
FF_A_NONNULL(3) static inline ssize_t ffReadFDData(FFNativeFD fd, size_t dataSize, void* data) {
|
||||
[[gnu::nonnull(3)]]
|
||||
static inline ssize_t ffReadFDData(FFNativeFD fd, size_t dataSize, void* data) {
|
||||
#ifndef _WIN32
|
||||
return read(fd, data, dataSize);
|
||||
#else
|
||||
@@ -104,10 +108,10 @@ FF_A_NONNULL(3) static inline ssize_t ffReadFDData(FFNativeFD fd, size_t dataSiz
|
||||
#endif
|
||||
}
|
||||
|
||||
FF_A_NONNULL(2) bool ffAppendFDBuffer(FFNativeFD fd, FFstrbuf* buffer);
|
||||
[[gnu::nonnull(2)]] bool ffAppendFDBuffer(FFNativeFD fd, FFstrbuf* buffer);
|
||||
|
||||
FF_A_NONNULL(1, 3) static inline ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data) {
|
||||
FFNativeFD FF_AUTO_CLOSE_FD fd =
|
||||
[[gnu::nonnull(1, 3)]] static inline ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data) {
|
||||
FF_AUTO_CLOSE_FD FFNativeFD fd =
|
||||
#ifndef _WIN32
|
||||
open(fileName, O_RDONLY | O_CLOEXEC);
|
||||
#else
|
||||
@@ -121,8 +125,8 @@ FF_A_NONNULL(1, 3) static inline ssize_t ffReadFileData(const char* fileName, si
|
||||
return ffReadFDData(fd, dataSize, data);
|
||||
}
|
||||
|
||||
FF_A_NONNULL(2, 4) static inline ssize_t ffReadFileDataRelative(FFNativeFD dfd, const char* fileName, size_t dataSize, void* data) {
|
||||
FFNativeFD FF_AUTO_CLOSE_FD fd = openat(dfd, fileName, O_RDONLY | O_CLOEXEC);
|
||||
[[gnu::nonnull(2, 4)]] static inline ssize_t ffReadFileDataRelative(FFNativeFD dfd, const char* fileName, size_t dataSize, void* data) {
|
||||
FF_AUTO_CLOSE_FD FFNativeFD fd = openat(dfd, fileName, O_RDONLY | O_CLOEXEC);
|
||||
if (!ffIsValidNativeFD(fd)) {
|
||||
return -1;
|
||||
}
|
||||
@@ -130,8 +134,8 @@ FF_A_NONNULL(2, 4) static inline ssize_t ffReadFileDataRelative(FFNativeFD dfd,
|
||||
return ffReadFDData(fd, dataSize, data);
|
||||
}
|
||||
|
||||
FF_A_NONNULL(1, 2) static inline bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer) {
|
||||
FFNativeFD FF_AUTO_CLOSE_FD fd =
|
||||
[[gnu::nonnull(1, 2)]] static inline bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer) {
|
||||
FF_AUTO_CLOSE_FD FFNativeFD fd =
|
||||
#ifndef _WIN32
|
||||
open(fileName, O_RDONLY | O_CLOEXEC);
|
||||
#else
|
||||
@@ -145,8 +149,8 @@ FF_A_NONNULL(1, 2) static inline bool ffAppendFileBuffer(const char* fileName, F
|
||||
return ffAppendFDBuffer(fd, buffer);
|
||||
}
|
||||
|
||||
FF_A_NONNULL(2, 3) static inline bool ffAppendFileBufferRelative(FFNativeFD dfd, const char* fileName, FFstrbuf* buffer) {
|
||||
FFNativeFD FF_AUTO_CLOSE_FD fd = openat(dfd, fileName, O_RDONLY | O_CLOEXEC);
|
||||
[[gnu::nonnull(2, 3)]] static inline bool ffAppendFileBufferRelative(FFNativeFD dfd, const char* fileName, FFstrbuf* buffer) {
|
||||
FF_AUTO_CLOSE_FD FFNativeFD fd = openat(dfd, fileName, O_RDONLY | O_CLOEXEC);
|
||||
if (!ffIsValidNativeFD(fd)) {
|
||||
return false;
|
||||
}
|
||||
@@ -154,17 +158,17 @@ FF_A_NONNULL(2, 3) static inline bool ffAppendFileBufferRelative(FFNativeFD dfd,
|
||||
return ffAppendFDBuffer(fd, buffer);
|
||||
}
|
||||
|
||||
FF_A_NONNULL(2) static inline bool ffReadFDBuffer(FFNativeFD fd, FFstrbuf* buffer) {
|
||||
[[gnu::nonnull(2)]] static inline bool ffReadFDBuffer(FFNativeFD fd, FFstrbuf* buffer) {
|
||||
ffStrbufClear(buffer);
|
||||
return ffAppendFDBuffer(fd, buffer);
|
||||
}
|
||||
|
||||
FF_A_NONNULL(1, 2) static inline bool ffReadFileBuffer(const char* fileName, FFstrbuf* buffer) {
|
||||
[[gnu::nonnull(1, 2)]] static inline bool ffReadFileBuffer(const char* fileName, FFstrbuf* buffer) {
|
||||
ffStrbufClear(buffer);
|
||||
return ffAppendFileBuffer(fileName, buffer);
|
||||
}
|
||||
|
||||
FF_A_NONNULL(2, 3) static inline bool ffReadFileBufferRelative(FFNativeFD dfd, const char* fileName, FFstrbuf* buffer) {
|
||||
[[gnu::nonnull(2, 3)]] static inline bool ffReadFileBufferRelative(FFNativeFD dfd, const char* fileName, FFstrbuf* buffer) {
|
||||
ffStrbufClear(buffer);
|
||||
return ffAppendFileBufferRelative(dfd, fileName, buffer);
|
||||
}
|
||||
@@ -175,7 +179,7 @@ typedef enum FFPathType: uint8_t {
|
||||
FF_PATHTYPE_ANY = FF_PATHTYPE_FILE | FF_PATHTYPE_DIRECTORY,
|
||||
} FFPathType;
|
||||
|
||||
FF_A_NONNULL(1) static inline bool ffPathExists(const char* path, FFPathType pathType) {
|
||||
[[gnu::nonnull(1)]] static inline bool ffPathExists(const char* path, FFPathType pathType) {
|
||||
#ifdef _WIN32
|
||||
|
||||
wchar_t wPath[MAX_PATH];
|
||||
@@ -224,13 +228,11 @@ FF_A_NONNULL(1) static inline bool ffPathExists(const char* path, FFPathType pat
|
||||
return false;
|
||||
}
|
||||
|
||||
FF_A_NONNULL(1, 2) bool ffPathExpandEnv(const char* in, FFstrbuf* out);
|
||||
[[gnu::nonnull(1, 2)]] bool ffPathExpandEnv(const char* in, FFstrbuf* out);
|
||||
|
||||
#define FF_IO_TERM_RESP_WAIT_MS 100 // #554
|
||||
|
||||
FF_A_SCANF(3, 4)
|
||||
FF_A_NONNULL(1, 3)
|
||||
const char* ffGetTerminalResponse(const char* request, int nParams, const char* format, ...);
|
||||
[[gnu::format(scanf, 3, 4), gnu::nonnull(1, 3)]] const char* ffGetTerminalResponse(const char* request, int nParams, const char* format, ...);
|
||||
|
||||
// Not thread safe!
|
||||
bool ffSuppressIO(bool suppress);
|
||||
@@ -243,19 +245,19 @@ static inline void ffUnsuppressIO(bool* suppressed) {
|
||||
*suppressed = false;
|
||||
}
|
||||
|
||||
#define FF_SUPPRESS_IO() bool FF_A_CLEANUP(ffUnsuppressIO) FF_A_UNUSED io_suppressed__ = ffSuppressIO(true)
|
||||
#define FF_SUPPRESS_IO() [[maybe_unused, gnu::cleanup(ffUnsuppressIO)]] bool io_suppressed__ = ffSuppressIO(true)
|
||||
|
||||
void ffListFilesRecursively(const char* path, bool pretty);
|
||||
|
||||
FF_A_NONNULL(1) FF_A_ALWAYS_INLINE static inline void wrapFclose(FILE** pfile) {
|
||||
[[gnu::nonnull(1), gnu::always_inline]] static inline void wrapFclose(FILE** pfile) {
|
||||
assert(pfile);
|
||||
if (*pfile) {
|
||||
fclose(*pfile);
|
||||
}
|
||||
}
|
||||
#define FF_AUTO_CLOSE_FILE FF_A_CLEANUP(wrapFclose)
|
||||
#define FF_AUTO_CLOSE_FILE [[gnu::cleanup(wrapFclose)]]
|
||||
|
||||
FF_A_NONNULL(1) FF_A_ALWAYS_INLINE
|
||||
[[gnu::nonnull(1), gnu::always_inline]]
|
||||
#ifndef _WIN32
|
||||
static inline void wrapClosedir(DIR** pdir) {
|
||||
assert(pdir);
|
||||
@@ -271,9 +273,9 @@ static inline void wrapClosedir(HANDLE* pdir) {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#define FF_AUTO_CLOSE_DIR FF_A_CLEANUP(wrapClosedir)
|
||||
#define FF_AUTO_CLOSE_DIR [[gnu::cleanup(wrapClosedir)]]
|
||||
|
||||
FF_A_NONNULL(1, 2, 3) static inline bool ffSearchUserConfigFile(const FFlist* configDirs, const char* fileSubpath, FFstrbuf* result) {
|
||||
[[gnu::nonnull(1, 2, 3)]] static inline bool ffSearchUserConfigFile(const FFlist* configDirs, const char* fileSubpath, FFstrbuf* result) {
|
||||
// configDirs is a list of FFstrbufs include the trailing slash
|
||||
FF_LIST_FOR_EACH (FFstrbuf, dir, *configDirs) {
|
||||
ffStrbufClear(result);
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define FF_DLOPEN_FLAGS 0
|
||||
FF_A_NODISCARD void* dlopen(const char* path, int mode);
|
||||
FF_A_NODISCARD void* dlsym(void* handle, const char* symbol);
|
||||
[[nodiscard]] void* dlopen(const char* path, int mode);
|
||||
[[nodiscard]] void* dlsym(void* handle, const char* symbol);
|
||||
int dlclose(void* handle);
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
@@ -36,7 +36,7 @@ static inline void ffLibraryUnload(void** handle) {
|
||||
__typeof__(&symbolName) ff##symbolName;
|
||||
|
||||
#define FF_LIBRARY_LOAD(libraryObjectName, returnValue, libraryFileName, maxVersion, ...) \
|
||||
void* FF_A_CLEANUP(ffLibraryUnload) libraryObjectName = ffLibraryLoadSingle(libraryFileName, maxVersion); \
|
||||
[[gnu::cleanup(ffLibraryUnload)]] void* libraryObjectName = ffLibraryLoadSingle(libraryFileName, maxVersion); \
|
||||
__VA_OPT__(if (__builtin_expect(libraryObjectName == nullptr, false)) libraryObjectName = ffLibraryLoadMulti(__VA_ARGS__, nullptr);) \
|
||||
if (__builtin_expect(libraryObjectName == nullptr, false)) \
|
||||
return returnValue;
|
||||
@@ -78,7 +78,7 @@ void* ffLibraryLoadMulti(const char* path, int maxVersion, ...);
|
||||
__typeof__(&symbolName) ff##symbolName;
|
||||
|
||||
#define FF_LIBRARY_LOAD(libraryObjectName, returnValue, ...) \
|
||||
FF_A_UNUSED void* libraryObjectName = nullptr; // Placeholder
|
||||
[[maybe_unused]] void* libraryObjectName = nullptr; // Placeholder
|
||||
|
||||
#define FF_LIBRARY_LOAD_MESSAGE(libraryObjectName, libraryFileName, maxVersion, ...) \
|
||||
FF_LIBRARY_LOAD(libraryObjectName, , libraryFileName, maxVersion, ##__VA_ARGS__)
|
||||
@@ -87,13 +87,13 @@ void* ffLibraryLoadMulti(const char* path, int maxVersion, ...);
|
||||
symbolMapping = (__typeof__(&symbolName)) &symbolName;
|
||||
|
||||
#define FF_LIBRARY_LOAD_SYMBOL(library, symbolName, returnValue) \
|
||||
FF_A_UNUSED __auto_type FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, ff##symbolName, symbolName, returnValue);
|
||||
[[maybe_unused]] __auto_type FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, ff##symbolName, symbolName, returnValue);
|
||||
|
||||
#define FF_LIBRARY_LOAD_SYMBOL_LAZY(library, symbolName) \
|
||||
FF_A_UNUSED __auto_type ff##symbolName = (__typeof__(&symbolName)) &symbolName;
|
||||
[[maybe_unused]] __auto_type ff##symbolName = (__typeof__(&symbolName)) &symbolName;
|
||||
|
||||
#define FF_LIBRARY_LOAD_SYMBOL_MESSAGE(library, symbolName) \
|
||||
FF_A_UNUSED __auto_type FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, ff##symbolName, symbolName, "dlsym " #symbolName " failed");
|
||||
[[maybe_unused]] __auto_type FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, ff##symbolName, symbolName, "dlsym " #symbolName " failed");
|
||||
|
||||
#define FF_LIBRARY_LOAD_SYMBOL_VAR(library, varName, symbolName, returnValue) \
|
||||
FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, (varName).ff##symbolName, symbolName, returnValue);
|
||||
|
||||
+28
-28
@@ -63,95 +63,95 @@ extern struct FFLuaData {
|
||||
} luaData;
|
||||
|
||||
#if !FF_DISABLE_DLOPEN
|
||||
FF_A_ALWAYS_INLINE void(lua_settop)(lua_State* L, int idx) {
|
||||
[[gnu::always_inline]] void(lua_settop)(lua_State* L, int idx) {
|
||||
return luaData.fflua_settop(L, idx);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE int(luaL_loadbufferx)(lua_State* L, const char* buff, size_t sz, const char* name, const char* mode) {
|
||||
[[gnu::always_inline]] int(luaL_loadbufferx)(lua_State* L, const char* buff, size_t sz, const char* name, const char* mode) {
|
||||
return luaData.ffluaL_loadbufferx(L, buff, sz, name, mode);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE const char*(lua_tolstring) (lua_State * L, int idx, size_t* len) {
|
||||
[[gnu::always_inline]] const char*(lua_tolstring) (lua_State * L, int idx, size_t* len) {
|
||||
return luaData.fflua_tolstring(L, idx, len);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE void(lua_createtable)(lua_State* L, int narr, int nrec) {
|
||||
[[gnu::always_inline]] void(lua_createtable)(lua_State* L, int narr, int nrec) {
|
||||
return luaData.fflua_createtable(L, narr, nrec);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE void(lua_pushinteger)(lua_State* L, lua_Integer n) {
|
||||
[[gnu::always_inline]] void(lua_pushinteger)(lua_State* L, lua_Integer n) {
|
||||
return luaData.fflua_pushinteger(L, n);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE void(lua_pushnumber)(lua_State* L, lua_Number n) {
|
||||
[[gnu::always_inline]] void(lua_pushnumber)(lua_State* L, lua_Number n) {
|
||||
return luaData.fflua_pushnumber(L, n);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE void(lua_pushboolean)(lua_State* L, int b) {
|
||||
[[gnu::always_inline]] void(lua_pushboolean)(lua_State* L, int b) {
|
||||
return luaData.fflua_pushboolean(L, b);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE const char*(lua_pushlstring) (lua_State * L, const char* s, size_t len) {
|
||||
[[gnu::always_inline]] const char*(lua_pushlstring) (lua_State * L, const char* s, size_t len) {
|
||||
return luaData.fflua_pushlstring(L, s, len);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE void(lua_pushvalue)(lua_State* L, int idx) {
|
||||
[[gnu::always_inline]] void(lua_pushvalue)(lua_State* L, int idx) {
|
||||
return luaData.fflua_pushvalue(L, idx);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE void(lua_seti)(lua_State* L, int idx, lua_Integer n) {
|
||||
[[gnu::always_inline]] void(lua_seti)(lua_State* L, int idx, lua_Integer n) {
|
||||
return luaData.fflua_seti(L, idx, n);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE void(lua_pushnil)(lua_State* L) {
|
||||
[[gnu::always_inline]] void(lua_pushnil)(lua_State* L) {
|
||||
return luaData.fflua_pushnil(L);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE void(lua_setfield)(lua_State* L, int idx, const char* k) {
|
||||
[[gnu::always_inline]] void(lua_setfield)(lua_State* L, int idx, const char* k) {
|
||||
return luaData.fflua_setfield(L, idx, k);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE int(lua_pcallk)(lua_State* L, int nargs, int nresults, int errfunc, lua_KContext ctx, lua_KFunction k) {
|
||||
[[gnu::always_inline]] int(lua_pcallk)(lua_State* L, int nargs, int nresults, int errfunc, lua_KContext ctx, lua_KFunction k) {
|
||||
return luaData.fflua_pcallk(L, nargs, nresults, errfunc, ctx, k);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE int(lua_gettop)(lua_State* L) {
|
||||
[[gnu::always_inline]] int(lua_gettop)(lua_State* L) {
|
||||
return luaData.fflua_gettop(L);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE const char*(luaL_tolstring) (lua_State * L, int idx, size_t* len) {
|
||||
[[gnu::always_inline]] const char*(luaL_tolstring) (lua_State * L, int idx, size_t* len) {
|
||||
return luaData.ffluaL_tolstring(L, idx, len);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE int(lua_error)(lua_State* L) {
|
||||
[[gnu::always_inline]] int(lua_error)(lua_State* L) {
|
||||
return luaData.fflua_error(L);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE void(lua_pushcclosure)(lua_State* L, lua_CFunction fn, int n) {
|
||||
[[gnu::always_inline]] void(lua_pushcclosure)(lua_State* L, lua_CFunction fn, int n) {
|
||||
return luaData.fflua_pushcclosure(L, fn, n);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE void(luaL_checkany)(lua_State* L, int idx) {
|
||||
[[gnu::always_inline]] void(luaL_checkany)(lua_State* L, int idx) {
|
||||
return luaData.ffluaL_checkany(L, idx);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE void(lua_callk)(lua_State* L, int nargs, int nresults, lua_KContext ctx, lua_KFunction k) {
|
||||
[[gnu::always_inline]] void(lua_callk)(lua_State* L, int nargs, int nresults, lua_KContext ctx, lua_KFunction k) {
|
||||
return luaData.fflua_callk(L, nargs, nresults, ctx, k);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE int(lua_isinteger)(lua_State* L, int idx) {
|
||||
[[gnu::always_inline]] int(lua_isinteger)(lua_State* L, int idx) {
|
||||
return luaData.fflua_isinteger(L, idx);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE int(lua_next)(lua_State* L, int idx) {
|
||||
[[gnu::always_inline]] int(lua_next)(lua_State* L, int idx) {
|
||||
return luaData.fflua_next(L, idx);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE int(lua_rawgeti)(lua_State* L, int idx, lua_Integer n) {
|
||||
[[gnu::always_inline]] int(lua_rawgeti)(lua_State* L, int idx, lua_Integer n) {
|
||||
return luaData.fflua_rawgeti(L, idx, n);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE
|
||||
[[gnu::always_inline]]
|
||||
#if LUA_VERSION_NUM > 503
|
||||
lua_Unsigned
|
||||
#else
|
||||
@@ -161,23 +161,23 @@ size_t
|
||||
return luaData.fflua_rawlen(L, idx);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE void(lua_setglobal)(lua_State* L, const char* name) {
|
||||
[[gnu::always_inline]] void(lua_setglobal)(lua_State* L, const char* name) {
|
||||
return luaData.fflua_setglobal(L, name);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE int(lua_toboolean)(lua_State* L, int idx) {
|
||||
[[gnu::always_inline]] int(lua_toboolean)(lua_State* L, int idx) {
|
||||
return luaData.fflua_toboolean(L, idx);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE lua_Integer(lua_tointegerx)(lua_State* L, int idx, int* isnum) {
|
||||
[[gnu::always_inline]] lua_Integer(lua_tointegerx)(lua_State* L, int idx, int* isnum) {
|
||||
return luaData.fflua_tointegerx(L, idx, isnum);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE lua_Number(lua_tonumberx)(lua_State* L, int idx, int* isnum) {
|
||||
[[gnu::always_inline]] lua_Number(lua_tonumberx)(lua_State* L, int idx, int* isnum) {
|
||||
return luaData.fflua_tonumberx(L, idx, isnum);
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE int(lua_type)(lua_State* L, int idx) {
|
||||
[[gnu::always_inline]] int(lua_type)(lua_State* L, int idx) {
|
||||
return luaData.fflua_type(L, idx);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "common/attributes.h"
|
||||
|
||||
#if FF_HAVE_MALLOC_USABLE_SIZE || FF_HAVE_MSVC_MSIZE
|
||||
#if __has_include(<malloc.h>)
|
||||
@@ -14,7 +13,7 @@
|
||||
#include <malloc/malloc.h>
|
||||
#endif
|
||||
|
||||
FF_A_ALWAYS_INLINE FF_A_NONNULL(1)
|
||||
[[gnu::always_inline, gnu::nonnull(1)]]
|
||||
static inline void ffWrapFree(const void* pPtr) {
|
||||
assert(pPtr);
|
||||
if (*(void**) pPtr) {
|
||||
@@ -22,7 +21,7 @@ static inline void ffWrapFree(const void* pPtr) {
|
||||
}
|
||||
}
|
||||
|
||||
#define FF_AUTO_FREE FF_A_CLEANUP(ffWrapFree)
|
||||
#define FF_AUTO_FREE [[gnu::cleanup(ffWrapFree)]]
|
||||
|
||||
// ptr MUST be a malloc'ed pointer
|
||||
static inline size_t ffMallocUsableSize(const void* ptr) {
|
||||
|
||||
+4
-4
@@ -65,10 +65,10 @@ typedef struct FFKeyValuePair {
|
||||
|
||||
const char* ffOptionTestPrefix(const char* argumentKey, const char* moduleName);
|
||||
void ffOptionParseString(const char* argumentKey, const char* value, FFstrbuf* buffer);
|
||||
FF_A_NODISCARD uint32_t ffOptionParseUInt32(const char* argumentKey, const char* value);
|
||||
FF_A_NODISCARD int32_t ffOptionParseInt32(const char* argumentKey, const char* value);
|
||||
FF_A_NODISCARD int ffOptionParseEnum(const char* argumentKey, const char* requestedKey, FFKeyValuePair pairs[]);
|
||||
FF_A_NODISCARD bool ffOptionParseBoolean(const char* str);
|
||||
[[nodiscard]] uint32_t ffOptionParseUInt32(const char* argumentKey, const char* value);
|
||||
[[nodiscard]] int32_t ffOptionParseInt32(const char* argumentKey, const char* value);
|
||||
[[nodiscard]] int ffOptionParseEnum(const char* argumentKey, const char* requestedKey, FFKeyValuePair pairs[]);
|
||||
[[nodiscard]] bool ffOptionParseBoolean(const char* str);
|
||||
void ffOptionParseColorNoClear(const char* value, FFstrbuf* buffer);
|
||||
static inline void ffOptionParseColor(const char* value, FFstrbuf* buffer) {
|
||||
ffStrbufClear(buffer);
|
||||
|
||||
@@ -15,6 +15,6 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModu
|
||||
bool ffPrintFormat(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, uint32_t numArgs, const FFformatarg* arguments);
|
||||
#define FF_PRINT_FORMAT_CHECKED(moduleName, moduleIndex, moduleArgs, printType, arguments) \
|
||||
ffPrintFormat((moduleName), (moduleIndex), (moduleArgs), (printType), (sizeof(arguments) / sizeof(*arguments)), (arguments));
|
||||
FF_A_PRINTF(5, 6) void ffPrintError(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, const char* message, ...);
|
||||
[[gnu::format(printf, 5, 6)]] void ffPrintError(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, const char* message, ...);
|
||||
void ffPrintColor(const FFstrbuf* colorValue);
|
||||
void ffPrintCharTimes(char c, uint32_t times);
|
||||
|
||||
+2
-2
@@ -67,7 +67,7 @@ typedef enum FFSmbiosType : uint8_t {
|
||||
} FFSmbiosType;
|
||||
static_assert(sizeof(FFSmbiosType) == 1, "FFSmbiosType should be 1 byte");
|
||||
|
||||
typedef struct FFSmbiosHeader {
|
||||
typedef struct [[gnu::packed]] FFSmbiosHeader {
|
||||
// Type of SMBIOS structure. Do NOT test `Type == FF_SMBIOS_END_OF_TABLE` to determine the end of the table,
|
||||
// as malformed tables may be missing the end-of-table marker.
|
||||
// **Use FFSmbiosHeaderTable[FF_SMBIOS_TYPE_END_OF_TABLE] pointer instead.**
|
||||
@@ -79,7 +79,7 @@ typedef struct FFSmbiosHeader {
|
||||
// Not guaranteed to be consistent across reboots or even multiple reads of the same table.
|
||||
// Must be less than 0xFF00
|
||||
uint16_t Handle;
|
||||
} FF_A_PACKED FFSmbiosHeader;
|
||||
} FFSmbiosHeader;
|
||||
static_assert(sizeof(FFSmbiosHeader) == 4, "FFSmbiosHeader should be 4 bytes");
|
||||
|
||||
static inline const char* ffSmbiosLocateString(const char* start, uint8_t index /* start from 1 */) {
|
||||
|
||||
+10
-13
@@ -5,9 +5,6 @@
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "common/attributes.h"
|
||||
#include "common/wcwidth.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
// #include <shlwapi.h>
|
||||
__stdcall char* StrStrIA(const char* lpFirst, const char* lpSrch);
|
||||
@@ -29,17 +26,17 @@ static inline bool ffStrSet(const char* str) {
|
||||
return *str != '\0';
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE
|
||||
[[gnu::always_inline]]
|
||||
static inline bool ffStrStartsWithIgnCase(const char* str, const char* compareTo) {
|
||||
return strncasecmp(str, compareTo, strlen(compareTo)) == 0;
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE
|
||||
[[gnu::always_inline]]
|
||||
static inline bool ffStrEqualsIgnCase(const char* str, const char* compareTo) {
|
||||
return strcasecmp(str, compareTo) == 0;
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE
|
||||
[[gnu::always_inline]]
|
||||
static inline bool ffStrStartsWith(const char* str, const char* compareTo) {
|
||||
return strncmp(str, compareTo, strlen(compareTo)) == 0;
|
||||
}
|
||||
@@ -62,32 +59,32 @@ static inline bool ffStrEndsWithIgnCase(const char* str, const char* compareTo)
|
||||
return strncasecmp(str + strLength - compareToLength, compareTo, compareToLength) == 0;
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE
|
||||
[[gnu::always_inline]]
|
||||
static inline bool ffStrEquals(const char* str, const char* compareTo) {
|
||||
return strcmp(str, compareTo) == 0;
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE
|
||||
[[gnu::always_inline]]
|
||||
static inline bool ffStrContains(const char* str, const char* compareTo) {
|
||||
return strstr(str, compareTo) != nullptr;
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE
|
||||
[[gnu::always_inline]]
|
||||
static inline bool ffStrContainsIgnCase(const char* str, const char* compareTo) {
|
||||
return strcasestr(str, compareTo) != nullptr;
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE
|
||||
[[gnu::always_inline]]
|
||||
static inline bool ffStrContainsC(const char* str, char compareTo) {
|
||||
return strchr(str, compareTo) != nullptr;
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE
|
||||
[[gnu::always_inline]]
|
||||
static inline bool ffCharIsEnglishAlphabet(char c) {
|
||||
return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
|
||||
}
|
||||
|
||||
FF_A_ALWAYS_INLINE
|
||||
[[gnu::always_inline]]
|
||||
static inline bool ffCharIsDigit(char c) {
|
||||
return '0' <= c && c <= '9';
|
||||
}
|
||||
@@ -99,7 +96,7 @@ uint8_t ffUtf8CharLenWidth(const char* str, uint32_t length, uint8_t* width);
|
||||
|
||||
uint32_t ffUtf8StrWidth(const char* str, uint32_t length);
|
||||
|
||||
FF_A_ALWAYS_INLINE
|
||||
[[gnu::always_inline]]
|
||||
static inline bool ffCharIsHexDigit(char c) {
|
||||
return ffCharIsDigit(c) || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F');
|
||||
}
|
||||
|
||||
+5
-5
@@ -7,11 +7,11 @@
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
const char* ffSysctlGetString(int mib1, int mib2, FFstrbuf* result);
|
||||
FF_A_NODISCARD int ffSysctlGetInt(int mib1, int mib2, int defaultValue);
|
||||
FF_A_NODISCARD int64_t ffSysctlGetInt64(int mib1, int mib2, int64_t defaultValue);
|
||||
[[nodiscard]] int ffSysctlGetInt(int mib1, int mib2, int defaultValue);
|
||||
[[nodiscard]] int64_t ffSysctlGetInt64(int mib1, int mib2, int64_t defaultValue);
|
||||
#else
|
||||
const char* ffSysctlGetString(const char* propName, FFstrbuf* result);
|
||||
FF_A_NODISCARD int ffSysctlGetInt(const char* propName, int defaultValue);
|
||||
FF_A_NODISCARD int64_t ffSysctlGetInt64(const char* propName, int64_t defaultValue);
|
||||
[[nodiscard]] int ffSysctlGetInt(const char* propName, int defaultValue);
|
||||
[[nodiscard]] int64_t ffSysctlGetInt64(const char* propName, int64_t defaultValue);
|
||||
#endif
|
||||
FF_A_NODISCARD void* ffSysctlGetData(int* request, u_int requestLength, size_t* resultLength);
|
||||
[[nodiscard]] void* ffSysctlGetData(int* request, u_int requestLength, size_t* resultLength);
|
||||
|
||||
+3
-3
@@ -90,7 +90,7 @@ static inline FFThreadType ffThreadCreate(void* (*func)(void*), void* data) {
|
||||
static inline void ffThreadDetach(FFThreadType thread) {
|
||||
pthread_detach(thread);
|
||||
}
|
||||
static inline bool ffThreadJoin(FFThreadType thread, FF_A_UNUSED uint32_t timeout) {
|
||||
static inline bool ffThreadJoin(FFThreadType thread, [[maybe_unused]] uint32_t timeout) {
|
||||
#if HAVE_TIMEDJOIN_NP
|
||||
if (timeout > 0) {
|
||||
struct timespec ts;
|
||||
@@ -115,7 +115,7 @@ static inline uintptr_t ffThreadGetCurrentId() {
|
||||
#else // FF_HAVE_THREADS
|
||||
#define FF_THREAD_MUTEX_INITIALIZER 0
|
||||
typedef char FFThreadMutex;
|
||||
static inline void ffThreadMutexLock(FF_A_UNUSED FFThreadMutex* mutex) {}
|
||||
static inline void ffThreadMutexUnlock(FF_A_UNUSED FFThreadMutex* mutex) {}
|
||||
static inline void ffThreadMutexLock([[maybe_unused]] FFThreadMutex* mutex) {}
|
||||
static inline void ffThreadMutexUnlock([[maybe_unused]] FFThreadMutex* mutex) {}
|
||||
#define FF_THREAD_ENTRY_DECL_WRAPPER(fn, paramType)
|
||||
#endif // FF_HAVE_THREADS
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/attributes.h"
|
||||
#include <assert.h>
|
||||
#include <unknwn.h>
|
||||
|
||||
@@ -20,4 +19,4 @@ static inline void ffReleaseComObject(void* ppUnknown) {
|
||||
}
|
||||
}
|
||||
|
||||
#define FF_AUTO_RELEASE_COM_OBJECT FF_A_CLEANUP(ffReleaseComObject)
|
||||
#define FF_AUTO_RELEASE_COM_OBJECT [[gnu::cleanup(ffReleaseComObject)]]
|
||||
|
||||
@@ -49,6 +49,4 @@ static inline void ffCloseWmiBlock(HANDLE* hBlock) {
|
||||
}
|
||||
}
|
||||
|
||||
#define FF_AUTO_CLOSE_WMI_BLOCK __attribute__((cleanup(ffCloseWmiBlock)))
|
||||
|
||||
// MOF: https://github.com/tpn/winsdk-10/blob/master/Include/10.0.16299.0/km/wmicore.mof
|
||||
|
||||
Reference in New Issue
Block a user