Skip to content

Commit 27a1d9f

Browse files
committed
Logo (Image): fix building on Windows
1 parent d50ebc8 commit 27a1d9f

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/common/io/io.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
#include <handleapi.h>
99
#include <io.h>
1010
typedef HANDLE FFNativeFD;
11+
#define FF_INVALID_FD INVALID_HANDLE_VALUE
1112
#else
1213
#include <unistd.h>
1314
#include <dirent.h>
1415
#include <sys/stat.h>
1516
typedef int FFNativeFD;
17+
#define FF_INVALID_FD (-1)
1618
// procfs's file can be changed between read calls such as /proc/meminfo and /proc/uptime.
1719
// one safe way to read correct data is reading the whole file in a single read syscall
1820
// 8192 comes from procps-ng: https://gitlab.com/procps-ng/procps/-/blob/master/library/meminfo.c?ref_type=heads#L39

src/logo/image/image.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,15 +670,20 @@ FFLogoImageResult ffLogoPrintImageImpl(FFLogoRequestData* requestData, const FFI
670670
return printSuccessful ? FF_LOGO_IMAGE_RESULT_SUCCESS : FF_LOGO_IMAGE_RESULT_RUN_ERROR;
671671
}
672672

673-
static int getCacheFD(FFLogoRequestData* requestData, const char* fileName)
673+
static FFNativeFD getCacheFD(FFLogoRequestData* requestData, const char* fileName)
674674
{
675675
uint32_t cacheDirLength = requestData->cacheDir.length;
676676
ffStrbufAppendS(&requestData->cacheDir, fileName);
677+
#ifndef _WIN32
677678
int fd = open(requestData->cacheDir.chars, O_RDONLY
678679
#ifdef O_CLOEXEC
679680
| O_CLOEXEC
680681
#endif
681682
);
683+
#else
684+
HANDLE fd = CreateFileA(requestData->cacheDir.chars, GENERIC_READ,
685+
FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
686+
#endif
682687
ffStrbufSubstrBefore(&requestData->cacheDir, cacheDirLength);
683688
return fd;
684689
}
@@ -740,17 +745,17 @@ static bool printCachedPixel(FFLogoRequestData* requestData)
740745
return false;
741746
}
742747

743-
FF_AUTO_CLOSE_FD int fd = -1;
748+
FF_AUTO_CLOSE_FD FFNativeFD fd = FF_INVALID_FD;
744749
if(requestData->type == FF_LOGO_TYPE_IMAGE_KITTY)
745750
{
746751
fd = getCacheFD(requestData, FF_CACHE_FILE_KITTY_COMPRESSED);
747-
if(fd == -1)
752+
if(fd == FF_INVALID_FD)
748753
fd = getCacheFD(requestData, FF_CACHE_FILE_KITTY_UNCOMPRESSED);
749754
}
750755
else if(requestData->type == FF_LOGO_TYPE_IMAGE_SIXEL)
751756
fd = getCacheFD(requestData, FF_CACHE_FILE_SIXEL);
752757

753-
if(fd == -1)
758+
if(fd == FF_INVALID_FD)
754759
return false;
755760

756761
ffPrintCharTimes('\n', options->paddingTop);
@@ -783,7 +788,7 @@ static bool printCachedPixel(FFLogoRequestData* requestData)
783788
{
784789
char buffer[32768];
785790
ssize_t readBytes;
786-
while((readBytes = ffReadFDData(FFUnixFD2NativeFD(fd), sizeof(buffer), buffer)) > 0)
791+
while((readBytes = ffReadFDData(fd, sizeof(buffer), buffer)) > 0)
787792
ffWriteFDData(FFUnixFD2NativeFD(STDOUT_FILENO), (size_t) readBytes, buffer);
788793
}
789794

0 commit comments

Comments
 (0)