Skip to content

Commit e99ecac

Browse files
committed
Chore: adds ffIsValidNativeFD and uses it
1 parent 3e22dd4 commit e99ecac

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/common/io/io.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,27 @@ static inline void ffUnsuppressIO(bool* suppressed)
171171

172172
void ffListFilesRecursively(const char* path, bool pretty);
173173

174+
static inline bool ffIsValidNativeFD(FFNativeFD fd)
175+
{
176+
#ifndef _WIN32
177+
return fd >= 0;
178+
#else
179+
// https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
180+
return fd != INVALID_HANDLE_VALUE && fd != NULL;
181+
#endif
182+
}
183+
174184
FF_C_NONNULL(1)
175185
static inline bool wrapClose(FFNativeFD* pfd)
176186
{
177187
assert(pfd);
178188

179-
#ifndef WIN32
180-
if (*pfd < 0)
181-
return false;
189+
if (!ffIsValidNativeFD(*pfd))
190+
return false;
191+
192+
#ifndef _WIN32
182193
close(*pfd);
183194
#else
184-
// https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
185-
if (*pfd == NULL || *pfd == INVALID_HANDLE_VALUE)
186-
return false;
187195
CloseHandle(*pfd);
188196
#endif
189197

src/logo/image/image.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,13 +891,13 @@ static bool printCachedPixel(FFLogoRequestData* requestData)
891891
if(requestData->type == FF_LOGO_TYPE_IMAGE_KITTY)
892892
{
893893
fd = getCacheFD(requestData, FF_CACHE_FILE_KITTY_COMPRESSED);
894-
if(fd == FF_INVALID_FD)
894+
if(!ffIsValidNativeFD(fd))
895895
fd = getCacheFD(requestData, FF_CACHE_FILE_KITTY_UNCOMPRESSED);
896896
}
897897
else if(requestData->type == FF_LOGO_TYPE_IMAGE_SIXEL)
898898
fd = getCacheFD(requestData, FF_CACHE_FILE_SIXEL);
899899

900-
if(fd == FF_INVALID_FD)
900+
if(!ffIsValidNativeFD(fd))
901901
return false;
902902

903903
ffPrintCharTimes('\n', options->paddingTop);

0 commit comments

Comments
 (0)