Chore: adds ffIsValidNativeFD and uses it

This commit is contained in:
李通洲
2025-12-02 15:38:19 +08:00
parent 3e22dd4b0e
commit e99ecacb52
2 changed files with 16 additions and 8 deletions
+14 -6
View File
@@ -171,19 +171,27 @@ static inline void ffUnsuppressIO(bool* suppressed)
void ffListFilesRecursively(const char* path, bool pretty);
static inline bool ffIsValidNativeFD(FFNativeFD fd)
{
#ifndef _WIN32
return fd >= 0;
#else
// https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
return fd != INVALID_HANDLE_VALUE && fd != NULL;
#endif
}
FF_C_NONNULL(1)
static inline bool wrapClose(FFNativeFD* pfd)
{
assert(pfd);
#ifndef WIN32
if (*pfd < 0)
return false;
if (!ffIsValidNativeFD(*pfd))
return false;
#ifndef _WIN32
close(*pfd);
#else
// https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
if (*pfd == NULL || *pfd == INVALID_HANDLE_VALUE)
return false;
CloseHandle(*pfd);
#endif
+2 -2
View File
@@ -891,13 +891,13 @@ static bool printCachedPixel(FFLogoRequestData* requestData)
if(requestData->type == FF_LOGO_TYPE_IMAGE_KITTY)
{
fd = getCacheFD(requestData, FF_CACHE_FILE_KITTY_COMPRESSED);
if(fd == FF_INVALID_FD)
if(!ffIsValidNativeFD(fd))
fd = getCacheFD(requestData, FF_CACHE_FILE_KITTY_UNCOMPRESSED);
}
else if(requestData->type == FF_LOGO_TYPE_IMAGE_SIXEL)
fd = getCacheFD(requestData, FF_CACHE_FILE_SIXEL);
if(fd == FF_INVALID_FD)
if(!ffIsValidNativeFD(fd))
return false;
ffPrintCharTimes('\n', options->paddingTop);