Skip to content

Commit 2a65be0

Browse files
committed
[Win] init
1 parent 1a996c3 commit 2a65be0

File tree

22 files changed

+1228
-22
lines changed

22 files changed

+1228
-22
lines changed

CMakeLists.txt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if("${CMAKE_SYSTEM_NAME}" MATCHES ".*[Ll]inux.*")
1515
set(LINUX TRUE CACHE BOOL "..." FORCE) # LINUX means GNU/Linux, not just the kernel
1616
elseif("${CMAKE_SYSTEM_NAME}" MATCHES ".*[Bb][Ss][Dd].*")
1717
set(BSD TRUE CACHE BOOL "..." FORCE)
18-
elseif(NOT APPLE AND NOT ANDROID)
18+
elseif(NOT APPLE AND NOT ANDROID AND NOT WIN32)
1919
message(FATAL_ERROR "Unsupported platform")
2020
endif()
2121

@@ -81,9 +81,11 @@ if(APPLE AND DEFINED ENV{HOMEBREW_PREFIX})
8181
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,$ENV{HOMEBREW_PREFIX}/lib")
8282
endif()
8383

84-
set(FASTFETCH_FLAGS_DEBUG "-fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined")
85-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FASTFETCH_FLAGS_DEBUG}")
86-
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} ${FASTFETCH_FLAGS_DEBUG} -rdynamic")
84+
if(NOT WIN32)
85+
set(FASTFETCH_FLAGS_DEBUG "-fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined")
86+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FASTFETCH_FLAGS_DEBUG}")
87+
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} ${FASTFETCH_FLAGS_DEBUG} -rdynamic")
88+
endif()
8789

8890
include(CheckIPOSupported)
8991
check_ipo_supported(RESULT IPO_SUPPORTED)
@@ -257,7 +259,7 @@ if(LINUX OR ANDROID)
257259
)
258260
endif()
259261

260-
if(LINUX OR ANDROID OR BSD)
262+
if(NOT WIN32 AND (LINUX OR ANDROID OR BSD))
261263
list(APPEND LIBFASTFETCH_SRC
262264
src/detection/cpuUsage/cpuUsage_linux.c
263265
src/detection/battery/battery_linux.c
@@ -320,6 +322,15 @@ if(ANDROID)
320322
)
321323
endif()
322324

325+
if(WIN32)
326+
list(APPEND LIBFASTFETCH_SRC
327+
src/util/windows/dlfcn.c
328+
src/util/windows/getline.c
329+
src/util/windows/pwd.c
330+
src/util/windows/uname.c
331+
)
332+
endif()
333+
323334
add_library(libfastfetch OBJECT
324335
${LIBFASTFETCH_SRC}
325336
)

src/common/init.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,30 @@ static void initCacheDir(FFstate* state)
101101
else
102102
ffStrbufEnsureEndsWithC(&state->cacheDir, '/');
103103

104-
mkdir(state->cacheDir.chars, S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH); //I hope everybody has a cache folder, but who knows
104+
mkdir(state->cacheDir.chars
105+
#ifndef WIN32
106+
, S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH
107+
#endif
108+
); //I hope everybody has a cache folder, but who knows
105109

106110
ffStrbufAppendS(&state->cacheDir, "fastfetch/");
107-
mkdir(state->cacheDir.chars, S_IRWXU | S_IRGRP | S_IROTH);
111+
mkdir(state->cacheDir.chars
112+
#ifndef WIN32
113+
, S_IRWXU | S_IRGRP | S_IROTH
114+
#endif
115+
);
108116
}
109117

