From 322ee8417a5c7337f7a4655d2be452bca0c0c107 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Sat, 16 Dec 2023 01:48:09 +0300 Subject: [PATCH] Add CMake & Attempt to make it compile for Windows --- .gitignore | 1 + CMakeLists.txt | 4 ++++ mycfetch.c | 27 ++++++++++++++++++++++----- 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 CMakeLists.txt diff --git a/.gitignore b/.gitignore index 88cfc38..099d88c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ mycfetch +build diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..37b9ab5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.5) +project(mycfetch LANGUAGES C) + +add_executable(mycfetch mycfetch.c) diff --git a/mycfetch.c b/mycfetch.c index 61c3f66..7842264 100644 --- a/mycfetch.c +++ b/mycfetch.c @@ -1,11 +1,18 @@ #include #include -#include -#include #include #include #include +#ifdef _WIN32 +#include +#include +#include +#else +#include +#include +#endif /* _WIN32 */ + #include "config.h" #include "defs.h" @@ -54,19 +61,29 @@ int main(int argc, char **argv) art = arts[0].art; } - struct utsname uname_buf; char hostname[max_hostname_length]; char username[max_username_length]; char uptime[max_uptime_length]; +#ifdef _WIN32 + RTL_OSVERSIONINFOW version_buffer = {.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOW)}; + RtlGetVersion(&version_buffer); + GetUserNameA(username, max_username_length); +#else + struct utsname uname_buf; - gethostname(hostname, max_hostname_length); getlogin_r(username, max_username_length); - getuptime(uptime, max_uptime_length); uname(&uname_buf); +#endif + gethostname(hostname, max_hostname_length); + getuptime(uptime, max_uptime_length); printf("%s %s@%s\n", art[0], username, hostname); printf("%s --\n", art[1]); +#ifdef _WIN32 + printf("%s NT %u.%u %s\n", art[2], version_buffer.dwMajorVersion, version_buffer.dwMinorVersion, version_buffer.szCSDVersion); +#else printf("%s %s %s\n", art[2], uname_buf.sysname, uname_buf.release); +#endif printf("%s %s\n", art[3], uptime); return 0; }