Global: formats code [ci skip]

This commit is contained in:
李通洲
2026-04-12 19:19:55 +08:00
parent 4dc5033c80
commit 679def253d
9 changed files with 51 additions and 54 deletions
+5 -8
View File
@@ -47,8 +47,7 @@ void ffStrbufAppendC(FFstrbuf* strbuf, char c);
void ffStrbufAppendNC(FFstrbuf* strbuf, uint32_t num, char c);
void ffStrbufAppendNS(FFstrbuf* strbuf, uint32_t length, const char* value);
void ffStrbufAppendTransformS(FFstrbuf* strbuf, const char* value, int (*transformFunc)(int));
FF_A_PRINTF(2, 3)
void ffStrbufAppendF(FFstrbuf* strbuf, const char* format, ...);
FF_A_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);
@@ -61,8 +60,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, ...);
FF_A_PRINTF(2, 3) void ffStrbufSetF(FFstrbuf* strbuf, const char* format, ...);
void ffStrbufTrimLeft(FFstrbuf* strbuf, char c);
void ffStrbufTrimRight(FFstrbuf* strbuf, char c);
@@ -194,16 +192,15 @@ FF_A_NODISCARD static inline FFstrbuf ffStrbufCreateVF(const char* format, va_li
return strbuf;
}
FF_A_PRINTF(2, 3)
static inline void ffStrbufInitF(FFstrbuf* strbuf, const char* format, ...) {
FF_A_PRINTF(2, 3) static inline void ffStrbufInitF(FFstrbuf* strbuf, const char* format, ...) {
va_list arguments;
va_start(arguments, format);
ffStrbufInitVF(strbuf, format, arguments);
va_end(arguments);
}
FF_A_PRINTF(1, 2)
FF_A_NODISCARD static inline FFstrbuf ffStrbufCreateF(const char* format, ...) {
FF_A_PRINTF(1, 2) FF_A_NODISCARD static inline FFstrbuf
ffStrbufCreateF(const char* format, ...) {
FFstrbuf strbuf;
va_list arguments;
+18 -36
View File
@@ -49,8 +49,7 @@ static inline bool ffIsValidNativeFD(FFNativeFD fd) {
#endif
}
FF_A_NONNULL(1)
static inline bool wrapClose(FFNativeFD* pfd) {
FF_A_NONNULL(1) static inline bool wrapClose(FFNativeFD* pfd) {
assert(pfd);
if (!ffIsValidNativeFD(*pfd)) {
@@ -75,8 +74,7 @@ static inline FFNativeFD FFUnixFD2NativeFD(int unixfd) {
#endif
}
FF_A_NONNULL(3)
static inline bool ffWriteFDData(FFNativeFD fd, size_t dataSize, const void* data) {
FF_A_NONNULL(3) static inline bool ffWriteFDData(FFNativeFD fd, size_t dataSize, const void* data) {
#ifndef _WIN32
return write(fd, data, dataSize) != -1;
#else
@@ -85,21 +83,17 @@ static inline bool ffWriteFDData(FFNativeFD fd, size_t dataSize, const void* dat
#endif
}
FF_A_NONNULL(2)
static inline bool ffWriteFDBuffer(FFNativeFD fd, const FFstrbuf* content) {
FF_A_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);
FF_A_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) {
FF_A_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) {
FF_A_NONNULL(3) static inline ssize_t ffReadFDData(FFNativeFD fd, size_t dataSize, void* data) {
#ifndef _WIN32
return read(fd, data, dataSize);
#else
@@ -112,11 +106,9 @@ static inline ssize_t ffReadFDData(FFNativeFD fd, size_t dataSize, void* data) {
#endif
}
FF_A_NONNULL(2)
bool ffAppendFDBuffer(FFNativeFD fd, FFstrbuf* buffer);
FF_A_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) {
FF_A_NONNULL(1, 3) static inline ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data) {
FFNativeFD FF_AUTO_CLOSE_FD fd =
#ifndef _WIN32
open(fileName, O_RDONLY | O_CLOEXEC);
@@ -131,8 +123,7 @@ static inline ssize_t ffReadFileData(const char* fileName, size_t dataSize, void
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) {
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);
if (!ffIsValidNativeFD(fd)) {
return -1;
@@ -141,8 +132,7 @@ static inline ssize_t ffReadFileDataRelative(FFNativeFD dfd, const char* fileNam
return ffReadFDData(fd, dataSize, data);
}
FF_A_NONNULL(1, 2)
static inline bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer) {
FF_A_NONNULL(1, 2) static inline bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer) {
FFNativeFD FF_AUTO_CLOSE_FD fd =
#ifndef _WIN32
open(fileName, O_RDONLY | O_CLOEXEC);
@@ -157,8 +147,7 @@ static inline bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer) {
return ffAppendFDBuffer(fd, buffer);
}
FF_A_NONNULL(2, 3)
static inline bool ffAppendFileBufferRelative(FFNativeFD dfd, const char* fileName, FFstrbuf* 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);
if (!ffIsValidNativeFD(fd)) {
return false;
@@ -167,20 +156,17 @@ static inline bool ffAppendFileBufferRelative(FFNativeFD dfd, const char* fileNa
return ffAppendFDBuffer(fd, buffer);
}
FF_A_NONNULL(2)
static inline bool ffReadFDBuffer(FFNativeFD fd, FFstrbuf* buffer) {
FF_A_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) {
FF_A_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) {
FF_A_NONNULL(2, 3) static inline bool ffReadFileBufferRelative(FFNativeFD dfd, const char* fileName, FFstrbuf* buffer) {
ffStrbufClear(buffer);
return ffAppendFileBufferRelative(dfd, fileName, buffer);
}
@@ -192,8 +178,7 @@ typedef enum FF_A_PACKED FFPathType {
FF_PATHTYPE_FORCE_UNSIGNED = UINT8_MAX,
} FFPathType;
FF_A_NONNULL(1)
static inline bool ffPathExists(const char* path, FFPathType pathType) {
FF_A_NONNULL(1) static inline bool ffPathExists(const char* path, FFPathType pathType) {
#ifdef _WIN32
wchar_t wPath[MAX_PATH];
@@ -242,8 +227,7 @@ static inline bool ffPathExists(const char* path, FFPathType pathType) {
return false;
}
FF_A_NONNULL(1, 2)
bool ffPathExpandEnv(const char* in, FFstrbuf* out);
FF_A_NONNULL(1, 2) bool ffPathExpandEnv(const char* in, FFstrbuf* out);
#define FF_IO_TERM_RESP_WAIT_MS 100 // #554
@@ -266,8 +250,7 @@ static inline void ffUnsuppressIO(bool* suppressed) {
void ffListFilesRecursively(const char* path, bool pretty);
FF_A_NONNULL(1)
static inline bool wrapFclose(FILE** pfile) {
FF_A_NONNULL(1) static inline bool wrapFclose(FILE** pfile) {
assert(pfile);
if (!*pfile) {
return false;
@@ -299,8 +282,7 @@ static inline bool wrapClosedir(HANDLE* pdir) {
#endif
#define FF_AUTO_CLOSE_DIR FF_A_CLEANUP(wrapClosedir)
FF_A_NONNULL(1, 2, 3)
static inline bool ffSearchUserConfigFile(const FFlist* configDirs, const char* fileSubpath, FFstrbuf* result) {
FF_A_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);
+2 -2
View File
@@ -35,9 +35,9 @@ static inline void ffLibraryUnload(void** handle) {
# define FF_LIBRARY_SYMBOL(symbolName) \
__typeof__(&symbolName) ff##symbolName;
# define FF_LIBRARY_LOAD(libraryObjectName, returnValue, ...) \
# define FF_LIBRARY_LOAD(libraryObjectName, returnValue, ...) \
void* FF_A_CLEANUP(ffLibraryUnload) libraryObjectName = ffLibraryLoad(__VA_ARGS__, NULL); \
if (libraryObjectName == NULL) \
if (libraryObjectName == NULL) \
return returnValue;
# define FF_LIBRARY_LOAD_MESSAGE(libraryObjectName, libraryFileName, maxVersion, ...) \
+1 -2
View File
@@ -16,7 +16,6 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModu
void 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, ...);
FF_A_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);