110118
static void initState(FFstate* state)
111119
{
112120
state->logoWidth = 0;
113121
state->logoHeight = 0;
114122
state->keysHeight = 0;
123+
#ifndef _WIN32
115124
state->passwd = getpwuid(getuid());
125+
#else
126+
state->passwd = ffGetPasswd();
127+
#endif
116128
uname(&state->utsname);
117129

118130
#if FF_HAVE_SYSINFO_H
@@ -354,12 +366,14 @@ void ffStart(FFinstance* instance)
354366
ffDisableLinewrap = instance->config.disableLinewrap && !instance->config.pipe;
355367
ffHideCursor = instance->config.hideCursor && !instance->config.pipe;
356368

369+
#ifndef WIN32
357370
struct sigaction action = {};
358371
action.sa_handler = exitSignalHandler;
359372

360373
sigaction(SIGINT, &action, NULL);
361374
sigaction(SIGTERM, &action, NULL);
362375
sigaction(SIGQUIT, &action, NULL);
376+
#endif
363377

364378
//We do the cache validation here, so we can skip it if --recache is given
365379
if(!instance->config.recache)

src/common/io.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
#include <sys/stat.h>
55
#include <unistd.h>
66
#include <fcntl.h>
7-
#include <termios.h>
8-
#include <poll.h>
7+
#ifndef WIN32
8+
#include <termios.h>
9+
#include <poll.h>
10+
#endif
911

1012
static void createSubfolders(const char* fileName)
1113
{
@@ -16,7 +18,11 @@ static void createSubfolders(const char* fileName)
1618
{
1719
ffStrbufAppendC(&path, *fileName);
1820
if(*fileName == '/')
19-
mkdir(path.chars, S_IRWXU | S_IRGRP | S_IROTH);
21+
mkdir(path.chars
22+
#ifndef WIN32
23+
, S_IRWXU | S_IRGRP | S_IROTH
24+
#endif
25+
);
2026
++fileName;
2127
}
2228

@@ -149,6 +155,7 @@ bool ffFileExists(const char* fileName, mode_t mode)
149155
return stat(fileName, &fileStat) == 0 && ((fileStat.st_mode & S_IFMT) == mode);
150156
}
151157

158+
#ifndef WIN32
152159
void ffGetTerminalResponse(const char* request, const char* format, ...)
153160
{
154161
struct termios oldTerm, newTerm;
@@ -190,3 +197,4 @@ void ffGetTerminalResponse(const char* request, const char* format, ...)
190197
vsscanf(buffer, format, args);
191198
va_end(args);
192199
}
200+
#endif

src/common/io.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ bool ffFileExists(const char* fileName, mode_t mode);
1919
// Not thread safe!
2020
void ffSuppressIO(bool suppress);
2121

22+
#ifndef WIN32
2223
FF_C_SCANF(2, 3) void ffGetTerminalResponse(const char* request, const char* format, ...);
24+
#endif
2325

2426
#endif

src/common/library.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
#ifndef FF_INCLUDED_common_library
44
#define FF_INCLUDED_common_library
55

6-
#include <dlfcn.h>
6+
#ifndef WIN32
7+
#include <dlfcn.h>
8+
#else
9+
#include "util/windows/dlfcn.h"
10+
#endif
711

8-
#ifdef __APPLE__
12+
#ifdef WIN32
13+
#define FF_LIBRARY_EXTENSION ".dll"
14+
#elif defined(__APPLE__)
915
#define FF_LIBRARY_EXTENSION ".dylib"
1016
#else
1117
#define FF_LIBRARY_EXTENSION ".so"

src/common/networking.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33

44
#include <unistd.h>
55
#include <sys/time.h>
6-
#include <sys/socket.h>
7-
#include <netdb.h>
6+
#ifndef WIN32
7+
#include <sys/socket.h>
8+
#include <netdb.h>
9+
#else
10+
#pragma comment(lib, "Ws2_32.lib")
11+
#include <WinSock2.h>
12+
#include <Ws2tcpip.h>
13+
#endif
814

915
void ffNetworkingGetHttp(const char* host, const char* path, uint32_t timeout, FFstrbuf* buffer)
1016
{

src/common/processing.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "common/io.h"
44

55
#include <stdlib.h>
6+
7+
#ifndef WIN32
68
#include <unistd.h>
79
#include <sys/wait.h>
810

@@ -36,3 +38,13 @@ const char* ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[])
3638

3739
return NULL;
3840
}
41+
42+
#else
43+
44+
const char* ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[])
45+
{
46+
FF_UNUSED(buffer, argv);
47+
return "Unimplemented";
48+
}
49+
50+
#endif

src/common/properties.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#include "common/properties.h"
33

44
#include <stdlib.h>
5+
#ifdef _WIN32
6+
#include "util/windows/getline.h"
7+
#endif
58

69
static bool parsePropLinePointer(const char** line, const char* start, FFstrbuf* buffer)
710
{

src/detection/title.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
#include <limits.h>
55
#include <unistd.h>
66
#include <pthread.h>
7-
#include <netdb.h>
87

98
#ifndef HOST_NAME_MAX
109
#define HOST_NAME_MAX 64
1110
#endif
1211

1312
#ifdef __linux__
13+
#include <netdb.h>
14+
1415
static void detectFQDN(FFTitleResult* title)
1516
{
1617
struct addrinfo hints = {0};

src/fastfetch.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#include <dirent.h>
1111
#include <sys/stat.h>
1212

13+
#ifdef WIN32
14+
#include "util/windows/getline.h"
15+
#endif
16+
1317
typedef struct CustomValue
1418
{
1519
bool printKey;
@@ -420,6 +424,7 @@ static inline void printCommandHelp(const char* command)
420424

421425
static inline void listAvailablePresetsFromFolder(FFstrbuf* folder, uint8_t indentation, const char* folderName)
422426
{
427+
#ifndef WIN32
423428
DIR* dir = opendir(folder->chars);
424429
if(dir == NULL)
425430
return;
@@ -453,6 +458,9 @@ static inline void listAvailablePresetsFromFolder(FFstrbuf* folder, uint8_t inde
453458
}
454459

455460
closedir(dir);
461+
#else
462+
FF_UNUSED(folder, indentation, folderName);
463+
#endif
456464
}
457465

458466
static inline void listAvailablePresets(FFinstance* instance)

0 commit comments

Comments
 (0)