Merge pull request #1353 from fastfetch-cli/dev

Release: v2.28.0
This commit is contained in:
Carter Li
2024-10-23 09:55:23 +08:00
committed by GitHub
179 changed files with 1967 additions and 990 deletions
+1 -1
View File
@@ -2,4 +2,4 @@
check-filenames =
builtin = clear,rare,usage,informal
skip = */.git,*/cmake-build-*,*/.idea,*/completions,*/presets,*/screenshots,*/tests,*/3rdparty,*/logo/ascii
ignore-words-list = iterm,compiletime,unknwn,pengwin,siduction,master,slave,sur,doas,conexant
ignore-words-list = iterm,compiletime,unknwn,pengwin,siduction,master,slave,sur,doas,conexant,ags
+4 -46
View File
@@ -272,47 +272,6 @@ jobs:
name: fastfetch-musl-amd64
path: ./fastfetch-*.*
musl-aarch64:
name: Musl-aarch64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: setup alpine linux
uses: jirutka/setup-alpine@master
with:
branch: v3.19
arch: aarch64
- name: install dependencies
run: |
cat /etc/alpine-release
uname -a
apk add cmake samurai vulkan-loader-dev libxcb-dev wayland-dev libdrm-dev dconf-dev imagemagick-dev chafa-dev zlib-dev dbus-dev mesa-dev opencl-dev xfconf-dev sqlite-dev networkmanager-dev pulseaudio-dev ddcutil-dev elfutils-dev gcc g++
shell: alpine.sh --root {0}
- name: build
run: |
cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DCMAKE_INSTALL_PREFIX=/usr -DIS_MUSL=ON -GNinja .
cmake --build . --target package --verbose -j4
shell: alpine.sh {0}
- name: run
run: |
./fastfetch --list-features
time ./fastfetch -c presets/ci.jsonc --stat false
time ./fastfetch -c presets/ci.jsonc --format json
time ./flashfetch
ldd fastfetch
ctest
shell: alpine.sh {0}
- name: upload artifacts
uses: actions/upload-artifact@v4
with:
name: fastfetch-musl-aarch64
path: ./fastfetch-*.*
macos-universal:
name: macOS-universal
runs-on: macos-12
@@ -555,9 +514,9 @@ jobs:
- name: setup-msys2
uses: msys2/setup-msys2@v2
with:
msystem: CLANG32
msystem: MINGW32
update: true
install: git p7zip mingw-w64-clang-i686-cmake mingw-w64-clang-i686-clang mingw-w64-clang-i686-vulkan-loader mingw-w64-clang-i686-vulkan-headers mingw-w64-clang-i686-opencl-icd mingw-w64-clang-i686-opencl-headers
install: git p7zip mingw-w64-i686-cmake mingw-w64-i686-clang mingw-w64-i686-vulkan-loader mingw-w64-i686-vulkan-headers mingw-w64-i686-opencl-icd mingw-w64-i686-opencl-headers
- name: print msys version
run: uname -a
@@ -568,7 +527,7 @@ jobs:
languages: c, cpp
- name: configure project
run: env PKG_CONFIG_PATH=/clang32/lib/pkgconfig/:$PKG_CONFIG_PATH cmake -DSET_TWEAK=Off -DBUILD_TESTS=On .
run: env PKG_CONFIG_PATH=/mingw32/lib/pkgconfig/:$PKG_CONFIG_PATH cmake -DSET_TWEAK=Off -DBUILD_TESTS=On .
- name: build project
run: cmake --build . --verbose -j4
@@ -577,7 +536,7 @@ jobs:
uses: github/codeql-action/analyze@v3
- name: copy necessary dlls
run: cp /clang32/bin/{OpenCL,vulkan-1}.dll .
run: cp /mingw32/bin/{OpenCL,vulkan-1}.dll .
- name: download amd_ags
run: curl -LO https://github.com/GPUOpen-LibrariesAndSDKs/AGS_SDK/raw/master/ags_lib/lib/amd_ags_x86.dll
@@ -619,7 +578,6 @@ jobs:
- linux-armv7
- linux-riscv64
- musl-amd64
- musl-aarch64
- macos-universal
- freebsd-amd64
- openbsd-amd64
+23 -2
View File
@@ -1,3 +1,24 @@
# 2.28.0
Features:
* Add new module `Mouse` and `Keyboard` which display connected mice and keyboards
* Support remaining time detection (Battery)
* Report if AC is connected (Battery, Linux)
* Report platform API used for display detection for debugging (Display)
* Report Wine version when running in Wine (Kernel, Windows)
* Add option `waitTime` in modules `CPUUsage`, `DiskIO` and `NetIO`
Bugfixes:
* Fix used memory size detection (Memory, OpenBSD)
* Don't report invalid fragmentation percentage when fails to detect it (Zpool)
* Fix unexpected errors when running fastfetch in parallel (#1346, Windows)
* Don't report obviously invalid temperature values (PhysicalDisk, Linux)
Logos:
* Add eweOS
* Add MidOS
* Update XeroArch
# 2.27.1
Bugfixes:
@@ -8,7 +29,7 @@ Bugfixes:
Changes:
* We now print `"` instead of `″` when displaying diagonal length in inches, so that the character can be correctly displayed in Linux console (Display)
* All detection code of `monitor` module is merged into `display` module. Now `monitor` just prints the same information as `display` with different format. Notably:
* The resolution reported by `monitor` module is now current resolution instead of native / maximum resolution. PPI is calcuated based on current resolution too.
* The resolution reported by `monitor` module is now current resolution instead of native / maximum resolution. PPI is calculated based on current resolution too.
* The refresh rate reported by `monitor` module is the current refresh rate.
Features:
@@ -24,7 +45,7 @@ Bugfixes:
* Remove trailing newline in GPU name for Raspberry pi (#1303, GPU, Linux)
* Fix a possible buffer overflow (GPU, Linux)
* Fix CPU temp incorrectly reported as 0 celsius (#1308, CPU, Linux)
* Corrently report `TPM device is not found` error (#1314, TPM, Windows)
* Correctly report `TPM device is not found` error (#1314, TPM, Windows)
* Fix errors when triggering shell completion with python3 uninstalled (#1310)
* To package managers: as shell completion scripts of fastfetch use python3, it should be added as an optional dependency of fastfetch
* Fix possible crashes when detecting term font of kitty (#1321, TerminalFont, Linux)
+25 -5
View File
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url
project(fastfetch
VERSION 2.27.1
VERSION 2.28.0
LANGUAGES C
DESCRIPTION "Fast neofetch-like system information tool"
HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch"
@@ -379,6 +379,7 @@ set(LIBFASTFETCH_SRC
src/modules/initsystem/initsystem.c
src/modules/gamepad/gamepad.c
src/modules/kernel/kernel.c
src/modules/keyboard/keyboard.c
src/modules/lm/lm.c
src/modules/loadavg/loadavg.c
src/modules/locale/locale.c
@@ -402,6 +403,7 @@ set(LIBFASTFETCH_SRC
src/modules/sound/sound.c
src/modules/swap/swap.c
src/modules/media/media.c
src/modules/mouse/mouse.c
src/modules/terminal/terminal.c
src/modules/terminaltheme/terminaltheme.c
src/modules/terminalfont/terminalfont.c
@@ -478,6 +480,7 @@ if(LINUX)
src/detection/host/host_linux.c
src/detection/icons/icons_linux.c
src/detection/initsystem/initsystem_linux.c
src/detection/keyboard/keyboard_linux.c
src/detection/libc/libc_linux.c
src/detection/lm/lm_linux.c
src/detection/loadavg/loadavg_linux.c
@@ -486,6 +489,7 @@ if(LINUX)
src/detection/gamepad/gamepad_linux.c
src/detection/media/media_linux.c
src/detection/memory/memory_linux.c
src/detection/mouse/mouse_linux.c
src/detection/netio/netio_linux.c
src/detection/opengl/opengl_linux.c
src/detection/os/os_linux.c
@@ -542,6 +546,7 @@ elseif(ANDROID)
src/detection/host/host_android.c
src/detection/icons/icons_nosupport.c
src/detection/initsystem/initsystem_linux.c
src/detection/keyboard/keyboard_nosupport.c
src/detection/libc/libc_android.c
src/detection/lm/lm_nosupport.c
src/detection/loadavg/loadavg_linux.c
@@ -550,6 +555,7 @@ elseif(ANDROID)
src/detection/gamepad/gamepad_nosupport.c
src/detection/media/media_nosupport.c
src/detection/memory/memory_linux.c
src/detection/mouse/mouse_nosupport.c
src/detection/netio/netio_linux.c
src/detection/opengl/opengl_linux.c
src/detection/os/os_android.c
@@ -622,6 +628,7 @@ elseif(FreeBSD)
src/detection/lm/lm_linux.c
src/detection/icons/icons_linux.c
src/detection/initsystem/initsystem_linux.c
src/detection/keyboard/keyboard_bsd.c
src/detection/libc/libc_bsd.c
src/detection/loadavg/loadavg_bsd.c
src/detection/locale/locale_linux.c
@@ -629,6 +636,7 @@ elseif(FreeBSD)
src/detection/gamepad/gamepad_bsd.c
src/detection/media/media_linux.c
src/detection/memory/memory_bsd.c
src/detection/mouse/mouse_bsd.c
src/detection/netio/netio_bsd.c
src/detection/opengl/opengl_linux.c
src/detection/os/os_linux.c
@@ -701,6 +709,7 @@ elseif(OpenBSD)
src/detection/lm/lm_nosupport.c
src/detection/icons/icons_linux.c
src/detection/initsystem/initsystem_linux.c
src/detection/keyboard/keyboard_nosupport.c
src/detection/libc/libc_nosupport.c
src/detection/loadavg/loadavg_bsd.c
src/detection/locale/locale_linux.c
@@ -708,6 +717,7 @@ elseif(OpenBSD)
src/detection/gamepad/gamepad_nosupport.c
src/detection/media/media_linux.c
src/detection/memory/memory_obsd.c
src/detection/mouse/mouse_nosupport.c
src/detection/netio/netio_nosupport.c
src/detection/opengl/opengl_linux.c
src/detection/os/os_obsd.c
@@ -766,6 +776,7 @@ elseif(APPLE)
src/detection/host/host_apple.c
src/detection/icons/icons_nosupport.c
src/detection/initsystem/initsystem_linux.c
src/detection/keyboard/keyboard_apple.c
src/detection/lm/lm_nosupport.c
src/detection/loadavg/loadavg_bsd.c
src/detection/libc/libc_apple.c
@@ -774,6 +785,7 @@ elseif(APPLE)
src/detection/gamepad/gamepad_apple.c
src/detection/media/media_apple.m
src/detection/memory/memory_apple.c
src/detection/mouse/mouse_apple.c
src/detection/netio/netio_bsd.c
src/detection/opengl/opengl_apple.c
src/detection/os/os_apple.m
@@ -832,6 +844,7 @@ elseif(WIN32)
src/detection/host/host_windows.c
src/detection/icons/icons_windows.c
src/detection/initsystem/initsystem_nosupport.c
src/detection/keyboard/keyboard_windows.c
src/detection/libc/libc_windows.cpp
src/detection/lm/lm_nosupport.c
src/detection/loadavg/loadavg_nosupport.c
@@ -840,10 +853,11 @@ elseif(WIN32)
src/detection/gamepad/gamepad_windows.c
src/detection/media/media_windows.c
src/detection/memory/memory_windows.c
src/detection/mouse/mouse_windows.c
src/detection/physicalmemory/physicalmemory_linux.c
src/detection/netio/netio_windows.c
src/detection/opengl/opengl_windows.c
src/detection/os/os_windows.cpp
src/detection/os/os_windows.c
src/detection/packages/packages_windows.c
src/detection/poweradapter/poweradapter_nosupport.c
src/detection/processes/processes_windows.c
@@ -916,6 +930,7 @@ elseif(SunOS)
src/detection/host/host_windows.c
src/detection/icons/icons_linux.c
src/detection/initsystem/initsystem_linux.c
src/detection/keyboard/keyboard_nosupport.c
src/detection/libc/libc_nosupport.c
src/detection/lm/lm_nosupport.c
src/detection/loadavg/loadavg_sunos.c
@@ -924,6 +939,7 @@ elseif(SunOS)
src/detection/gamepad/gamepad_nosupport.c
src/detection/media/media_linux.c
src/detection/memory/memory_sunos.c
src/detection/mouse/mouse_nosupport.c
src/detection/netio/netio_sunos.c
src/detection/opengl/opengl_linux.c
src/detection/os/os_sunos.c
@@ -1026,10 +1042,12 @@ if(FreeBSD AND EXISTS "/usr/local/bin/objdump")
endif()
endif()
if(LINUX OR ANDROID)
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__=1 _FILE_OFFSET_BITS=64)
if(LINUX)
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE _ATFILE_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64) # "$<$<CONFIG:Release>:_FORTIFY_SOURCE=3>"
elseif(ANDROID)
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE _FILE_OFFSET_BITS=64 "$<$<CONFIG:DEBUG>:__BIONIC_FORTIFY>" "$<$<CONFIG:DEBUG>:__BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED>")
elseif(WIN32)
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE WIN32_LEAN_AND_MEAN=1 _WIN32_WINNT=0x0A00)
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE WIN32_LEAN_AND_MEAN=1 _WIN32_WINNT=0x0A00) # "$<$<CONFIG:Release>:_FORTIFY_SOURCE=3>"
elseif(APPLE)
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 _DARWIN_C_SOURCE)
elseif(OpenBSD)
@@ -1298,6 +1316,8 @@ elseif(WIN32)
PRIVATE "hid"
PRIVATE "wtsapi32"
PRIVATE "imagehlp"
PRIVATE "cfgmgr32"
PRIVATE "winbrand"
)
elseif(FreeBSD)
target_link_libraries(libfastfetch
+6
View File
@@ -1,3 +1,9 @@
fastfetch (2.27.1) jammy; urgency=medium
* Update to 2.27.1
-- Carter Li <zhangsongcui@live.cn> Sun, 06 Oct 2024 12:55:18 +0800
fastfetch (2.26.1ubuntu1) jammy; urgency=medium
* Update correct code
+1 -1
View File
@@ -1 +1 @@
fastfetch_2.26.1ubuntu1_source.buildinfo universe/utils optional
fastfetch_2.27.1_source.buildinfo universe/utils optional
+18
View File
@@ -1181,6 +1181,12 @@
"description": "Display CPU usage per CPU logical core, instead of an average result",
"default": false
},
"waitTime": {
"type": "integer",
"description": "Wait time (in ms). CPU usage = (inUseEnd - inUseStart) / waitTime",
"default": 200,
"minimum": 1
},
"key": {
"$ref": "#/$defs/key"
},
@@ -1472,6 +1478,12 @@
"type": "boolean",
"default": false
},
"waitTime": {
"type": "integer",
"description": "Wait time (in ms). Disk I/O = (totalBytesEnd - totalBytesStart) / waitTime",
"default": 200,
"minimum": 1
},
"key": {
"$ref": "#/$defs/key"
},
@@ -1841,6 +1853,12 @@
"type": "boolean",
"default": false
},
"waitTime": {
"type": "integer",
"description": "Wait time (in ms). Disk I/O = (totalBytesEnd - totalBytesStart) / waitTime",
"default": 200,
"minimum": 1
},
"key": {
"$ref": "#/$defs/key"
},
+2 -1
View File
@@ -74,7 +74,8 @@
"showSpeed": true,
"showMtu": true,
"showLoop": true,
"showFlags": true
"showFlags": true,
"showAllIps": true
},
"dns",
"wifi",
+2 -1
View File
@@ -76,7 +76,8 @@
"showSpeed": true,
"showMtu": true,
"showLoop": true,
"showFlags": true
"showFlags": true,
"showAllIps": true
},
"dns",
"wifi",
+16 -12
View File
@@ -5,18 +5,22 @@ set -e
mkdir -p build/
cd build/
if [ -z "${CMAKE_BUILD_TYPE}" ]; then
CMAKE_BUILD_TYPE=Release
fi
cmake "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" ..
cmake ..
if [ -z "$OSTYPE" ] || [ "$OSTYPE" = "linux-gnu" ]; then
cmake_build_args="-j$(nproc)"
elif [ "$OSTYPE" = "darwin" ]; then
cmake_build_args="-j$(sysctl -n hw.ncpu)"
else
cmake_build_args=""
fi
cmake --build . --target fastfetch ${cmake_build_args}
kernel_name="$(uname -s)"
case "${kernel_name}" in
"Linux" | "MINGW"*)
cmake_build_args="-j$(nproc)"
;;
"Darwin" | *"BSD" | "DragonFly")
cmake_build_args="-j$(sysctl -n hw.ncpu)"
;;
*)
cmake_build_args=""
;;
esac
cmake --build . --target fastfetch "${cmake_build_args}"
./fastfetch "$@"
+1 -1
View File
@@ -43,6 +43,6 @@ typedef struct FFformatarg
void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg);
void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t numArgs, const FFformatarg* arguments);
#define FF_PARSE_FORMAT_STRING_CHECKED(buffer, formatstr, numArgs, arguments) do {\
static_assert(sizeof(arguments) / sizeof(*(arguments)) == (numArgs), "Invalid number of format arguments");\
static_assert(sizeof(arguments) / sizeof(*arguments) == (numArgs), "Invalid number of format arguments");\
ffParseFormatString((buffer), (formatstr), (numArgs), (arguments));\
} while (0)
+30 -10
View File
@@ -13,6 +13,8 @@
#include <unistd.h>
#include <dirent.h>
#include <sys/stat.h>
#include <errno.h>
#include <limits.h>
typedef int FFNativeFD;
#define FF_INVALID_FD (-1)
// procfs's file can be changed between read calls such as /proc/meminfo and /proc/uptime.
@@ -66,9 +68,11 @@ static inline ssize_t ffReadFDData(FFNativeFD fd, size_t dataSize, void* data)
}
ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data);
ssize_t ffReadFileDataRelative(FFNativeFD dfd, const char* fileName, size_t dataSize, void* data);
bool ffAppendFDBuffer(FFNativeFD fd, FFstrbuf* buffer);
bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer);
bool ffAppendFileBufferRelative(FFNativeFD dfd, const char* fileName, FFstrbuf* buffer);
static inline bool ffReadFileBuffer(const char* fileName, FFstrbuf* buffer)
{
@@ -76,6 +80,12 @@ static inline bool ffReadFileBuffer(const char* fileName, FFstrbuf* buffer)
return ffAppendFileBuffer(fileName, buffer);
}
static inline bool ffReadFileBufferRelative(FFNativeFD dfd, const char* fileName, FFstrbuf* buffer)
{
ffStrbufClear(buffer);
return ffAppendFileBufferRelative(dfd, fileName, buffer);
}
//Bit flags, combine with |
typedef enum FFPathType
{
@@ -108,17 +118,22 @@ static inline bool ffPathExists(const char* path, FFPathType pathType)
}
else
{
struct stat fileStat;
if(stat(path, &fileStat) != 0)
return false;
size_t len = strlen(path);
assert(len < PATH_MAX);
if (len == 0) return false;
unsigned int mode = fileStat.st_mode & S_IFMT;
if(pathType & FF_PATHTYPE_FILE && mode != S_IFDIR)
return true;
if(pathType & FF_PATHTYPE_DIRECTORY && mode == S_IFDIR)
return true;
int ret;
if (path[len - 1] != '/')
{
char buf[PATH_MAX + 1];
memcpy(buf, path, len);
buf[len] = '/';
buf[len + 1] = 0;
ret = access(buf, F_OK);
}
else
ret = access(path, F_OK);
return pathType == FF_PATHTYPE_DIRECTORY ? ret == 0 : ret == -1 && errno == ENOTDIR;
}
#endif
@@ -211,3 +226,8 @@ static inline bool ffSearchUserConfigFile(const FFlist* configDirs, const char*
return false;
}
#ifdef _WIN32
// Only O_RDONLY is supported
HANDLE openat(HANDLE dfd, const char* fileName, bool directory);
#endif
+19 -1
View File
@@ -37,7 +37,7 @@ static void createSubfolders(const char* fileName)
bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data)
{
int openFlagsModes = O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC;
int openFlagsRights = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
mode_t openFlagsRights = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
int FF_AUTO_CLOSE_FD fd = open(fileName, openFlagsModes, openFlagsRights);
if(fd == -1)
@@ -108,6 +108,15 @@ ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data)
return ffReadFDData(fd, dataSize, data);
}
ssize_t ffReadFileDataRelative(int dfd, const char* fileName, size_t dataSize, void* data)
{
int FF_AUTO_CLOSE_FD fd = openat(dfd, fileName, O_RDONLY | O_CLOEXEC);
if(fd == -1)
return -1;
return ffReadFDData(fd, dataSize, data);
}
bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer)
{
int FF_AUTO_CLOSE_FD fd = open(fileName, O_RDONLY | O_CLOEXEC);
@@ -117,6 +126,15 @@ bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer)
return ffAppendFDBuffer(fd, buffer);
}
bool ffAppendFileBufferRelative(int dfd, const char* fileName, FFstrbuf* buffer)
{
int FF_AUTO_CLOSE_FD fd = openat(dfd, fileName, O_RDONLY | O_CLOEXEC);
if(fd == -1)
return false;
return ffAppendFDBuffer(fd, buffer);
}
bool ffPathExpandEnv(FF_MAYBE_UNUSED const char* in, FF_MAYBE_UNUSED FFstrbuf* out)
{
bool result = false;
+46 -1
View File
@@ -3,6 +3,8 @@
#include "util/stringUtils.h"
#include <windows.h>
#include <ntstatus.h>
#include <winternl.h>
static void createSubfolders(const char* fileName)
{
@@ -38,7 +40,7 @@ bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data)
static inline void readWithLength(HANDLE handle, FFstrbuf* buffer, uint32_t length)
{
ffStrbufEnsureFixedLengthFree(buffer, length);
ffStrbufEnsureFree(buffer, length);
DWORD bytesRead = 0;
while(
length > 0 &&
@@ -100,6 +102,49 @@ bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer)
return ffAppendFDBuffer(handle, buffer);
}
HANDLE openat(HANDLE dfd, const char* fileName, bool directory)
{
NTSTATUS ret;
UNICODE_STRING fileNameW;
ret = RtlAnsiStringToUnicodeString(&fileNameW, &(ANSI_STRING) {
.Length = (USHORT) strlen(fileName),
.Buffer = (PCHAR) fileName
}, TRUE);
if (!NT_SUCCESS(ret)) return INVALID_HANDLE_VALUE;
FF_AUTO_CLOSE_FD HANDLE hFile;
IO_STATUS_BLOCK iosb = {};
ret = NtOpenFile(&hFile, FILE_READ_DATA | SYNCHRONIZE, &(OBJECT_ATTRIBUTES) {
.Length = sizeof(OBJECT_ATTRIBUTES),
.RootDirectory = dfd,
.ObjectName = &fileNameW,
}, &iosb, FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_NONALERT | (directory ? FILE_DIRECTORY_FILE : FILE_NON_DIRECTORY_FILE));
RtlFreeUnicodeString(&fileNameW);
if(!NT_SUCCESS(ret) || iosb.Information != FILE_OPENED)
return INVALID_HANDLE_VALUE;
return hFile;
}
bool ffAppendFileBufferRelative(HANDLE dfd, const char* fileName, FFstrbuf* buffer)
{
HANDLE FF_AUTO_CLOSE_FD fd = openat(dfd, fileName, false);
if(fd == INVALID_HANDLE_VALUE)
return false;
return ffAppendFDBuffer(fd, buffer);
}
ssize_t ffReadFileDataRelative(HANDLE dfd, const char* fileName, size_t dataSize, void* data)
{
HANDLE FF_AUTO_CLOSE_FD fd = openat(dfd, fileName, false);
if(fd == INVALID_HANDLE_VALUE)
return -1;
return ffReadFDData(fd, dataSize, data);
}
bool ffPathExpandEnv(const char* in, FFstrbuf* out)
{
DWORD length = ExpandEnvironmentStringsA(in, NULL, 0);
+2
View File
@@ -73,6 +73,7 @@ static FFModuleBaseInfo* J[] = {
static FFModuleBaseInfo* K[] = {
(void*) &instance.config.modules.kernel,
(void*) &instance.config.modules.keyboard,
NULL,
};
@@ -88,6 +89,7 @@ static FFModuleBaseInfo* M[] = {
(void*) &instance.config.modules.media,
(void*) &instance.config.modules.memory,
(void*) &instance.config.modules.monitor,
(void*) &instance.config.modules.mouse,
NULL,
};
+2 -4
View File
@@ -13,11 +13,9 @@ bool ffNetifGetDefaultRouteImpl(char iface[IF_NAMESIZE + 1], uint32_t* ifIndex)
if (!netRoute) return false;
// skip first line
flockfile(netRoute);
while (getc_unlocked(netRoute) != '\n');
funlockfile(netRoute);
unsigned long long destination; //, gateway, flags, refCount, use, metric, mask, mtu,
FF_UNUSED(fscanf(netRoute, "%*[^\n]\n"));
unsigned long long destination; //, gateway, flags, refCount, use, metric, mask, mtu,
while (fscanf(netRoute, "%" FF_STR(IF_NAMESIZE) "s%llx%*[^\n]", iface, &destination) == 2)
{
if (destination != 0) continue;
+42
View File
@@ -190,6 +190,48 @@ void ffParseGTK(FFstrbuf* buffer, const FFstrbuf* gtk2, const FFstrbuf* gtk3, co
}
}
void ffParseDuration(uint32_t days, uint32_t hours, uint32_t minutes, uint32_t seconds, FFstrbuf* result)
{
if(days == 0 && hours == 0 && minutes == 0)
{
ffStrbufAppendF(result, "%u seconds", seconds);
return;
}
if(days > 0)
{
ffStrbufAppendF(result, "%u day", days);
if(days > 1)
ffStrbufAppendC(result, 's');
if(days >= 100)
ffStrbufAppendS(result, "(!)");
if(hours > 0 || minutes > 0)
ffStrbufAppendS(result, ", ");
}
if(hours > 0)
{
ffStrbufAppendF(result, "%u hour", hours);
if(hours > 1)
ffStrbufAppendC(result, 's');
if(minutes > 0)
ffStrbufAppendS(result, ", ");
}
if(minutes > 0)
{
ffStrbufAppendF(result, "%u min", minutes);
if(minutes > 1)
ffStrbufAppendC(result, 's');
}
}
#ifdef _WIN32
#pragma GCC diagnostic pop
#endif
+1
View File
@@ -27,3 +27,4 @@ int8_t ffVersionCompare(const FFVersion* version1, const FFVersion* version2);
void ffParseSize(uint64_t bytes, FFstrbuf* result);
bool ffParseFrequency(uint32_t mhz, FFstrbuf* result);
void ffParseDuration(uint32_t days, uint32_t hours, uint32_t minutes, uint32_t seconds, FFstrbuf* result);
+2 -2
View File
@@ -14,7 +14,7 @@ typedef enum FFPrintType {
void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType);
void ffPrintFormat(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, uint32_t numArgs, const FFformatarg* arguments);
#define FF_PRINT_FORMAT_CHECKED(moduleName, moduleIndex, moduleArgs, printType, numArgs, arguments) do {\
static_assert(sizeof(arguments) / sizeof(*(arguments)) == (numArgs), "Invalid number of format arguments");\
static_assert(sizeof(arguments) / sizeof(*arguments) == (numArgs), "Invalid number of format arguments");\
ffPrintFormat((moduleName), (moduleIndex), (moduleArgs), (printType), (numArgs), (arguments));\
} while (0)
FF_C_PRINTF(5, 6) void ffPrintError(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, const char* message, ...);
@@ -23,6 +23,6 @@ void ffPrintCharTimes(char c, uint32_t times);
void ffPrintModuleFormatHelp(const char* name, const char* def, uint32_t numArgs, const char* args[]);
#define FF_PRINT_MODULE_FORMAT_HELP_CHECKED(moduleName, def, numArgs, args) do {\
static_assert(sizeof(args) / sizeof(*(args)) == (numArgs), "Invalid number of format arguments");\
static_assert(sizeof(args) / sizeof(*args) == (numArgs), "Invalid number of format arguments");\
ffPrintModuleFormatHelp((moduleName), (def), (numArgs), (args));\
} while (0)
+13 -11
View File
@@ -139,12 +139,13 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
if (exePath)
{
snprintf(filePath, sizeof(filePath), "/proc/%d/exe", (int)pid);
ffStrbufEnsureFixedLengthFree(exePath, PATH_MAX);
ssize_t length = readlink(filePath, exePath->chars, exePath->allocated - 1);
char buf[PATH_MAX];
ssize_t length = readlink(filePath, buf, PATH_MAX - 1);
if (length > 0) // doesn't contain trailing NUL
{
exePath->chars[length] = '\0';
exePath->length = (uint32_t) length;
buf[length] = '\0';
ffStrbufEnsureFixedLengthFree(exePath, (uint32_t)length + 1); // +1 for the NUL
ffStrbufAppendNS(exePath, (uint32_t)length, buf);
}
}
@@ -152,14 +153,14 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
size_t len = 0;
int mibs[] = { CTL_KERN, KERN_PROCARGS2, pid };
if (sysctl(mibs, sizeof(mibs) / sizeof(*mibs), NULL, &len, NULL, 0) == 0)
if (sysctl(mibs, ARRAY_SIZE(mibs), NULL, &len, NULL, 0) == 0)
{// try get arg0
#ifndef MAC_OS_X_VERSION_10_15
//don't know why if don't let len longer, proArgs2 and len will change during the following sysctl() in old MacOS version.
len++;
#endif
FF_AUTO_FREE char* const procArgs2 = malloc(len);
if (sysctl(mibs, sizeof(mibs) / sizeof(*mibs), procArgs2, &len, NULL, 0) == 0)
if (sysctl(mibs, ARRAY_SIZE(mibs), procArgs2, &len, NULL, 0) == 0)
{
// https://gist.github.com/nonowarn/770696#file-getargv-c-L46
uint32_t argc = *(uint32_t*) procArgs2;
@@ -242,7 +243,7 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
#elif defined(__sun)
char filePath[PATH_MAX];
char filePath[128];
snprintf(filePath, sizeof(filePath), "/proc/%d/psinfo", (int) pid);
psinfo_t proc;
if (ffReadFileData(filePath, sizeof(proc), &proc) == sizeof(proc))
@@ -254,12 +255,13 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
if (exePath)
{
snprintf(filePath, sizeof(filePath), "/proc/%d/path/a.out", (int) pid);
ffStrbufEnsureFixedLengthFree(exePath, PATH_MAX);
ssize_t length = readlink(filePath, exePath->chars, exePath->allocated - 1);
char buf[PATH_MAX];
ssize_t length = readlink(filePath, buf, PATH_MAX - 1);
if (length > 0) // doesn't contain trailing NUL
{
exePath->chars[length] = '\0';
exePath->length = (uint32_t) length;
buf[length] = '\0';
ffStrbufEnsureFixedLengthFree(exePath, (uint32_t)length + 1); // +1 for the NUL
ffStrbufAppendNS(exePath, (uint32_t)length, buf);
}
}
+7 -4
View File
@@ -49,8 +49,11 @@ const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool use
{
int timeout = instance.config.general.processingTimeout;
wchar_t pipeName[32];
swprintf(pipeName, ARRAY_SIZE(pipeName), L"\\\\.\\pipe\\FASTFETCH-%u", GetCurrentProcessId());
FF_AUTO_CLOSE_FD HANDLE hChildPipeRead = CreateNamedPipeW(
L"\\\\.\\pipe\\LOCAL\\",
pipeName,
PIPE_ACCESS_INBOUND | FILE_FLAG_FIRST_PIPE_INSTANCE | (timeout < 0 ? 0 : FILE_FLAG_OVERLAPPED),
0,
1,
@@ -60,10 +63,10 @@ const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool use
NULL
);
if (hChildPipeRead == INVALID_HANDLE_VALUE)
return "CreateNamedPipeW(L\"\\\\.\\pipe\\LOCAL\\\") failed";
return "CreateNamedPipeW(L\"\\\\.\\pipe\\FASTFETCH-$(PID)\") failed";
HANDLE hChildPipeWrite = CreateFileW(
L"\\\\.\\pipe\\LOCAL\\",
pipeName,
GENERIC_WRITE,
0,
&(SECURITY_ATTRIBUTES){
@@ -76,7 +79,7 @@ const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool use
NULL
);
if (hChildPipeWrite == INVALID_HANDLE_VALUE)
return "CreateFileW(L\"\\\\.\\pipe\\LOCAL\\\") failed";
return "CreateFileW(L\"\\\\.\\pipe\\FASTFETCH-$(PID)\") failed";
PROCESS_INFORMATION piProcInfo = {0};
+1 -1
View File
@@ -100,7 +100,7 @@ bool ffParsePropFileValues(const char* filename, uint32_t numQueries, FFpropquer
bool valueStorage[32];
bool* unsetValues = valueStorage;
if (numQueries > sizeof(valueStorage) / sizeof(valueStorage[0]))
if (numQueries > ARRAY_SIZE(valueStorage))
unsetValues = malloc(sizeof(bool) * numQueries);
bool allSet = true;
+24
View File
@@ -916,6 +916,14 @@
"type": "str"
}
},
{
"long": "diskio-wait-time",
"desc": "Set the wait time (in ms) when detecting disk usage",
"arg": {
"type": "num",
"default": 1000
}
},
{
"long": "physicaldisk-name-prefix",
"desc": "Show disks with given name prefix only",
@@ -1070,6 +1078,14 @@
"default": false
}
},
{
"long": "cpuusage-wait-time",
"desc": "Set the wait time (in ms) when detecting CPU usage",
"arg": {
"type": "num",
"default": 200
}
},
{
"long": "de-slow-version-detection",
"desc": "Set if DE version should be detected with slow operations",
@@ -1305,6 +1321,14 @@
"default": false
}
},
{
"long": "netio-wait-time",
"desc": "Set the wait time (in ms) when detecting network usage",
"arg": {
"type": "num",
"default": 1000
}
},
{
"long": "publicip-timeout",
"desc": "Time in milliseconds to wait for the public ip server to respond",
+1
View File
@@ -15,6 +15,7 @@ typedef struct FFBatteryResult
double capacity;
double temperature;
uint32_t cycleCount;
int32_t timeRemaining;
} FFBatteryResult;
const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results);
+24 -2
View File
@@ -1,6 +1,6 @@
#include "fastfetch.h"
#include "battery.h"
#include "util/stringUtils.h"
#include "common/processing.h"
#include "common/properties.h"
@@ -36,6 +36,7 @@ static const char* parseTermuxApi(FFBatteryOptions* options, FFlist* results)
FFBatteryResult* battery = ffListAdd(results);
battery->temperature = FF_BATTERY_TEMP_UNSET;
battery->cycleCount = 0;
battery->timeRemaining = -1;
ffStrbufInit(&battery->manufacturer);
ffStrbufInit(&battery->modelName);
ffStrbufInit(&battery->status);
@@ -44,7 +45,27 @@ static const char* parseTermuxApi(FFBatteryOptions* options, FFlist* results)
ffStrbufInit(&battery->manufactureDate);
battery->capacity = yyjson_get_num(yyjson_obj_get(root, "percentage"));
ffStrbufAppendS(&battery->status, yyjson_get_str(yyjson_obj_get(root, "status")));
const char* acStatus = yyjson_get_str(yyjson_obj_get(root, "plugged"));
if (acStatus)
{
if (ffStrEquals(acStatus, "PLUGGED_AC"))
ffStrbufAppendS(&battery->status, "AC Connected, ");
else if (ffStrEquals(acStatus, "PLUGGED_USB"))
ffStrbufAppendS(&battery->status, "USB Connected, ");
else if (ffStrEquals(acStatus, "PLUGGED_WIRELESS"))
ffStrbufAppendS(&battery->status, "Wireless Connected, ");
}
const char* status = yyjson_get_str(yyjson_obj_get(root, "status"));
if (status)
{
if (ffStrEquals(status, "CHARGING"))
ffStrbufAppendS(&battery->status, "Charging");
else if (ffStrEquals(status, "DISCHARGING"))
ffStrbufAppendS(&battery->status, "Discharging");
}
ffStrbufTrimRight(&battery->status, ' ');
ffStrbufTrimRight(&battery->status, ',');
if(options->temp)
battery->temperature = yyjson_get_num(yyjson_obj_get(root, "temperature"));
@@ -74,6 +95,7 @@ static const char* parseDumpsys(FFBatteryOptions* options, FFlist* results)
FFBatteryResult* battery = ffListAdd(results);
battery->temperature = FF_BATTERY_TEMP_UNSET;
battery->cycleCount = 0;
battery->timeRemaining = -1;
ffStrbufInit(&battery->manufacturer);
ffStrbufInit(&battery->modelName);
ffStrbufInit(&battery->status);
+17 -6
View File
@@ -57,13 +57,24 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results)
ffCfDictGetInt(properties, CFSTR(kIOPMPSCycleCountKey), &cycleCount);
battery->cycleCount = cycleCount < 0 ? 0 : (uint32_t) cycleCount;
if (!ffCfDictGetBool(properties, CFSTR(kIOPMPSExternalConnectedKey), &boolValue) && boolValue)
ffStrbufAppendS(&battery->status, "AC connected, ");
else
ffStrbufAppendS(&battery->status, "Discharging, ");
if (!ffCfDictGetBool(properties, CFSTR(kIOPMPSIsChargingKey), &boolValue) && boolValue)
battery->timeRemaining = -1;
if (ffCfDictGetBool(properties, CFSTR(kIOPMPSExternalConnectedKey), &boolValue) == NULL)
{
if (boolValue)
ffStrbufAppendS(&battery->status, "AC connected, ");
else
{
ffStrbufAppendS(&battery->status, "Discharging, ");
ffCfDictGetInt(properties, CFSTR("AvgTimeToEmpty"), &battery->timeRemaining); // in minutes
if (battery->timeRemaining < 0 || battery->timeRemaining >= 0xFFFF)
battery->timeRemaining = -1;
else
battery->timeRemaining *= 60;
}
}
if (ffCfDictGetBool(properties, CFSTR(kIOPMPSIsChargingKey), &boolValue) == NULL && boolValue)
ffStrbufAppendS(&battery->status, "Charging, ");
if (!ffCfDictGetBool(properties, CFSTR(kIOPMPSAtCriticalLevelKey), &boolValue) && boolValue)
if (ffCfDictGetBool(properties, CFSTR(kIOPMPSAtCriticalLevelKey), &boolValue) == NULL && boolValue)
ffStrbufAppendS(&battery->status, "Critical, ");
ffStrbufTrimRight(&battery->status, ' ');
ffStrbufTrimRight(&battery->status, ',');
+4 -1
View File
@@ -41,7 +41,9 @@ const char* ffDetectBattery(FF_MAYBE_UNUSED FFBatteryOptions* options, FFlist* r
ffStrbufInit(&battery->technology);
ffStrbufInit(&battery->serial);
ffStrbufInit(&battery->manufactureDate);
battery->timeRemaining = -1;
if (battio.battinfo.min > 0)
battery->timeRemaining = battio.battinfo.min * 60;
battery->capacity = battio.battinfo.cap;
if(battio.battinfo.state == ACPI_BATT_STAT_INVALID)
{
@@ -74,6 +76,7 @@ const char* ffDetectBattery(FF_MAYBE_UNUSED FFBatteryOptions* options, FFlist* r
ffStrbufAppendS(&battery->manufacturer, battio.bix.oeminfo);
ffStrbufAppendS(&battery->modelName, battio.bix.model);
ffStrbufAppendS(&battery->technology, battio.bix.type);
battery->cycleCount = battio.bix.cycles;
}
}
return NULL;
+76 -71
View File
@@ -3,39 +3,45 @@
#include "util/stringUtils.h"
#include <dirent.h>
#include <unistd.h>
#include <fcntl.h>
// https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-power
static void parseBattery(FFstrbuf* dir, const char* id, FFBatteryOptions* options, FFlist* results)
static bool checkAc(const char* id, FFstrbuf* tmpBuffer)
{
uint32_t dirLength = dir->length;
if (ffStrStartsWith(id, "BAT"))
ffStrbufSetS(tmpBuffer, "/sys/class/power_supply/ADP1/online");
else if (ffStrStartsWith(id, "macsmc-battery"))
ffStrbufSetS(tmpBuffer, "/sys/class/power_supply/macsmc-ac/online");
else
ffStrbufClear(tmpBuffer);
char online = '\0';
return ffReadFileData(tmpBuffer->chars, 1, &online) == 1 && online == '1';
}
static void parseBattery(int dfd, const char* id, FFBatteryOptions* options, FFlist* results)
{
FF_STRBUF_AUTO_DESTROY tmpBuffer = ffStrbufCreate();
//type must exist and be "Battery"
ffStrbufAppendS(dir, "/type");
if (ffReadFileBuffer(dir->chars, &tmpBuffer))
ffStrbufTrimRightSpace(&tmpBuffer);
ffStrbufSubstrBefore(dir, dirLength);
// type must exist and be "Battery"
if (!ffReadFileBufferRelative(dfd, "type", &tmpBuffer))
return;
ffStrbufTrimRightSpace(&tmpBuffer);
if(!ffStrbufIgnCaseEqualS(&tmpBuffer, "Battery"))
return;
//scope may not exist or must not be "Device"
ffStrbufAppendS(dir, "/scope");
if (ffReadFileBuffer(dir->chars, &tmpBuffer))
// scope may not exist or must not be "Device"
if (ffReadFileBufferRelative(dfd, "scope", &tmpBuffer))
ffStrbufTrimRightSpace(&tmpBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if(ffStrbufIgnCaseEqualS(&tmpBuffer, "Device"))
return;
//capacity must exist and be not empty
ffStrbufAppendS(dir, "/capacity");
bool available = ffReadFileBuffer(dir->chars, &tmpBuffer); // This is expensive in my laptop
ffStrbufSubstrBefore(dir, dirLength);
if (!available)
// capacity must exist and be not empty
// This is expensive in my laptop
if (!ffReadFileBufferRelative(dfd, "capacity", &tmpBuffer))
return;
FFBatteryResult* result = ffListAdd(results);
@@ -44,39 +50,63 @@ static void parseBattery(FFstrbuf* dir, const char* id, FFBatteryOptions* option
//At this point, we have a battery. Try to get as much values as possible.
ffStrbufInit(&result->manufacturer);
ffStrbufAppendS(dir, "/manufacturer");
if (ffReadFileBuffer(dir->chars, &result->manufacturer))
if (ffReadFileBufferRelative(dfd, "manufacturer", &result->manufacturer))
ffStrbufTrimRightSpace(&result->manufacturer);
else if (ffStrEquals(id, "macsmc-battery")) // asahi
ffStrbufSetStatic(&result->manufacturer, "Apple Inc.");
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->modelName);
ffStrbufAppendS(dir, "/model_name");
if (ffReadFileBuffer(dir->chars, &result->modelName))
if (ffReadFileBufferRelative(dfd, "model_name", &result->modelName))
ffStrbufTrimRightSpace(&result->modelName);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->technology);
ffStrbufAppendS(dir, "/technology");
if (ffReadFileBuffer(dir->chars, &result->technology))
if (ffReadFileBufferRelative(dfd, "technology", &result->technology))
ffStrbufTrimRightSpace(&result->technology);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->status);
ffStrbufAppendS(dir, "/status");
if (ffReadFileBuffer(dir->chars, &result->status))
if (ffReadFileBufferRelative(dfd, "status", &result->status))
ffStrbufTrimRightSpace(&result->status);
ffStrbufSubstrBefore(dir, dirLength);
// Unknown, Charging, Discharging, Not charging, Full
if (ffStrbufEqualS(&result->status, "Not charging") || ffStrbufEqualS(&result->status, "Full"))
ffStrbufSetStatic(&result->status, "AC Connected");
else if (ffStrbufEqualS(&result->status, "Unknown"))
ffStrbufClear(&result->status);
ffStrbufAppendS(dir, "/capacity_level");
if (ffReadFileBuffer(dir->chars, &tmpBuffer))
result->timeRemaining = -1;
if (ffStrbufEqualS(&result->status, "Discharging"))
{
if (ffReadFileBufferRelative(dfd, "time_to_empty_now", &tmpBuffer))
result->timeRemaining = (int32_t) ffStrbufToSInt(&tmpBuffer, 0);
else
{
if (ffReadFileBufferRelative(dfd, "charge_now", &tmpBuffer))
{
int64_t chargeNow = ffStrbufToSInt(&tmpBuffer, 0);
if (chargeNow > 0)
{
if (ffReadFileBufferRelative(dfd, "current_now", &tmpBuffer))
{
int64_t currentNow = ffStrbufToSInt(&tmpBuffer, INT64_MIN);
if (currentNow < 0) currentNow = -currentNow;
if (currentNow > 0)
result->timeRemaining = (int32_t) ((chargeNow * 3600) / currentNow);
}
}
}
}
if (checkAc(id, &tmpBuffer))
ffStrbufAppendS(&result->status, ", AC Connected");
}
else if (ffStrbufEqualS(&result->status, "Not charging") || ffStrbufEqualS(&result->status, "Full"))
ffStrbufSetStatic(&result->status, "AC Connected");
else if (ffStrbufEqualS(&result->status, "Charging"))
ffStrbufAppendS(&result->status, ", AC Connected");
else if (ffStrbufEqualS(&result->status, "Unknown"))
{
ffStrbufClear(&result->status);
if (checkAc(id, &tmpBuffer))
ffStrbufAppendS(&result->status, "AC Connected");
}
if (ffReadFileBufferRelative(dfd, "capacity_level", &tmpBuffer))
{
ffStrbufTrimRightSpace(&result->manufacturer);
if (ffStrbufEqualS(&tmpBuffer, "Critical"))
@@ -87,50 +117,33 @@ static void parseBattery(FFstrbuf* dir, const char* id, FFBatteryOptions* option
ffStrbufSetStatic(&result->status, "Critical");
}
}
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->serial);
ffStrbufAppendS(dir, "/serial_number");
if (ffReadFileBuffer(dir->chars, &result->serial))
if (ffReadFileBufferRelative(dfd, "serial_number", &result->serial))
ffStrbufTrimRightSpace(&result->serial);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufAppendS(dir, "/cycle_count");
available = ffReadFileBuffer(dir->chars, &tmpBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if (available)
if (ffReadFileBufferRelative(dfd, "cycle_count", &tmpBuffer))
{
int64_t cycleCount = ffStrbufToSInt(&tmpBuffer, 0);
result->cycleCount = cycleCount < 0 || cycleCount > UINT32_MAX ? 0 : (uint32_t) cycleCount;
}
ffStrbufInit(&result->manufactureDate);
ffStrbufAppendS(dir, "/manufacture_year");
available = ffReadFileBuffer(dir->chars, &tmpBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if (available)
if (ffReadFileBufferRelative(dfd, "manufacture_year", &tmpBuffer))
{
int year = (int) ffStrbufToSInt(&tmpBuffer, 0);
if (year > 0)
{
ffStrbufAppendS(dir, "/manufacture_month");
available = ffReadFileBuffer(dir->chars, &tmpBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if (available)
if (ffReadFileBufferRelative(dfd, "manufacture_month", &tmpBuffer))
{
int month = (int) ffStrbufToSInt(&tmpBuffer, 0);
if (month > 0)
{
ffStrbufAppendS(dir, "/manufacture_day");
available = ffReadFileBuffer(dir->chars, &tmpBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if (available)
if (ffReadFileBufferRelative(dfd, "manufacture_day", &tmpBuffer))
{
int day = (int) ffStrbufToSInt(&tmpBuffer, 0);
if (day > 0)
{
ffStrbufSetF(&result->manufactureDate, "%.4d-%.2d-%.2d", year, month, day);
}
}
}
}
@@ -140,33 +153,25 @@ static void parseBattery(FFstrbuf* dir, const char* id, FFBatteryOptions* option
result->temperature = FF_BATTERY_TEMP_UNSET;
if (options->temp)
{
ffStrbufAppendS(dir, "/temp");
if (ffReadFileBuffer(dir->chars, &tmpBuffer))
if (ffReadFileBufferRelative(dfd, "temp", &tmpBuffer))
result->temperature = ffStrbufToDouble(&tmpBuffer) / 10;
ffStrbufSubstrBefore(dir, dirLength);
}
}
const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results)
{
FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateA(64);
ffStrbufAppendS(&baseDir, "/sys/class/power_supply/");
uint32_t baseDirLength = baseDir.length;
FF_AUTO_CLOSE_DIR DIR* dirp = opendir(baseDir.chars);
FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/power_supply/");
if(dirp == NULL)
return "opendir(\"/sys/class/power_supply/\") == NULL";
struct dirent* entry;
while((entry = readdir(dirp)) != NULL)
{
if(ffStrEquals(entry->d_name, ".") || ffStrEquals(entry->d_name, ".."))
if(entry->d_name[0] == '.')
continue;
ffStrbufAppendS(&baseDir, entry->d_name);
parseBattery(&baseDir, entry->d_name, options, results);
ffStrbufSubstrBefore(&baseDir, baseDirLength);
FF_AUTO_CLOSE_FD int dfd = openat(dirfd(dirp), entry->d_name, O_RDONLY | O_CLOEXEC | O_PATH | O_DIRECTORY);
if (dfd > 0) parseBattery(dfd, entry->d_name, options, results);
}
return NULL;
+9
View File
@@ -121,6 +121,13 @@ static const char* detectWithSetupApi(FFBatteryOptions* options, FFlist* results
battery->temperature = temp / 10.0 - 273.15;
}
{
bqi.InformationLevel = BatteryEstimatedTime;
ULONG time;
if(DeviceIoControl(hBattery, IOCTL_BATTERY_QUERY_INFORMATION, &bqi, sizeof(bqi), &time, sizeof(time), &dwOut, NULL))
battery->timeRemaining = time == BATTERY_UNKNOWN_TIME ? -1 : (int32_t) time;
}
{
BATTERY_STATUS bs;
BATTERY_WAIT_STATUS bws = { .BatteryTag = bqi.BatteryTag };
@@ -241,6 +248,7 @@ static const char* detectWithNtApi(FF_MAYBE_UNUSED FFBatteryOptions* options, FF
ffStrbufInit(&battery->serial);
battery->temperature = FF_BATTERY_TEMP_UNSET;
battery->cycleCount = 0;
battery->timeRemaining = info.EstimatedTime == BATTERY_UNKNOWN_TIME ? -1 : (int32_t) info.EstimatedTime;
battery->capacity = info.RemainingCapacity * 100.0 / info.MaxCapacity;
if(info.AcOnLine)
@@ -252,6 +260,7 @@ static const char* detectWithNtApi(FF_MAYBE_UNUSED FFBatteryOptions* options, FF
else if(info.Discharging)
ffStrbufAppendS(&battery->status, "Discharging");
detectBySmbios(battery);
return NULL;
+1 -1
View File
@@ -25,7 +25,7 @@ const char* ffDetectBios(FFBiosResult* result)
{
ffStrbufSetStatic(&result->type,
ffPathExists("/dev/efi" /*efidev*/, FF_PATHTYPE_FILE) ||
ffPathExists("/boot/efi/efi" /*efi partition*/, FF_PATHTYPE_DIRECTORY)
ffPathExists("/boot/efi/efi/" /*efi partition*/, FF_PATHTYPE_DIRECTORY)
? "UEFI" : "BIOS");
}
}
+1 -1
View File
@@ -10,7 +10,7 @@ const char *ffDetectBios(FFBiosResult *bios)
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/bios_release", "/sys/class/dmi/id/bios_release", &bios->release);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/bios_vendor", "/sys/class/dmi/id/bios_vendor", &bios->vendor);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/bios_version", "/sys/class/dmi/id/bios_version", &bios->version);
if (ffPathExists("/sys/firmware/efi", FF_PATHTYPE_DIRECTORY) || ffPathExists("/sys/firmware/acpi/tables/UEFI", FF_PATHTYPE_FILE))
if (ffPathExists("/sys/firmware/efi/", FF_PATHTYPE_DIRECTORY) || ffPathExists("/sys/firmware/acpi/tables/UEFI", FF_PATHTYPE_FILE))
ffStrbufSetStatic(&bios->type, "UEFI");
else
ffStrbufSetStatic(&bios->type, "BIOS");
+1 -1
View File
@@ -1,6 +1,6 @@
#include "bios.h"
const char* ffDetectBios(FFBiosResult* bios)
const char* ffDetectBios(FF_MAYBE_UNUSED FFBiosResult* bios)
{
return "Not supported on this platform";
}
@@ -202,6 +202,7 @@ const char* ffDetectBluetoothRadio(FFlist* devices /* FFBluetoothRadioResult */)
#ifdef FF_HAVE_DBUS
return detectBluetooth(devices);
#else
FF_UNUSED(devices)
return "Fastfetch was compiled without DBus support";
#endif
}
+2 -2
View File
@@ -38,9 +38,9 @@ const char* ffDetectBootmgr(FFBootmgrResult* result)
uint8_t buffer[2048];
wchar_t key[16];
swprintf(key, sizeof(key) / sizeof(*key), L"Boot%04X", value);
swprintf(key, ARRAY_SIZE(key), L"Boot%04X", value);
uint32_t size = GetFirmwareEnvironmentVariableW(key, L"{" FF_EFI_GLOBAL_GUID L"}", buffer, sizeof(buffer));
if (size < sizeof(FFEfiLoadOption) || size == sizeof(buffer))
if (size < sizeof(FFEfiLoadOption) || size == ARRAY_SIZE(buffer))
return "GetFirmwareEnvironmentVariableW(Boot####) failed";
ffEfiFillLoadOption((FFEfiLoadOption *)buffer, result);
+5 -5
View File
@@ -92,13 +92,13 @@ static const char* detectWithDdcci(FF_MAYBE_UNUSED const FFDisplayServerResult*
for (uint32_t i = 0; i < 2; ++i)
{
IOAVServiceWriteI2C(service, 0x37, 0x51, i2cIn, sizeof(i2cIn));
IOAVServiceWriteI2C(service, 0x37, 0x51, i2cIn, ARRAY_SIZE(i2cIn));
usleep(options->ddcciSleep * 1000);
}
}
uint8_t i2cOut[12] = {};
if (IOAVServiceReadI2C(service, 0x37, 0x51, i2cOut, sizeof(i2cOut)) == KERN_SUCCESS)
if (IOAVServiceReadI2C(service, 0x37, 0x51, i2cOut, ARRAY_SIZE(i2cOut)) == KERN_SUCCESS)
{
if (i2cOut[2] != 0x02 || i2cOut[3] != 0x00)
continue;
@@ -113,7 +113,7 @@ static const char* detectWithDdcci(FF_MAYBE_UNUSED const FFDisplayServerResult*
ffStrbufInit(&brightness->name);
uint8_t edid[128] = {};
if (IOAVServiceReadI2C(service, 0x50, 0x00, edid, sizeof(edid)) == KERN_SUCCESS)
if (IOAVServiceReadI2C(service, 0x50, 0x00, edid, ARRAY_SIZE(edid)) == KERN_SUCCESS)
ffEdidGetName(edid, &brightness->name);
}
}
@@ -155,12 +155,12 @@ static const char* detectWithDdcci(const FFDisplayServerResult* displayServer, F
.sendAddress = 0x6e,
.sendTransactionType = kIOI2CSimpleTransactionType,
.sendBuffer = (vm_address_t) i2cIn,
.sendBytes = sizeof(i2cIn) / sizeof(i2cIn[0]),
.sendBytes = ARRAY_SIZE(i2cIn),
.minReplyDelay = options->ddcciSleep,
.replyAddress = 0x6F,
.replySubAddress = 0x51,
.replyTransactionType = kIOI2CDDCciReplyTransactionType,
.replyBytes = sizeof(i2cOut) / sizeof(i2cOut[0]),
.replyBytes = ARRAY_SIZE(i2cOut),
.replyBuffer = (vm_address_t) i2cOut,
};
IOReturn ret = IOI2CSendRequest(connect, kNilOptions, &request);
+1 -1
View File
@@ -16,7 +16,7 @@ const char* ffDetectBrightness(FF_MAYBE_UNUSED FFBrightnessOptions* options, FFl
for (char i = '0'; i <= '9'; ++i)
{
path[sizeof(path) - 2] = i;
path[ARRAY_SIZE(path) - 2] = i;
FF_AUTO_CLOSE_FD int blfd = open(path, O_RDONLY | O_CLOEXEC);
if (blfd < 0)
+2 -2
View File
@@ -25,7 +25,7 @@ static const char* detectWithBacklight(FFlist* result)
struct dirent* entry;
while((entry = readdir(dirp)) != NULL)
{
if(ffStrEquals(entry->d_name, ".") || ffStrEquals(entry->d_name, ".."))
if(entry->d_name[0] == '.')
continue;
ffStrbufAppendS(&backlightDir, entry->d_name);
@@ -48,7 +48,7 @@ static const char* detectWithBacklight(FFlist* result)
// if we managed to get edid, use it
ffStrbufAppendS(&brightness->name, "/edid");
uint8_t edidData[128];
if(ffReadFileData(brightness->name.chars, sizeof(edidData), edidData) == sizeof(edidData))
if(ffReadFileData(brightness->name.chars, ARRAY_SIZE(edidData), edidData) == ARRAY_SIZE(edidData))
{
ffStrbufClear(&brightness->name);
ffEdidGetName(edidData, &brightness->name);
+41 -67
View File
@@ -1,16 +1,18 @@
#include "btrfs.h"
#include "common/io/io.h"
#include <fcntl.h>
enum { uuidLen = (uint32_t) __builtin_strlen("00000000-0000-0000-0000-000000000000") };
static const char* enumerateDevices(FFBtrfsResult* item, FFstrbuf* path, FFstrbuf* buffer)
static const char* enumerateDevices(FFBtrfsResult* item, int dfd, FFstrbuf* buffer)
{
ffStrbufAppendS(path, "devices/");
FF_AUTO_CLOSE_DIR DIR* dirp = opendir(path->chars);
int subfd = openat(dfd, "devices", O_RDONLY | O_CLOEXEC | O_DIRECTORY);
if (subfd < 0) return "openat(\"/sys/fs/btrfs/UUID/devices\") == -1";
FF_AUTO_CLOSE_DIR DIR* dirp = fdopendir(subfd);
if(dirp == NULL)
return "opendir(\"/sys/fs/btrfs/UUID/devices\") == NULL";
const uint32_t devicesPathLen = path->length;
return "fdopendir(\"/sys/fs/btrfs/UUID/devices\") == NULL";
struct dirent* entry;
while ((entry = readdir(dirp)) != NULL)
@@ -21,25 +23,25 @@ static const char* enumerateDevices(FFBtrfsResult* item, FFstrbuf* path, FFstrbu
if (item->devices.length)
ffStrbufAppendC(&item->devices, ',');
ffStrbufAppendS(&item->devices, entry->d_name);
ffStrbufAppendS(path, entry->d_name);
ffStrbufAppendS(path, "/size");
if (ffReadFileBuffer(path->chars, buffer))
char path[ARRAY_SIZE(entry->d_name) + ARRAY_SIZE("/size") + 1];
snprintf(path, ARRAY_SIZE(path), "%s/size", entry->d_name);
if (ffReadFileBufferRelative(subfd, path, buffer))
item->totalSize += ffStrbufToUInt(buffer, 0) * 512;
ffStrbufSubstrBefore(path, devicesPathLen);
}
return NULL;
}
static const char* enumerateFeatures(FFBtrfsResult* item, FFstrbuf* path)
static const char* enumerateFeatures(FFBtrfsResult* item, int dfd)
{
ffStrbufAppendS(path, "features/");
FF_AUTO_CLOSE_DIR DIR* dirp = opendir(path->chars);
int subfd = openat(dfd, "features", O_RDONLY | O_CLOEXEC | O_DIRECTORY);
if (subfd < 0) return "openat(\"/sys/fs/btrfs/UUID/features\") == -1";
FF_AUTO_CLOSE_DIR DIR* dirp = fdopendir(subfd);
if(dirp == NULL)
return "opendir(\"/sys/fs/btrfs/UUID/features\") == NULL";
const uint32_t featuresPathLen = path->length;
return "fdopendir(\"/sys/fs/btrfs/UUID/features\") == NULL";
struct dirent* entry;
while ((entry = readdir(dirp)) != NULL)
@@ -49,45 +51,33 @@ static const char* enumerateFeatures(FFBtrfsResult* item, FFstrbuf* path)
if (item->features.length)
ffStrbufAppendC(&item->features, ',');
ffStrbufAppendS(&item->features, entry->d_name);
ffStrbufSubstrBefore(path, featuresPathLen);
}
return NULL;
}
static const char* detectAllocation(FFBtrfsResult* item, FFstrbuf* path, FFstrbuf* buffer)
static const char* detectAllocation(FFBtrfsResult* item, int dfd, FFstrbuf* buffer)
{
ffStrbufAppendS(path, "allocation/");
const uint32_t AllocationPathLen = path->length;
FF_AUTO_CLOSE_FD int subfd = openat(dfd, "allocation", O_RDONLY | O_CLOEXEC | O_PATH | O_DIRECTORY);
if (subfd < 0) return "openat(\"/sys/fs/btrfs/UUID/allocation\") == -1";
ffStrbufAppendS(path, "global_rsv_size");
if (ffReadFileBuffer(path->chars, buffer))
if (ffReadFileBufferRelative(subfd, "global_rsv_size", buffer))
item->globalReservationTotal = ffStrbufToUInt(buffer, 0);
else
return "ffReadFileBuffer(\"/sys/fs/btrfs/UUID/allocation/global_rsv_size\") == NULL";
ffStrbufSubstrBefore(path, AllocationPathLen);
ffStrbufAppendS(path, "global_rsv_reserved");
if (ffReadFileBuffer(path->chars, buffer))
if (ffReadFileBufferRelative(subfd, "global_rsv_reserved", buffer))
item->globalReservationUsed = ffStrbufToUInt(buffer, 0);
ffStrbufSubstrBefore(path, AllocationPathLen);
item->globalReservationUsed = item->globalReservationTotal - item->globalReservationUsed;
#define FF_BTRFS_DETECT_TYPE(index, _type) \
ffStrbufAppendS(path, #_type "/total_bytes"); \
if (ffReadFileBuffer(path->chars, buffer)) \
if (ffReadFileBufferRelative(subfd, #_type "/total_bytes", buffer)) \
item->allocation[index].total = ffStrbufToUInt(buffer, 0); \
ffStrbufSubstrBefore(path, AllocationPathLen); \
\
ffStrbufAppendS(path, #_type "/bytes_used"); \
if (ffReadFileBuffer(path->chars, buffer)) \
if (ffReadFileBufferRelative(subfd, #_type "/bytes_used", buffer)) \
item->allocation[index].used = ffStrbufToUInt(buffer, 0); \
ffStrbufSubstrBefore(path, AllocationPathLen); \
\
ffStrbufAppendS(path, #_type "/dup"); \
item->allocation[index].dup = ffPathExists(path->chars, FF_PATHTYPE_DIRECTORY); \
ffStrbufSubstrBefore(path, AllocationPathLen); \
item->allocation[index].dup = faccessat(subfd, #_type "/dup/", F_OK, 0) == 0; \
\
item->allocation[index].type = #_type;
@@ -102,10 +92,7 @@ static const char* detectAllocation(FFBtrfsResult* item, FFstrbuf* path, FFstrbu
const char* ffDetectBtrfs(FFlist* result)
{
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateS("/sys/fs/btrfs/");
const uint32_t basePathLen = path.length;
FF_AUTO_CLOSE_DIR DIR* dirp = opendir(path.chars);
FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/fs/btrfs/");
if(dirp == NULL)
return "opendir(\"/sys/fs/btrfs\") == NULL";
@@ -120,46 +107,33 @@ const char* ffDetectBtrfs(FFlist* result)
continue;
FFBtrfsResult* item = ffListAdd(result);
(*item) = (FFBtrfsResult){};
ffStrbufInitNS(&item->uuid, uuidLen, entry->d_name);
ffStrbufInit(&item->name);
ffStrbufInit(&item->devices);
ffStrbufInit(&item->features);
(*item) = (FFBtrfsResult){
.uuid = ffStrbufCreateNS(uuidLen, entry->d_name),
.name = ffStrbufCreate(),
.devices = ffStrbufCreate(),
.features = ffStrbufCreate(),
};
ffStrbufAppendNS(&path, uuidLen, entry->d_name);
ffStrbufAppendC(&path, '/');
const uint32_t itemPathLen = path.length;
FF_AUTO_CLOSE_FD int dfd = openat(dirfd(dirp), entry->d_name, O_RDONLY | O_CLOEXEC | O_PATH | O_DIRECTORY);
if (dfd < 0) continue;
ffStrbufAppendS(&path, "label");
if (ffAppendFileBuffer(path.chars, &item->name))
if (ffAppendFileBufferRelative(dfd, "label", &item->name))
ffStrbufTrimRightSpace(&item->name);
ffStrbufSubstrBefore(&path, itemPathLen);
enumerateDevices(item, &path, &buffer);
ffStrbufSubstrBefore(&path, itemPathLen);
enumerateDevices(item, dfd, &buffer);
enumerateFeatures(item, &path);
ffStrbufSubstrBefore(&path, itemPathLen);
enumerateFeatures(item, dfd);
ffStrbufAppendS(&path, "generation");
if (ffReadFileBuffer(path.chars, &buffer))
if (ffReadFileBufferRelative(dfd, "generation", &buffer))
item->generation = (uint32_t) ffStrbufToUInt(&buffer, 0);
ffStrbufSubstrBefore(&path, itemPathLen);
ffStrbufAppendS(&path, "nodesize");
if (ffReadFileBuffer(path.chars, &buffer))
if (ffReadFileBufferRelative(dfd, "nodesize", &buffer))
item->nodeSize = (uint32_t) ffStrbufToUInt(&buffer, 0);
ffStrbufSubstrBefore(&path, itemPathLen);
ffStrbufAppendS(&path, "sectorsize");
if (ffReadFileBuffer(path.chars, &buffer))
if (ffReadFileBufferRelative(dfd, "sectorsize", &buffer))
item->sectorSize = (uint32_t) ffStrbufToUInt(&buffer, 0);
ffStrbufSubstrBefore(&path, itemPathLen);
detectAllocation(item, &path, &buffer);
// finally
ffStrbufSubstrBefore(&path, basePathLen);
detectAllocation(item, dfd, &buffer);
}
return NULL;
+1 -1
View File
@@ -16,7 +16,7 @@ const char* ffDetectCamera(FFlist* result)
for (uint32_t i = 0; i <= 9; ++i)
{
path[sizeof(path) - 2] = (char) (i + '0');
path[ARRAY_SIZE(path) - 2] = (char) (i + '0');
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY);
if (fd < 0)
break;
+2 -2
View File
@@ -52,7 +52,7 @@ const char* ffDetectCamera(FF_MAYBE_UNUSED FFlist* result)
wchar_t buffer[256];
uint32_t length = 0;
if (FAILED(device->GetString(MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, buffer, sizeof(buffer), &length)) || length == 0)
if (FAILED(device->GetString(MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, buffer, ARRAY_SIZE(buffer), &length)) || length == 0)
continue;
FFCameraResult* camera = (FFCameraResult*) ffListAdd(result);
@@ -63,7 +63,7 @@ const char* ffDetectCamera(FF_MAYBE_UNUSED FFlist* result)
camera->width = 0;
camera->height = 0;
if (SUCCEEDED(device->GetString(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, buffer, sizeof(buffer), &length)) && length > 0)
if (SUCCEEDED(device->GetString(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, buffer, ARRAY_SIZE(buffer), &length)) && length > 0)
ffStrbufSetNWS(&camera->id, length, buffer);
IMFMediaSource* FF_AUTO_RELEASE_COM_OBJECT source = nullptr;
+1 -1
View File
@@ -13,7 +13,7 @@ const char* ffDetectCPU(const FFCPUOptions* options, FFCPUResult* cpu)
" 2-Core", " 4-Core", " 6-Core", " 8-Core", " 10-Core", " 12-Core", " 14-Core", " 16-Core",
" with Radeon Graphics"
};
ffStrbufRemoveStrings(&cpu->name, sizeof(removeStrings) / sizeof(removeStrings[0]), removeStrings);
ffStrbufRemoveStrings(&cpu->name, ARRAY_SIZE(removeStrings), removeStrings);
ffStrbufSubstrBeforeFirstC(&cpu->name, '@'); //Cut the speed output in the name as we append our own
ffStrbufTrimRight(&cpu->name, ' '); //If we removed the @ in previous step there was most likely a space before it
return NULL;
+2 -2
View File
@@ -85,8 +85,8 @@ static const char* detectCoreCount(FFCPUResult* cpu)
if (nPerfLevels <= 0) return "sysctl(hw.nperflevels) failed";
char sysctlKey[] = "hw.perflevelN.logicalcpu";
if (nPerfLevels > sizeof(cpu->coreTypes) / sizeof(cpu->coreTypes[0]))
nPerfLevels = sizeof(cpu->coreTypes) / sizeof(cpu->coreTypes[0]);
if (nPerfLevels > ARRAY_SIZE(cpu->coreTypes))
nPerfLevels = ARRAY_SIZE(cpu->coreTypes);
for (uint32_t i = 0; i < nPerfLevels; ++i)
{
sysctlKey[strlen("hw.perflevel")] = (char) ('0' + i);
+1 -1
View File
@@ -389,7 +389,7 @@ FF_MAYBE_UNUSED static void detectArmSoc(FFCPUResult* cpu)
// device-vendor,device-model\0soc-vendor,soc-model\0
char content[256];
ssize_t length = ffReadFileData("/proc/device-tree/compatible", sizeof(content), content);
ssize_t length = ffReadFileData("/proc/device-tree/compatible", ARRAY_SIZE(content), content);
if (length <= 2) return;
// get the second NUL terminated string if it exists
+1 -1
View File
@@ -1,6 +1,6 @@
#include "cpu.h"
const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
const char* ffDetectCPUImpl(FF_MAYBE_UNUSED const FFCPUOptions* options, FF_MAYBE_UNUSED FFCPUResult* cpu)
{
return "Not supported on this platform";
}
+10 -9
View File
@@ -1,5 +1,6 @@
#include "cpucache.h"
#include "common/sysctl.h"
#include "util/stringUtils.h"
const char* ffDetectCPUCache(FFCPUCacheResult* result)
{
@@ -10,44 +11,44 @@ const char* ffDetectCPUCache(FFCPUCacheResult* result)
// macOS provides the global system cache line size
uint32_t lineSize = (uint32_t) ffSysctlGetInt("hw.cachelinesize", 0);
char sysctlKey[256] = "hw.perflevelN.";
char sysctlKey[128] = "hw.perflevelN.";
char* pNum = sysctlKey + strlen("hw.perflevel");
char* pSubkey = sysctlKey + strlen("hw.perflevelN.");
const size_t lenLeft = sizeof(sysctlKey) - strlen("hw.perflevelN.");
const size_t lenLeft = ARRAY_SIZE(sysctlKey) - strlen("hw.perflevelN.");
for (uint32_t i = 0; i < nPerfLevels; ++i)
{
*pNum = (char) ('0' + i);
strncpy(pSubkey, "physicalcpu", lenLeft);
ffStrCopyN(pSubkey, "physicalcpu", lenLeft);
uint32_t ncpu = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
if (ncpu <= 0) continue;
strncpy(pSubkey, "l1icachesize", lenLeft);
ffStrCopyN(pSubkey, "l1icachesize", lenLeft);
uint32_t size = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
if (size)
ffCPUCacheAddItem(result, 1, size, lineSize, FF_CPU_CACHE_TYPE_INSTRUCTION)->num = ncpu;
strncpy(pSubkey, "l1dcachesize", lenLeft);
ffStrCopyN(pSubkey, "l1dcachesize", lenLeft);
size = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
if (size)
ffCPUCacheAddItem(result, 1, size, lineSize, FF_CPU_CACHE_TYPE_DATA)->num = ncpu;
strncpy(pSubkey, "l2cachesize", lenLeft);
ffStrCopyN(pSubkey, "l2cachesize", lenLeft);
size = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
if (size)
{
strncpy(pSubkey, "cpusperl2", lenLeft);
ffStrCopyN(pSubkey, "cpusperl2", lenLeft);
uint32_t cpuSper = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
if (cpuSper)
ffCPUCacheAddItem(result, 2, size, lineSize, FF_CPU_CACHE_TYPE_UNIFIED)->num = ncpu / cpuSper;
}
strncpy(pSubkey, "l3cachesize", lenLeft);
ffStrCopyN(pSubkey, "l3cachesize", lenLeft);
size = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
if (size)
{
strncpy(pSubkey, "cpusperl3", lenLeft);
ffStrCopyN(pSubkey, "cpusperl3", lenLeft);
uint32_t cpuSper = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
if (cpuSper)
ffCPUCacheAddItem(result, 3, size, lineSize, FF_CPU_CACHE_TYPE_UNIFIED)->num = ncpu / cpuSper;
+3 -3
View File
@@ -13,7 +13,7 @@ void ffPrepareCPUUsage(void)
ffGetCpuUsageInfo(&cpuTimes1);
}
const char* ffGetCpuUsageResult(FFlist* result)
const char* ffGetCpuUsageResult(FFCPUUsageOptions* options, FFlist* result)
{
const char* error = NULL;
if(cpuTimes1.elementSize == 0)
@@ -21,7 +21,7 @@ const char* ffGetCpuUsageResult(FFlist* result)
ffListInit(&cpuTimes1, sizeof(FFCpuUsageInfo));
error = ffGetCpuUsageInfo(&cpuTimes1);
if(error) return error;
ffTimeSleep(200);
ffTimeSleep(options->waitTime);
}
if(cpuTimes1.length == 0) return "No CPU cores found";
@@ -43,7 +43,7 @@ retry:
if (++retryCount <= 3)
{
ffListClear(&cpuTimes2);
ffTimeSleep(200);
ffTimeSleep(options->waitTime);
goto retry;
}
}
+1 -1
View File
@@ -8,4 +8,4 @@ typedef struct FFCpuUsageInfo {
} FFCpuUsageInfo;
const char* ffGetCpuUsageInfo(FFlist* cpuTimes);
const char* ffGetCpuUsageResult(FFlist* result); // list of double
const char* ffGetCpuUsageResult(FFCPUUsageOptions* options, FFlist* result); // list of double
+2 -2
View File
@@ -8,13 +8,13 @@
const char* ffGetCpuUsageInfo(FFlist* cpuTimes)
{
char buf[PROC_FILE_BUFFSIZ];
ssize_t nRead = ffReadFileData("/proc/stat", sizeof(buf) - 1, buf);
ssize_t nRead = ffReadFileData("/proc/stat", ARRAY_SIZE(buf) - 1, buf);
if(nRead < 0)
{
#ifdef __ANDROID__
return "Accessing \"/proc/stat\" is restricted on Android O+";
#else
return "ffReadFileData(\"/proc/stat\", sizeof(buf) - 1, buf) failed";
return "ffReadFileData(\"/proc/stat\", ARRAY_SIZE(buf) - 1, buf) failed";
#endif
}
buf[nRead] = '\0';
+1 -1
View File
@@ -1,7 +1,7 @@
#include "fastfetch.h"
#include "detection/cpuusage/cpuusage.h"
const char* ffGetCpuUsageInfo(FFlist* cpuTimes)
const char* ffGetCpuUsageInfo(FF_MAYBE_UNUSED FFlist* cpuTimes)
{
return "Not support on this platform";
}
+12 -8
View File
@@ -149,7 +149,7 @@ static void detectName(FFDisk* disk)
#ifdef __ANDROID__
static void detectType(FF_MAYBE_UNUSED const FFlist* disks, FFDisk* currentDisk)
static void detectType(FF_MAYBE_UNUSED const FFlist* disks, FFDisk* currentDisk, FF_MAYBE_UNUSED struct mntent* device)
{
if(ffStrbufEqualS(&currentDisk->mountpoint, "/") || ffStrbufEqualS(&currentDisk->mountpoint, "/storage/emulated"))
currentDisk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT;
@@ -204,7 +204,7 @@ static bool isRemovable(FFDisk* currentDisk)
return false;
char sysBlockPartition[64];
snprintf(sysBlockPartition, sizeof(sysBlockPartition), "/sys/class/block/%s", currentDisk->mountFrom.chars + strlen("/dev/"));
snprintf(sysBlockPartition, ARRAY_SIZE(sysBlockPartition), "/sys/class/block/%s", currentDisk->mountFrom.chars + strlen("/dev/"));
char sysBlockVolume[PATH_MAX]; // /sys/devices/pci0000:00/0000:00:14.0/usb4/4-3/4-3:1.0/host0/target0:0:0/0:0:0:0/block/sda/sda1
if (realpath(sysBlockPartition, sysBlockVolume) == NULL)
@@ -215,7 +215,7 @@ static bool isRemovable(FFDisk* currentDisk)
return ffReadFileData(sysBlockVolume, 1, &removableChar) > 0 && removableChar == '1';
}
static void detectType(const FFlist* disks, FFDisk* currentDisk)
static void detectType(const FFlist* disks, FFDisk* currentDisk, struct mntent* device)
{
if(ffStrbufStartsWithS(&currentDisk->mountpoint, "/boot") || ffStrbufStartsWithS(&currentDisk->mountpoint, "/efi"))
currentDisk->type = FF_DISK_VOLUME_TYPE_HIDDEN_BIT;
@@ -225,6 +225,8 @@ static void detectType(const FFlist* disks, FFDisk* currentDisk)
currentDisk->type = FF_DISK_VOLUME_TYPE_EXTERNAL_BIT;
else
currentDisk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT;
if (hasmntopt(device, MNTOPT_RO))
currentDisk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT;
}
#endif
@@ -233,7 +235,7 @@ static void detectStats(FFDisk* disk)
{
struct statvfs fs;
if(statvfs(disk->mountpoint.chars, &fs) != 0)
memset(&fs, 0, sizeof(struct statvfs)); //Set all values to 0, so our values get initialized to 0 too
memset(&fs, 0, sizeof(fs)); //Set all values to 0, so our values get initialized to 0 too
disk->bytesTotal = fs.f_blocks * fs.f_frsize;
disk->bytesFree = fs.f_bfree * fs.f_frsize;
@@ -251,15 +253,17 @@ static void detectStats(FFDisk* disk)
disk->filesTotal = disk->filesUsed = 0;
}
if(fs.f_flag & ST_RDONLY)
disk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT;
disk->createTime = 0;
#ifdef FF_HAVE_STATX
struct statx stx;
if (statx(0, disk->mountpoint.chars, 0, STATX_BTIME, &stx) == 0 && (stx.stx_mask & STATX_BTIME))
disk->createTime = (uint64_t)((stx.stx_btime.tv_sec * 1000) + (stx.stx_btime.tv_nsec / 1000000));
#endif
#ifdef __ANDROID__ // hasmntopt requires a higher Android API level
if(fs.f_flag & ST_RDONLY)
disk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT;
#endif
}
const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
@@ -298,7 +302,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
detectName(disk); // Also detects external devices
//detect type
detectType(disks, disk);
detectType(disks, disk, device);
//Detects stats
detectStats(disk);
+1 -1
View File
@@ -1,6 +1,6 @@
#include "disk.h"
const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
const char* ffDetectDisksImpl(FF_MAYBE_UNUSED FFDiskOptions* options, FF_MAYBE_UNUSED FFlist* disks)
{
return "Not supported on this platform";
}
+4 -5
View File
@@ -72,19 +72,21 @@ static bool isSubvolume(const FFlist* disks, FFDisk* currentDisk)
static void detectType(const FFlist* disks, FFDisk* currentDisk, struct mnttab* device)
{
if(ffStrContains(device->mnt_mntopts, MNTOPT_NOBROWSE))
if(hasmntopt(device, MNTOPT_NOBROWSE))
currentDisk->type = FF_DISK_VOLUME_TYPE_HIDDEN_BIT;
else if(isSubvolume(disks, currentDisk))
currentDisk->type = FF_DISK_VOLUME_TYPE_SUBVOLUME_BIT;
else
currentDisk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT;
if (hasmntopt(device, MNTOPT_RO))
currentDisk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT;
}
static void detectStats(FFDisk* disk)
{
struct statvfs fs;
if(statvfs(disk->mountpoint.chars, &fs) != 0)
memset(&fs, 0, sizeof(struct statvfs));
memset(&fs, 0, sizeof(fs));
disk->bytesTotal = fs.f_blocks * fs.f_frsize;
disk->bytesFree = fs.f_bfree * fs.f_frsize;
@@ -94,9 +96,6 @@ static void detectStats(FFDisk* disk)
disk->filesTotal = (uint32_t) fs.f_files;
disk->filesUsed = (uint32_t) (disk->filesTotal - fs.f_ffree);
if(fs.f_flag & ST_RDONLY)
disk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT;
ffStrbufSetS(&disk->name, fs.f_fstr);
disk->createTime = 0;
+7 -7
View File
@@ -22,9 +22,9 @@ static unsigned __stdcall testRemoteVolumeAccessible(void* mountpoint)
const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
{
wchar_t buf[MAX_PATH + 1];
uint32_t length = GetLogicalDriveStringsW(sizeof(buf) / sizeof(*buf), buf);
if (length == 0 || length >= sizeof(buf) / sizeof(*buf))
return "GetLogicalDriveStringsW(sizeof(buf) / sizeof(*buf), buf) failed";
uint32_t length = GetLogicalDriveStringsW(ARRAY_SIZE(buf), buf);
if (length == 0 || length >= ARRAY_SIZE(buf))
return "GetLogicalDriveStringsW(ARRAY_SIZE(buf), buf) failed";
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
@@ -32,7 +32,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
if (__builtin_expect(options->folders.length == 1 && options->folders.chars[0] == '/', 0))
{
wchar_t path[MAX_PATH + 1];
GetSystemWindowsDirectoryW(path, sizeof(path) / sizeof(*path));
GetSystemWindowsDirectoryW(path, ARRAY_SIZE(path));
ffStrbufSetF(&options->folders, "%c:\\", (char) path[0]);
}
@@ -76,7 +76,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
{
wchar_t volumeName[MAX_PATH + 1];
mountpoint[2] = L'\0';
if(QueryDosDeviceW(mountpoint, volumeName, sizeof(volumeName) / sizeof(*volumeName)))
if(QueryDosDeviceW(mountpoint, volumeName, ARRAY_SIZE(volumeName)))
ffStrbufSetWS(&disk->mountFrom, volumeName);
mountpoint[2] = L'\\';
}
@@ -104,11 +104,11 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
DWORD diskFlags;
BOOL result = GetVolumeInformationW(mountpoint,
diskName, sizeof(diskName) / sizeof(*diskName), //Volume name
diskName, ARRAY_SIZE(diskName), //Volume name
NULL, //Serial number
NULL, //Max component length
&diskFlags, //File system flags
diskFileSystem, sizeof(diskFileSystem) / sizeof(*diskFileSystem)
diskFileSystem, ARRAY_SIZE(diskFileSystem)
);
SetErrorMode(errorMode);
+2 -2
View File
@@ -41,9 +41,9 @@ const char* ffDetectDiskIO(FFlist* result, FFDiskIOOptions* options)
return "No physical disk found";
uint64_t time2 = ffTimeGetNow();
while (time2 - time1 < 1000)
while (time2 - time1 < options->waitTime)
{
ffTimeSleep((uint32_t) (1000 - (time2 - time1)));
ffTimeSleep((uint32_t) (options->waitTime - (time2 - time1)));
time2 = ffTimeGetNow();
}
+68 -77
View File
@@ -6,6 +6,71 @@
#include <ctype.h>
#include <limits.h>
#include <inttypes.h>
#include <fcntl.h>
static void parseDiskIOCounters(int dfd, const char* devName, FFlist* result, FFDiskIOOptions* options)
{
FF_AUTO_CLOSE_FD int devfd = openat(dfd, "device", O_RDONLY | O_CLOEXEC | O_PATH | O_DIRECTORY);
if (devfd < 0) return; // virtual device
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate();
{
if (ffAppendFileBufferRelative(devfd, "vendor", &name))
{
ffStrbufTrimRightSpace(&name);
if (name.length > 0)
ffStrbufAppendC(&name, ' ');
}
if (ffAppendFileBufferRelative(devfd, "model", &name))
ffStrbufTrimRightSpace(&name);
if (name.length == 0)
ffStrbufSetS(&name, devName);
else if (ffStrStartsWith(devName, "nvme"))
{
int devid, nsid;
if (sscanf(devName, "nvme%dn%d", &devid, &nsid) == 2)
{
bool multiNs = nsid > 1;
if (!multiNs)
{
char pathSysBlock[16];
snprintf(pathSysBlock, ARRAY_SIZE(pathSysBlock), "nvme%dn2", devid);
multiNs = faccessat(devfd, pathSysBlock, F_OK, 0) == 0;
}
if (multiNs)
{
// In Asahi Linux, there are multiple namespaces for the same NVMe drive.
ffStrbufAppendF(&name, " - %d", nsid);
}
}
}
if (options->namePrefix.length && !ffStrbufStartsWith(&name, &options->namePrefix))
return;
}
// I/Os merges sectors ticks ...
uint64_t nRead, sectorRead, nWritten, sectorWritten;
{
char sysBlockStat[PROC_FILE_BUFFSIZ];
ssize_t fileSize = ffReadFileDataRelative(dfd, "stat", ARRAY_SIZE(sysBlockStat) - 1, sysBlockStat);
if (fileSize <= 0) return;
sysBlockStat[fileSize] = '\0';
if (sscanf(sysBlockStat, "%" PRIu64 "%*u%" PRIu64 "%*u%" PRIu64 "%*u%" PRIu64 "%*u", &nRead, &sectorRead, &nWritten, &sectorWritten) <= 0)
return;
}
FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result);
ffStrbufInitMove(&device->name, &name);
ffStrbufInitF(&device->devPath, "/dev/%s", devName);
device->bytesRead = sectorRead * 512;
device->bytesWritten = sectorWritten * 512;
device->readCount = nRead;
device->writeCount = nWritten;
}
const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
{
@@ -18,84 +83,10 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
{
const char* const devName = sysBlockEntry->d_name;
if (devName[0] == '.')
continue;
if (devName[0] == '.') continue;;
char pathSysBlock[PATH_MAX];
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s", devName);
char pathSysDeviceReal[PATH_MAX];
ssize_t pathLength = readlink(pathSysBlock, pathSysDeviceReal, sizeof(pathSysDeviceReal) - 1);
if (pathLength < 0)
continue;
pathSysDeviceReal[pathLength] = '\0';
if (strstr(pathSysDeviceReal, "/virtual/")) // virtual device
continue;
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device", devName);
if (!ffPathExists(pathSysBlock, FF_PATHTYPE_DIRECTORY))
continue;
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate();
{
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/vendor", devName);
if (ffAppendFileBuffer(pathSysBlock, &name))
{
ffStrbufTrimRightSpace(&name);
if (name.length > 0)
ffStrbufAppendC(&name, ' ');
}
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/model", devName);
ffAppendFileBuffer(pathSysBlock, &name);
ffStrbufTrimRightSpace(&name);
if (name.length == 0)
ffStrbufSetS(&name, devName);
else if (ffStrStartsWith(devName, "nvme"))
{
int devid, nsid;
if (sscanf(devName, "nvme%dn%d", &devid, &nsid) == 2)
{
bool multiNs = nsid > 1;
if (!multiNs)
{
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/nvme%dn2", devName, devid);
multiNs = ffPathExists(pathSysBlock, FF_PATHTYPE_DIRECTORY);
}
if (multiNs)
{
// In Asahi Linux, there are multiple namespaces for the same NVMe drive.
ffStrbufAppendF(&name, " - %d", nsid);
}
}
}
if (options->namePrefix.length && !ffStrbufStartsWith(&name, &options->namePrefix))
continue;
}
// I/Os merges sectors ticks ...
uint64_t nRead, sectorRead, nWritten, sectorWritten;
{
char sysBlockStat[PROC_FILE_BUFFSIZ];
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/stat", devName);
ssize_t fileSize = ffReadFileData(pathSysBlock, sizeof(sysBlockStat) - 1, sysBlockStat);
if (fileSize <= 0) continue;
sysBlockStat[fileSize] = '\0';
if (sscanf(sysBlockStat, "%" PRIu64 "%*u%" PRIu64 "%*u%" PRIu64 "%*u%" PRIu64 "%*u", &nRead, &sectorRead, &nWritten, &sectorWritten) <= 0)
continue;
}
FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result);
ffStrbufInitMove(&device->name, &name);
ffStrbufInitF(&device->devPath, "/dev/%s", devName);
device->bytesRead = sectorRead * 512;
device->bytesWritten = sectorWritten * 512;
device->readCount = nRead;
device->writeCount = nWritten;
FF_AUTO_CLOSE_FD int dfd = openat(dirfd(sysBlockDirp), devName, O_RDONLY | O_CLOEXEC | O_PATH | O_DIRECTORY);
if (dfd > 0) parseDiskIOCounters(dfd, devName, result, options);
}
return NULL;
+1 -1
View File
@@ -1,6 +1,6 @@
#include "diskio.h"
const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
const char* ffDiskIOGetIoCounters(FF_MAYBE_UNUSED FFlist* result, FF_MAYBE_UNUSED FFDiskIOOptions* options)
{
return "Not supported on this platform";
}
+1 -1
View File
@@ -22,7 +22,7 @@ static bool detectPhysicalDisk(const wchar_t* szDevice, FFlist* result, FFDiskIO
},
sizeof(STORAGE_PROPERTY_QUERY),
&sddBuffer,
sizeof(sddBuffer),
ARRAY_SIZE(sddBuffer),
&retSize,
NULL
) || retSize == 0)
+3 -1
View File
@@ -13,7 +13,8 @@ FFDisplayResult* ffdsAppendDisplay(
bool primary,
uint64_t id,
uint32_t physicalWidth,
uint32_t physicalHeight)
uint32_t physicalHeight,
const char* platformApi)
{
if(width == 0 || height == 0)
return NULL;
@@ -31,6 +32,7 @@ FFDisplayResult* ffdsAppendDisplay(
display->physicalWidth = physicalWidth;
display->physicalHeight = physicalHeight;
display->primary = primary;
display->platformApi = platformApi;
display->bitDepth = 0;
display->hdrStatus = FF_DISPLAY_HDR_STATUS_UNKNOWN;
+3 -1
View File
@@ -70,6 +70,7 @@ typedef struct FFDisplayResult
uint32_t physicalWidth;
uint32_t physicalHeight;
bool primary;
const char* platformApi;
uint8_t bitDepth;
FFDisplayHdrStatus hdrStatus;
uint16_t manufactureYear;
@@ -102,4 +103,5 @@ FFDisplayResult* ffdsAppendDisplay(
bool primary,
uint64_t id,
uint32_t physicalWidth,
uint32_t physicalHeight);
uint32_t physicalHeight,
const char* platformApi);
@@ -66,7 +66,8 @@ static void detectWithDumpsys(FFDisplayServerResult* ds)
false,
0,
0,
0
0,
"dumpsys"
);
}
@@ -100,7 +101,8 @@ static bool detectWithGetprop(FFDisplayServerResult* ds)
false,
0,
0,
0
0,
"getprop"
);
}
@@ -9,9 +9,9 @@
#include <CoreGraphics/CGDirectDisplay.h>
#include <CoreVideo/CVDisplayLink.h>
#ifdef MAC_OS_X_VERSION_10_15
extern Boolean CoreDisplay_Display_SupportsHDRMode(CGDirectDisplayID display) __attribute__((weak_import));
extern Boolean CoreDisplay_Display_IsHDRModeEnabled(CGDirectDisplayID display) __attribute__((weak_import));
#ifdef MAC_OS_X_VERSION_10_15
extern CFDictionaryRef CoreDisplay_DisplayCreateInfoDictionary(CGDirectDisplayID display) __attribute__((weak_import));
#else
#include <IOKit/graphics/IOGraphicsLib.h>
@@ -21,7 +21,7 @@ static void detectDisplays(FFDisplayServerResult* ds)
{
CGDirectDisplayID screens[128];
uint32_t screenCount;
if(CGGetOnlineDisplayList(sizeof(screens) / sizeof(screens[0]), screens, &screenCount) != kCGErrorSuccess)
if(CGGetOnlineDisplayList(ARRAY_SIZE(screens), screens, &screenCount) != kCGErrorSuccess)
return;
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
@@ -94,7 +94,8 @@ static void detectDisplays(FFDisplayServerResult* ds)
CGDisplayIsMain(screen),
(uint64_t)screen,
physicalWidth,
physicalHeight
physicalHeight,
"CoreGraphics"
);
if (display)
{
@@ -111,6 +112,7 @@ static void detectDisplays(FFDisplayServerResult* ds)
if (display->type == FF_DISPLAY_TYPE_BUILTIN)
display->hdrStatus = CFDictionaryContainsKey(displayInfo, CFSTR("ReferencePeakHDRLuminance"))
? FF_DISPLAY_HDR_STATUS_SUPPORTED : FF_DISPLAY_HDR_STATUS_UNSUPPORTED;
#ifdef MAC_OS_X_VERSION_10_15
else if (CoreDisplay_Display_SupportsHDRMode)
{
if (CoreDisplay_Display_SupportsHDRMode(screen))
@@ -122,6 +124,7 @@ static void detectDisplays(FFDisplayServerResult* ds)
else
display->hdrStatus = FF_DISPLAY_HDR_STATUS_UNSUPPORTED;
}
#endif
display->serial = CGDisplaySerialNumber(screen);
int value;
@@ -36,9 +36,9 @@ static void detectDisplays(FFDisplayServerResult* ds)
EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, (LPARAM) &monitors);
DISPLAYCONFIG_PATH_INFO paths[128];
uint32_t pathCount = sizeof(paths) / sizeof(paths[0]);
uint32_t pathCount = ARRAY_SIZE(paths);
DISPLAYCONFIG_MODE_INFO modes[256];
uint32_t modeCount = sizeof(modes) / sizeof(modes[0]);
uint32_t modeCount = ARRAY_SIZE(modes);
if (QueryDisplayConfig(
QDC_ONLY_ACTIVE_PATHS,
@@ -66,7 +66,7 @@ static void detectDisplays(FFDisplayServerResult* ds)
{
FF_LIST_FOR_EACH(FFMonitorInfo, item, monitors)
{
if (wcsncmp(item->info.szDevice, sourceName.viewGdiDeviceName, sizeof(sourceName.viewGdiDeviceName) / sizeof(wchar_t)) == 0)
if (wcsncmp(item->info.szDevice, sourceName.viewGdiDeviceName, ARRAY_SIZE(sourceName.viewGdiDeviceName)) == 0)
{
monitorInfo = item;
break;
@@ -102,11 +102,11 @@ static void detectDisplays(FFDisplayServerResult* ds)
*pRegPath = *pDevPath;
++pRegPath;
++pDevPath;
assert(pRegPath < regPath + sizeof(regPath) / sizeof(wchar_t) + strlen("Device Parameters"));
assert(pRegPath < regPath + ARRAY_SIZE(regPath) + strlen("Device Parameters"));
}
wcscpy(pRegPath, L"Device Parameters");
edidLength = sizeof(edidData);
edidLength = ARRAY_SIZE(edidData);
if (RegGetValueW(HKEY_LOCAL_MACHINE, regPath, L"EDID", RRF_RT_REG_BINARY, NULL, edidData, &edidLength) == ERROR_SUCCESS &&
edidLength > 0 && edidLength % 128 == 0)
{
@@ -165,7 +165,8 @@ static void detectDisplays(FFDisplayServerResult* ds)
!!(monitorInfo->info.dwFlags & MONITORINFOF_PRIMARY),
(uint64_t)(uintptr_t) monitorInfo->handle,
physicalWidth,
physicalHeight
physicalHeight,
"GDI"
);
if (display)
@@ -86,7 +86,7 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds)
if (ffSettingsGetFreeBSDKenv("screen.height", &buf))
{
uint32_t height = (uint32_t) ffStrbufToUInt(&buf, 0);
ffdsAppendDisplay(ds, width, height, 0, 0, 0, 0, NULL, FF_DISPLAY_TYPE_UNKNOWN, false, 0, 0, 0);
ffdsAppendDisplay(ds, width, height, 0, 0, 0, 0, NULL, FF_DISPLAY_TYPE_UNKNOWN, false, 0, 0, 0, "kenv");
}
}
}
@@ -1,8 +1,5 @@
#pragma once
#ifndef FASTFETCH_INCLUDED_DISPLAYSERVER
#define FASTFETCH_INCLUDED_DISPLAYSERVER
#include "detection/displayserver/displayserver.h"
const char* ffdsConnectWayland(FFDisplayServerResult* result);
@@ -18,5 +15,3 @@ const char* ffdsConnectDrm(FFDisplayServerResult* result);
void ffdsDetectWMDE(FFDisplayServerResult* result);
FFDisplayType ffdsGetDisplayType(const char* drmConnectorName);
#endif
+10 -8
View File
@@ -22,7 +22,7 @@ static const char* drmParseSysfs(FFDisplayServerResult* result)
struct dirent* entry;
while((entry = readdir(dirp)) != NULL)
{
if(ffStrEquals(entry->d_name, ".") || ffStrEquals(entry->d_name, ".."))
if(entry->d_name[0] == '.')
continue;
ffStrbufAppendS(&drmDir, entry->d_name);
@@ -58,7 +58,7 @@ static const char* drmParseSysfs(FFDisplayServerResult* result)
}
uint8_t edidData[512];
ssize_t edidLength = ffReadFileData(drmDir.chars, sizeof(edidData), edidData);
ssize_t edidLength = ffReadFileData(drmDir.chars, ARRAY_SIZE(edidData), edidData);
if(edidLength <= 0 || edidLength % 128 != 0)
{
edidLength = 0;
@@ -66,7 +66,7 @@ static const char* drmParseSysfs(FFDisplayServerResult* result)
ffStrbufAppendS(&drmDir, "/modes");
char modes[32];
if (ffReadFileData(drmDir.chars, sizeof(modes), modes) >= 3)
if (ffReadFileData(drmDir.chars, ARRAY_SIZE(modes), modes) >= 3)
{
sscanf(modes, "%ux%u", &width, &height);
ffStrbufAppendS(&name, plainName);
@@ -90,7 +90,8 @@ static const char* drmParseSysfs(FFDisplayServerResult* result)
false,
0,
physicalWidth,
physicalHeight
physicalHeight,
"sysfs-drm"
);
if (item && edidLength)
{
@@ -184,7 +185,7 @@ FF_MAYBE_UNUSED static const char* drmGetEdidByConnId(uint32_t connId, uint8_t*
struct dirent* entry;
while((entry = readdir(dirp)) != NULL)
{
if(ffStrEquals(entry->d_name, ".") || ffStrEquals(entry->d_name, ".."))
if(entry->d_name[0] == '.')
continue;
ffStrbufAppendS(&drmDir, entry->d_name);
@@ -193,7 +194,7 @@ FF_MAYBE_UNUSED static const char* drmGetEdidByConnId(uint32_t connId, uint8_t*
char connectorId[16] = {};
ffStrbufAppendS(&drmDir, "/connector_id");
ffReadFileData(drmDir.chars, sizeof(connectorId), connectorId);
ffReadFileData(drmDir.chars, ARRAY_SIZE(connectorId), connectorId);
if (strtoul(connectorId, NULL, 10) != connId)
{
ffStrbufSubstrBefore(&drmDir, drmDirLength);
@@ -228,7 +229,7 @@ static const char* drmConnectLibdrm(FFDisplayServerResult* result)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libdrm, drmFreeDevices)
drmDevice* devices[64];
int nDevices = ffdrmGetDevices(devices, sizeof(devices) / sizeof(devices[0]));
int nDevices = ffdrmGetDevices(devices, ARRAY_SIZE(devices));
if (nDevices <= 0)
return "drmGetDevices() failed";
@@ -390,7 +391,8 @@ static const char* drmConnectLibdrm(FFDisplayServerResult* result)
false,
conn->connector_id,
conn->mmWidth,
conn->mmHeight
conn->mmHeight,
"libdrm"
);
if (item)
@@ -129,7 +129,8 @@ void ffWaylandHandleGlobalOutput(WaylandData* wldata, struct wl_registry* regist
false,
display.id,
(uint32_t) display.physicalWidth,
(uint32_t) display.physicalHeight
(uint32_t) display.physicalHeight,
"wayland-global"
);
if (item)
{
@@ -112,6 +112,7 @@ static void waylandKdeNameListener(void* data, FF_MAYBE_UNUSED struct kde_output
{
WaylandDisplay* display = data;
display->type = ffdsGetDisplayType(name);
// As display->id is used as an internal identifier, we don't need it to be NUL terminated
strncpy((char*) &display->id, name, sizeof(display->id));
ffStrbufAppendS(&display->name, name);
}
@@ -194,7 +195,8 @@ void ffWaylandHandleKdeOutput(WaylandData* wldata, struct wl_registry* registry,
false,
display.id,
(uint32_t) display.physicalWidth,
(uint32_t) display.physicalHeight
(uint32_t) display.physicalHeight,
"wayland-kde"
);
if (item)
{
@@ -22,7 +22,7 @@
static bool waylandDetectWM(int fd, FFDisplayServerResult* result)
{
struct ucred ucred;
socklen_t len = sizeof(struct ucred);
socklen_t len = sizeof(ucred);
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &len) == -1 || ucred.pid <= 0)
return false;
@@ -108,7 +108,7 @@ static bool matchDrmConnector(const char* connName, WaylandDisplay* wldata)
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateF("%s%s/edid", drmDirPath, entry->d_name);
uint8_t edidData[512];
ssize_t edidLength = ffReadFileData(path.chars, sizeof(edidData), edidData);
ssize_t edidLength = ffReadFileData(path.chars, ARRAY_SIZE(edidData), edidData);
if (edidLength > 0 && edidLength % 128 == 0)
{
ffEdidGetName(edidData, &wldata->edidName);
@@ -249,7 +249,7 @@ const char* ffdsConnectWayland(FFDisplayServerResult* result)
FF_LIST_FOR_EACH(FFstrbuf, basePath, instance.state.platform.configDirs)
{
char path[1024];
snprintf(path, sizeof(path) - 1, "%s%s", basePath->chars, fileName);
snprintf(path, ARRAY_SIZE(path) - 1, "%s%s", basePath->chars, fileName);
if (ffReadFileBuffer(path, &monitorsXml))
break;
}
@@ -138,7 +138,8 @@ static void waylandHandleZwlrHead(void *data, FF_MAYBE_UNUSED struct zwlr_output
false,
display.id,
(uint32_t) display.physicalWidth,
(uint32_t) display.physicalHeight
(uint32_t) display.physicalHeight,
"wayland-zwlr"
);
if (item)
{
+3 -3
View File
@@ -260,11 +260,11 @@ static const char* getFromProcesses(FFDisplayServerResult* result)
int request[] = {CTL_KERN, KERN_PROC, KERN_PROC_UID, (int) userId};
size_t length = 0;
if(sysctl(request, sizeof(request) / sizeof(*request), NULL, &length, NULL, 0) != 0)
if(sysctl(request, ARRAY_SIZE(request), NULL, &length, NULL, 0) != 0)
return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_UID}, NULL) failed";
FF_AUTO_FREE struct kinfo_proc* procs = (struct kinfo_proc*) malloc(length);
if(sysctl(request, sizeof(request) / sizeof(*request), procs, &length, NULL, 0) != 0)
if(sysctl(request, ARRAY_SIZE(request), procs, &length, NULL, 0) != 0)
return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_UID}, procs) failed";
length /= sizeof(*procs);
@@ -283,7 +283,7 @@ static const char* getFromProcesses(FFDisplayServerResult* result)
#elif __OpenBSD__
kvm_t* kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, NULL);
int count = 0;
const struct kinfo_proc* proc = kvm_getprocs(kd, KERN_PROC_UID, userId, sizeof(struct kinfo_proc), &count);
const struct kinfo_proc* proc = kvm_getprocs(kd, KERN_PROC_UID, userId, sizeof(*proc), &count);
if (proc)
{
for (int i = 0; i < count; ++i)
+8 -4
View File
@@ -118,7 +118,8 @@ const char* ffdsConnectXcb(FFDisplayServerResult* result)
false,
0,
(uint32_t) screen->width_in_millimeters,
(uint32_t) screen->height_in_millimeters
(uint32_t) screen->height_in_millimeters,
"xcb"
);
ffxcb_screen_next(&iterator);
}
@@ -239,7 +240,8 @@ static bool xcbRandrHandleCrtc(XcbRandrData* data, xcb_randr_crtc_t crtc, FFstrb
primary,
0,
(uint32_t) output->mm_width,
(uint32_t) output->mm_height
(uint32_t) output->mm_height,
"xcb-randr-crtc"
);
if (item && edidLength)
{
@@ -327,7 +329,8 @@ static bool xcbRandrHandleMonitor(XcbRandrData* data, xcb_randr_monitor_info_t*
!!monitor->primary,
0,
(uint32_t) monitor->width_in_millimeters,
(uint32_t) monitor->height_in_millimeters
(uint32_t) monitor->height_in_millimeters,
"xcb-randr-monitor"
);
}
@@ -381,7 +384,8 @@ static void xcbRandrHandleScreen(XcbRandrData* data, xcb_screen_t* screen)
false,
0,
(uint32_t) screen->width_in_millimeters,
(uint32_t) screen->height_in_millimeters
(uint32_t) screen->height_in_millimeters,
"xcb-randr-screen"
);
}
+8 -4
View File
@@ -89,7 +89,8 @@ const char* ffdsConnectXlib(FFDisplayServerResult* result)
false,
0,
(uint32_t) WidthMMOfScreen(screen),
(uint32_t) HeightMMOfScreen(screen)
(uint32_t) HeightMMOfScreen(screen),
"xlib"
);
}
@@ -193,7 +194,8 @@ static bool xrandrHandleCrtc(XrandrData* data, XRROutputInfo* output, FFstrbuf*
primary,
0,
(uint32_t) output->mm_width,
(uint32_t) output->mm_height
(uint32_t) output->mm_height,
"xlib-randr-crtc"
);
if (edidLength)
@@ -268,7 +270,8 @@ static bool xrandrHandleMonitor(XrandrData* data, XRRMonitorInfo* monitorInfo)
!!monitorInfo->primary,
0,
(uint32_t) monitorInfo->mwidth,
(uint32_t) monitorInfo->mheight
(uint32_t) monitorInfo->mheight,
"xlib-randr-monitor"
);
}
@@ -318,7 +321,8 @@ static void xrandrHandleScreen(XrandrData* data, Screen* screen)
false,
0,
(uint32_t) WidthMMOfScreen(screen),
(uint32_t) HeightMMOfScreen(screen)
(uint32_t) HeightMMOfScreen(screen),
"xlib_randr_screen"
);
}
+1 -1
View File
@@ -11,7 +11,7 @@ static void generateString(FFFontResult* font)
ffStrbufAppend(&font->display, &font->fonts[0]);
ffStrbufAppendS(&font->display, " [Qt]");
for(uint8_t i = 1; i < sizeof(font->fonts) / sizeof(font->fonts[0]); i++)
for(uint8_t i = 1; i < ARRAY_SIZE(font->fonts); i++)
{
if(font->fonts[i].length > 0)
{
+2 -2
View File
@@ -6,7 +6,7 @@
static void generateString(FFFontResult* font)
{
const char* types[] = { "Caption", "Menu", "Message", "Status" };
for(uint32_t i = 0; i < sizeof(types) / sizeof(types[0]); ++i)
for(uint32_t i = 0; i < ARRAY_SIZE(types); ++i)
{
if(i == 0 || !ffStrbufEqual(&font->fonts[i - 1], &font->fonts[i]))
{
@@ -31,7 +31,7 @@ const char* ffDetectFontImpl(FFFontResult* result)
LOGFONTW* fonts[4] = { &info.lfCaptionFont, &info.lfMenuFont, &info.lfMessageFont, &info.lfStatusFont };
for(uint32_t i = 0; i < sizeof(fonts) / sizeof(fonts[0]); ++i)
for(uint32_t i = 0; i < ARRAY_SIZE(fonts); ++i)
{
ffStrbufSetWS(&result->fonts[i], fonts[i]->lfFaceName);
if(fonts[i]->lfHeight < 0)
+4 -3
View File
@@ -13,7 +13,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
char path[16];
for (int i = 0; i < MAX_UHID_JOYS; i++)
{
snprintf(path, sizeof(path), "/dev/uhid%d", i);
snprintf(path, ARRAY_SIZE(path), "/dev/uhid%d", i);
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0) continue;
@@ -31,8 +31,9 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
if (HID_PAGE(hItem.usage) != 1) continue;
switch (HID_USAGE(hItem.usage))
{
case 1: // FreeBSD returns 1 for my Pro Controller for some reason
case 5:
case 1: // Pointer. FreeBSD returns 1 for my Pro Controller for some reason
case 4: // Joystick
case 5: // Gamepad
break;
default:
continue;
+3 -3
View File
@@ -28,7 +28,7 @@ static void detectGamepad(FFlist* devices, FFstrbuf* name, FFstrbuf* path)
ffStrbufAppendS(path, entry->d_name);
ffStrbufAppendS(path, "/capacity"); // /sys/class/input/jsX/device/device/power_supply/XXX/capacity
char capacity[32];
ssize_t nRead = ffReadFileData(path->chars, sizeof(capacity) - 1, capacity);
ssize_t nRead = ffReadFileData(path->chars, ARRAY_SIZE(capacity) - 1, capacity);
if (nRead > 0) // Tested with a PS4 controller
{
capacity[nRead] = '\0';
@@ -37,7 +37,7 @@ static void detectGamepad(FFlist* devices, FFstrbuf* name, FFstrbuf* path)
}
ffStrbufAppendS(path, "_level");
nRead = ffReadFileData(path->chars, sizeof(capacity) - 1, capacity);
nRead = ffReadFileData(path->chars, ARRAY_SIZE(capacity) - 1, capacity);
if (nRead > 0) // Tested with a NS Pro controller
{
// https://github.com/torvalds/linux/blob/52b1853b080a082ec3749c3a9577f6c71b1d4a90/drivers/power/supply/power_supply_sysfs.c#L124
@@ -68,7 +68,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
{
if (!ffStrStartsWith(entry->d_name, "js"))
continue;
if (!ffCharIsDigit(entry->d_name[2]))
if (!ffCharIsDigit(entry->d_name[strlen("js")]))
continue;
ffStrbufAppendS(&path, entry->d_name);
+9 -9
View File
@@ -78,7 +78,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
for (UINT i = 0; i < nDevices; ++i)
{
if (pRawInputDeviceList[i].dwType != 2) continue;
if (pRawInputDeviceList[i].dwType != RIM_TYPEHID) continue;
HANDLE hDevice = pRawInputDeviceList[i].hDevice;
@@ -87,7 +87,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
if (GetRawInputDeviceInfoW(hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) == (UINT) -1)
continue;
if (rdi.hid.usUsagePage != 1 || rdi.hid.usUsage != 5) // Gamepad
if (rdi.hid.usUsagePage != 1 || (rdi.hid.usUsage != 4/*Joystick*/ && rdi.hid.usUsage != 5/*Gamepad*/))
continue;
WCHAR devName[MAX_PATH] = L"";
@@ -104,7 +104,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
if (knownGamepad)
ffStrbufSetS(&device->name, knownGamepad);
HANDLE FF_AUTO_CLOSE_FD hHidFile = CreateFileW(devName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
if (!hHidFile)
if (hHidFile == INVALID_HANDLE_VALUE)
{
if (!knownGamepad)
ffStrbufSetF(&device->name, "Unknown gamepad %04X-%04X", (unsigned) rdi.hid.dwVendorId, (unsigned) rdi.hid.dwProductId);
@@ -114,10 +114,10 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
if (!knownGamepad)
{
wchar_t displayName[126];
if (HidD_GetProductString(hHidFile, displayName, sizeof(displayName)))
if (HidD_GetProductString(hHidFile, displayName, sizeof(displayName) /*in bytes*/))
{
wchar_t manufacturer[126];
if (HidD_GetManufacturerString(hHidFile, manufacturer, sizeof(manufacturer)))
if (HidD_GetManufacturerString(hHidFile, manufacturer, sizeof(manufacturer) /*in bytes*/))
{
ffStrbufSetWS(&device->name, manufacturer);
FF_STRBUF_AUTO_DESTROY displayNameStr = ffStrbufCreateWS(displayName);
@@ -131,6 +131,10 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
}
}
wchar_t serialNumber[127] = L"";
if (HidD_GetSerialNumberString(hHidFile, serialNumber, sizeof(serialNumber) /*in bytes*/))
ffStrbufSetWS(&device->serial, serialNumber);
PHIDP_PREPARSED_DATA preparsedData = NULL;
if (HidD_GetPreparsedData(hHidFile, &preparsedData))
{
@@ -140,10 +144,6 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
if (!NT_SUCCESS(capsResult))
continue;
wchar_t serialNumber[127] = L"";
if (HidD_GetSerialNumberString(hHidFile, serialNumber, sizeof(serialNumber)))
ffStrbufSetWS(&device->serial, serialNumber);
if (
(rdi.hid.dwVendorId == 0x054C && (
rdi.hid.dwProductId == 0x05C4 || // PS4 Gen1
+1 -1
View File
@@ -76,7 +76,7 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD)
{
char query[32];
snprintf(query, sizeof(query), "%X,\t%X,", (unsigned) pc->pc_device, (unsigned) pc->pc_revid);
snprintf(query, ARRAY_SIZE(query), "%X,\t%X,", (unsigned) pc->pc_device, (unsigned) pc->pc_revid);
ffParsePropFileData("libdrm/amdgpu.ids", query, &gpu->name);
}
if (gpu->name.length == 0)
+3 -3
View File
@@ -128,7 +128,7 @@ const char* ffDetectIntelGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverRe
if (result.memory)
{
ctl_mem_handle_t memoryModules[16];
uint32_t memoryCount = sizeof(memoryModules) / sizeof(memoryModules[0]);
uint32_t memoryCount = ARRAY_SIZE(memoryModules);
if (igclData.ffctlEnumMemoryModules(device, &memoryCount, memoryModules) == CTL_RESULT_SUCCESS && memoryCount > 0)
{
result.memory->used = 0;
@@ -157,7 +157,7 @@ const char* ffDetectIntelGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverRe
if (result.temp)
{
ctl_temp_handle_t sensors[16];
uint32_t sensorCount = sizeof(sensors) / sizeof(sensors[0]);
uint32_t sensorCount = ARRAY_SIZE(sensors);
if (igclData.ffctlEnumTemperatureSensors(device, &sensorCount, sensors) == CTL_RESULT_SUCCESS && sensorCount > 0)
{
double sumValue = 0;
@@ -178,7 +178,7 @@ const char* ffDetectIntelGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverRe
if (result.frequency)
{
ctl_freq_handle_t domains[16];
uint32_t domainCount = sizeof(domains) / sizeof(domains[0]);
uint32_t domainCount = ARRAY_SIZE(domains);
if (igclData.ffctlEnumFrequencyDomains(device, &domainCount, domains) == CTL_RESULT_SUCCESS && domainCount > 0)
{
double maxValue = 0;
+6 -6
View File
@@ -32,7 +32,7 @@ static bool pciDetectDriver(FFstrbuf* result, FFstrbuf* pciDir, FFstrbuf* buffer
uint32_t pciDirLength = pciDir->length;
ffStrbufAppendS(pciDir, "/driver");
char pathBuf[PATH_MAX];
ssize_t resultLength = readlink(pciDir->chars, pathBuf, sizeof(pathBuf));
ssize_t resultLength = readlink(pciDir->chars, pathBuf, ARRAY_SIZE(pathBuf));
if(resultLength <= 0) return false;
const char* slash = memrchr(pathBuf, '/', (size_t) resultLength);
@@ -78,7 +78,7 @@ static bool pciDetectDriver(FFstrbuf* result, FFstrbuf* pciDir, FFstrbuf* buffer
return true;
}
static const char* drmFindRenderFromCard(const char* drmCardKey, FFstrbuf* result)
FF_MAYBE_UNUSED static const char* drmFindRenderFromCard(const char* drmCardKey, FFstrbuf* result)
{
char path[PATH_MAX];
sprintf(path, "/sys/class/drm/%s/device/drm", drmCardKey);
@@ -395,6 +395,7 @@ static const char* drmDetectIntelSpecific(FFGPUResult* gpu, const char* drmKey,
}
return NULL;
#else
FF_UNUSED(gpu, drmKey, buffer);
return "Fastfetch is not compiled with drm support";
#endif
}
@@ -414,7 +415,7 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf
const char* pPciPath = NULL;
if (drmKey)
{
ssize_t pathLength = readlink(deviceDir->chars, pciPath, sizeof(pciPath) - 1);
ssize_t pathLength = readlink(deviceDir->chars, pciPath, ARRAY_SIZE(pciPath) - 1);
if (pathLength <= 0)
return "Unable to get PCI device path";
pciPath[pathLength] = '\0';
@@ -459,8 +460,7 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf
{
if (ffStrStartsWith(entry->d_name, "card"))
{
strncpy(drmKeyBuffer, entry->d_name, sizeof(drmKeyBuffer) - 1);
drmKeyBuffer[sizeof(drmKeyBuffer) - 1] = '\0';
ffStrCopyN(drmKeyBuffer, entry->d_name, ARRAY_SIZE(drmKeyBuffer));
drmKey = drmKeyBuffer;
break;
}
@@ -493,7 +493,7 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf
if (pend != buffer->chars)
{
char query[32];
snprintf(query, sizeof(query), "%X,\t%X,", (unsigned) deviceId, (unsigned) revision);
snprintf(query, ARRAY_SIZE(query), "%X,\t%X,", (unsigned) deviceId, (unsigned) revision);
#ifdef FF_CUSTOM_AMDGPU_IDS_PATH
ffParsePropFile(FF_STR(FF_CUSTOM_AMDGPU_IDS_PATH), query, &gpu->name);
#else
+2 -2
View File
@@ -86,7 +86,7 @@ const char *ffDetectMthreadsGpuInfo(const FFGpuDriverCondition *cond, FFGpuDrive
if (cond->type & FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID)
{
char pciBusIdStr[32];
snprintf(pciBusIdStr, sizeof(pciBusIdStr) - 1, "%04x:%02x:%02x.%d", cond->pciBusId.domain, cond->pciBusId.bus, cond->pciBusId.device, cond->pciBusId.func);
snprintf(pciBusIdStr, ARRAY_SIZE(pciBusIdStr) - 1, "%04x:%02x:%02x.%d", cond->pciBusId.domain, cond->pciBusId.bus, cond->pciBusId.device, cond->pciBusId.func);
MtmlReturn ret = mtmlData.ffmtmlLibraryInitDeviceByPciSbdf(mtmlData.lib, pciBusIdStr, &device);
if (ret != MTML_SUCCESS)
@@ -195,7 +195,7 @@ const char *ffDetectMthreadsGpuInfo(const FFGpuDriverCondition *cond, FFGpuDrive
if (result.name)
{
char name[MTML_DEVICE_NAME_BUFFER_SIZE];
if (mtmlData.ffmtmlDeviceGetName(device, name, sizeof(name)) == MTML_SUCCESS)
if (mtmlData.ffmtmlDeviceGetName(device, name, ARRAY_SIZE(name)) == MTML_SUCCESS)
ffStrbufSetS(result.name, name);
}
+2 -2
View File
@@ -59,7 +59,7 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR
if (cond->type & FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID)
{
char pciBusIdStr[32];
snprintf(pciBusIdStr, sizeof(pciBusIdStr) - 1, "%04x:%02x:%02x.%d", cond->pciBusId.domain, cond->pciBusId.bus, cond->pciBusId.device, cond->pciBusId.func);
snprintf(pciBusIdStr, ARRAY_SIZE(pciBusIdStr) - 1, "%04x:%02x:%02x.%d", cond->pciBusId.domain, cond->pciBusId.bus, cond->pciBusId.device, cond->pciBusId.func);
nvmlReturn_t ret = nvmlData.ffnvmlDeviceGetHandleByPciBusId_v2(pciBusIdStr, &device);
if (ret != NVML_SUCCESS)
@@ -148,7 +148,7 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR
if (result.name)
{
char name[NVML_DEVICE_NAME_V2_BUFFER_SIZE];
if (nvmlData.ffnvmlDeviceGetName(device, name, sizeof(name)) == NVML_SUCCESS)
if (nvmlData.ffnvmlDeviceGetName(device, name, ARRAY_SIZE(name)) == NVML_SUCCESS)
ffStrbufSetS(result.name, name);
}
+3 -3
View File
@@ -55,7 +55,7 @@ static void parsePciIdsFile(const FFstrbuf* content, uint8_t subclass, uint16_t
char buffer[32];
// Search for vendor
uint32_t len = (uint32_t) snprintf(buffer, sizeof(buffer), "\n%04x ", vendor);
uint32_t len = (uint32_t) snprintf(buffer, ARRAY_SIZE(buffer), "\n%04x ", vendor);
char* start = (char*) memmem(content->chars, content->length, buffer, len);
char* end = content->chars + content->length;
if (start)
@@ -83,7 +83,7 @@ static void parsePciIdsFile(const FFstrbuf* content, uint8_t subclass, uint16_t
}
// Search for device
len = (uint32_t) snprintf(buffer, sizeof(buffer), "\n\t%04x ", device);
len = (uint32_t) snprintf(buffer, ARRAY_SIZE(buffer), "\n\t%04x ", device);
start = memmem(start, (size_t) (end - start), buffer, len);
if (start)
{
@@ -138,7 +138,7 @@ static bool loadPciidsInc(uint8_t subclass, uint16_t vendor, uint16_t device, FF
if (!gpu->vendor.length)
ffStrbufSetS(&gpu->vendor, pvendor->name);
const FFPciDevice* pdevice = (const FFPciDevice*) bsearch(&device, pvendor->devices, pvendor->nDevices, sizeof(FFPciDevice), (void*) pciDeviceCmp);
const FFPciDevice* pdevice = (const FFPciDevice*) bsearch(&device, pvendor->devices, pvendor->nDevices, sizeof(*pdevice), (void*) pciDeviceCmp);
if (pdevice)
{
+1 -1
View File
@@ -67,7 +67,7 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD)
{
char query[32];
snprintf(query, sizeof(query), "%X,\t%X,", (unsigned) deviceId, (unsigned) revision);
snprintf(query, ARRAY_SIZE(query), "%X,\t%X,", (unsigned) deviceId, (unsigned) revision);
ffParsePropFileData("libdrm/amdgpu.ids", query, &gpu->name);
}
+1 -1
View File
@@ -1,6 +1,6 @@
#include "host.h"
const char* ffDetectHost(FFHostResult* host)
const char* ffDetectHost(FF_MAYBE_UNUSED FFHostResult* host)
{
return "Not supported on this platform";
}
+9
View File
@@ -0,0 +1,9 @@
#include "fastfetch.h"
typedef struct FFKeyboardDevice
{
FFstrbuf serial;
FFstrbuf name;
} FFKeyboardDevice;
const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */);
+42
View File
@@ -0,0 +1,42 @@
#include "keyboard.h"
#include "util/apple/cf_helpers.h"
#include "util/mallocHelper.h"
#include <IOKit/IOKitLib.h>
#include <IOKit/hid/IOHIDLib.h>
static void enumSet(IOHIDDeviceRef value, FFlist* results)
{
FFKeyboardDevice* device = (FFKeyboardDevice*) ffListAdd(results);
ffStrbufInit(&device->serial);
ffStrbufInit(&device->name);
CFStringRef product = IOHIDDeviceGetProperty(value, CFSTR(kIOHIDProductKey));
ffCfStrGetString(product, &device->name);
CFStringRef serialNumber = IOHIDDeviceGetProperty(value, CFSTR(kIOHIDSerialNumberKey));
ffCfStrGetString(serialNumber, &device->serial);
}
const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */)
{
IOHIDManagerRef FF_CFTYPE_AUTO_RELEASE manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (IOHIDManagerOpen(manager, kIOHIDOptionsTypeNone) != kIOReturnSuccess)
return "IOHIDManagerOpen() failed";
CFDictionaryRef FF_CFTYPE_AUTO_RELEASE matching1 = CFDictionaryCreate(kCFAllocatorDefault, (const void **)(CFStringRef[]){
CFSTR(kIOHIDDeviceUsagePageKey),
CFSTR(kIOHIDDeviceUsageKey)
}, (const void **)(CFNumberRef[]){
ffCfCreateInt(kHIDPage_GenericDesktop),
ffCfCreateInt(kHIDUsage_GD_Keyboard)
}, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
IOHIDManagerSetDeviceMatching(manager, matching1);
CFSetRef FF_CFTYPE_AUTO_RELEASE set = IOHIDManagerCopyDevices(manager);
if (set)
CFSetApplyFunction(set, (CFSetApplierFunction) &enumSet, devices);
IOHIDManagerClose(manager, kIOHIDOptionsTypeNone);
return NULL;
}
+47
View File
@@ -0,0 +1,47 @@
#include "keyboard.h"
#include "common/io/io.h"
#include <stdio.h>
#include <fcntl.h>
#include <usbhid.h>
#include <dev/usb/usb_ioctl.h>
#define MAX_UHID_JOYS 64
const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */)
{
char path[16];
for (int i = 0; i < MAX_UHID_JOYS; i++)
{
snprintf(path, ARRAY_SIZE(path), "/dev/uhid%d", i);
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0) continue;
report_desc_t repDesc = hid_get_report_desc(fd);
if (!repDesc) continue;
int reportId = hid_get_report_id(fd);
struct hid_data* hData = hid_start_parse(repDesc, 0, reportId);
if (hData)
{
struct hid_item hItem;
while (hid_get_item(hData, &hItem) > 0)
{
if (HID_PAGE(hItem.usage) != 1 || HID_USAGE(hItem.usage) != 6) continue;
struct usb_device_info di;
if (ioctl(fd, USB_GET_DEVICEINFO, &di) != -1)
{
FFKeyboardDevice* device = (FFKeyboardDevice*) ffListAdd(devices);
ffStrbufInitS(&device->serial, di.udi_serial);
ffStrbufInitS(&device->name, di.udi_product);
}
}
}
hid_dispose_report_desc(repDesc);
}
return NULL;
}
+57
View File
@@ -0,0 +1,57 @@
#include "keyboard.h"
#include "common/io/io.h"
#include "util/stringUtils.h"
const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */)
{
// There is no /sys/class/input/kbd* on Linux
FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/dev/input/by-path/");
if (dirp == NULL)
return "opendir(\"/dev/input/by-path/\") == NULL";
uint64_t flags = 0;
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();
struct dirent* entry;
while ((entry = readdir(dirp)) != NULL)
{
if (!ffStrEndsWith(entry->d_name, "-event-kbd"))
continue;
char buffer[32]; // `../eventX`
ssize_t len = readlinkat(dirfd(dirp), entry->d_name, buffer, ARRAY_SIZE(buffer) - 1);
if (len != strlen("../eventX") || !ffStrStartsWith(buffer, "../event")) continue;
buffer[len] = 0;
const char* eventid = buffer + strlen("../event");
char* pend = NULL;
uint32_t index = (uint32_t) strtoul(eventid, &pend, 10);
if (pend == eventid) continue;
// Ignore duplicate entries
if (flags & (1 << index))
continue;
flags |= (1 << index);
ffStrbufSetF(&path, "/sys/class/input/event%s/device/name", eventid);
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate();
if (ffAppendFileBuffer(path.chars, &name))
{
ffStrbufTrimRightSpace(&name);
ffStrbufSubstrBefore(&path, path.length - 4);
FFKeyboardDevice* device = (FFKeyboardDevice*) ffListAdd(devices);
ffStrbufInitMove(&device->name, &name);
ffStrbufInit(&device->serial);
ffStrbufAppendS(&path, "uniq");
if (ffAppendFileBuffer(path.chars, &device->serial))
ffStrbufTrimRightSpace(&device->serial);
}
}
return NULL;
}
@@ -0,0 +1,6 @@
#include "keyboard.h"
const char* ffDetectKeyboard(FF_MAYBE_UNUSED FFlist* devices /* List of FFKeyboardDevice */)
{
return "No mouse support on this platform";
}
+82
View File
@@ -0,0 +1,82 @@
#define INITGUID
#include "keyboard.h"
#include "common/io/io.h"
#include "util/mallocHelper.h"
#include "util/windows/unicode.h"
#include <winternl.h>
#include <windows.h>
#include <hidsdi.h>
#include <cfgmgr32.h>
#include <devpkey.h>
const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */)
{
UINT nDevices = 0;
if (GetRawInputDeviceList(NULL, &nDevices, sizeof(RAWINPUTDEVICELIST)))
return "GetRawInputDeviceList(NULL) failed";
if (nDevices == 0)
return "No HID devices found";
RAWINPUTDEVICELIST* FF_AUTO_FREE pRawInputDeviceList = (RAWINPUTDEVICELIST*) malloc(sizeof(RAWINPUTDEVICELIST) * nDevices);
if ((nDevices = GetRawInputDeviceList(pRawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST))) == (UINT) -1)
return "GetRawInputDeviceList(pRawInputDeviceList) failed";
for (UINT i = 0; i < nDevices; ++i)
{
if (pRawInputDeviceList[i].dwType != RIM_TYPEKEYBOARD) continue;
HANDLE hDevice = pRawInputDeviceList[i].hDevice;
RID_DEVICE_INFO rdi;
UINT rdiSize = sizeof(rdi);
if (GetRawInputDeviceInfoW(hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) == (UINT) -1)
continue;
WCHAR devName[MAX_PATH];
UINT nameSize = MAX_PATH;
if (GetRawInputDeviceInfoW(hDevice, RIDI_DEVICENAME, devName, &nameSize) == (UINT) -1)
continue;
FFKeyboardDevice* device = (FFKeyboardDevice*) ffListAdd(devices);
ffStrbufInit(&device->serial);
ffStrbufInit(&device->name);
wchar_t buffer[MAX_PATH];
HANDLE FF_AUTO_CLOSE_FD hHidFile = CreateFileW(devName, 0 /* must be 0 instead of GENERIC_READ */, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (hHidFile != INVALID_HANDLE_VALUE)
{
if (HidD_GetProductString(hHidFile, buffer, (ULONG) sizeof(buffer)))
ffStrbufSetWS(&device->name, buffer);
if (HidD_GetSerialNumberString(hHidFile, buffer, sizeof(buffer)))
ffStrbufSetWS(&device->serial, buffer);
}
if (!device->name.length)
{
// https://stackoverflow.com/a/64321096/9976392
DEVPROPTYPE propertyType;
ULONG propertySize = sizeof(buffer);
if (CM_Get_Device_Interface_PropertyW(devName, &DEVPKEY_Device_InstanceId, &propertyType, (PBYTE) buffer, &propertySize, 0) == CR_SUCCESS)
{
DEVINST devInst;
if (CM_Locate_DevNodeW(&devInst, buffer, CM_LOCATE_DEVNODE_NORMAL) == CR_SUCCESS)
{
propertySize = sizeof(buffer);
if (CM_Get_DevNode_PropertyW(devInst, &DEVPKEY_NAME, &propertyType, (PBYTE) buffer, &propertySize, 0) == CR_SUCCESS)
ffStrbufSetWS(&device->name, buffer);
}
}
}
if (!device->name.length)
ffStrbufSetF(&device->name, "Unknown device %04X-%04X", (unsigned) rdi.hid.dwVendorId, (unsigned) rdi.hid.dwProductId);
}
return NULL;
}
+4 -4
View File
@@ -198,7 +198,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
char addressBuffer[32];
uint8_t* ptr = (uint8_t*) LLADDR((struct sockaddr_dl *)ifa->ifa_addr);
snprintf(addressBuffer, sizeof(addressBuffer), "%02x:%02x:%02x:%02x:%02x:%02x",
snprintf(addressBuffer, ARRAY_SIZE(addressBuffer), "%02x:%02x:%02x:%02x:%02x:%02x",
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]);
addNewIp(results, ifa->ifa_name, addressBuffer, -1, isDefaultRoute, flags, false);
}
@@ -210,7 +210,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
char addressBuffer[32];
uint8_t* ptr = ((struct sockaddr_ll *)ifa->ifa_addr)->sll_addr;
snprintf(addressBuffer, sizeof(addressBuffer), "%02x:%02x:%02x:%02x:%02x:%02x",
snprintf(addressBuffer, ARRAY_SIZE(addressBuffer), "%02x:%02x:%02x:%02x:%02x:%02x",
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]);
addNewIp(results, ifa->ifa_name, addressBuffer, -1, isDefaultRoute, flags, false);
}
@@ -231,7 +231,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
FF_LIST_FOR_EACH(FFLocalIpResult, iface, *results)
{
struct ifreq ifr;
strncpy(ifr.ifr_name, iface->name.chars, IFNAMSIZ - 1);
ffStrCopyN(ifr.ifr_name, iface->name.chars, IFNAMSIZ);
if (options->showType & FF_LOCALIP_TYPE_MTU_BIT)
{
@@ -248,7 +248,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
iface->speed = (edata.speed_hi << 16) | edata.speed; // ethtool_cmd_speed is not available on Android
#elif __FreeBSD__ || __APPLE__ || __OpenBSD__
struct ifmediareq ifmr = {};
strncpy(ifmr.ifm_name, iface->name.chars, IFNAMSIZ - 1);
ffStrCopyN(ifmr.ifm_name, iface->name.chars, IFNAMSIZ);
if (ioctl(sockfd, SIOCGIFMEDIA, &ifmr) == 0 && (IFM_TYPE(ifmr.ifm_active) & IFM_ETHER))
{
switch (IFM_SUBTYPE(ifmr.ifm_active))
+2 -2
View File
@@ -106,7 +106,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
bool newIp = true;
char name[128];
WideCharToMultiByte(CP_UTF8, 0, adapter->FriendlyName, -1, name, sizeof(name), NULL, NULL);
WideCharToMultiByte(CP_UTF8, 0, adapter->FriendlyName, -1, name, ARRAY_SIZE(name), NULL, NULL);
if (options->namePrefix.length && strncmp(name, options->namePrefix.chars, options->namePrefix.length) != 0)
continue;
@@ -114,7 +114,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
{
char addressBuffer[32];
uint8_t* ptr = adapter->PhysicalAddress;
snprintf(addressBuffer, sizeof(addressBuffer), "%02x:%02x:%02x:%02x:%02x:%02x",
snprintf(addressBuffer, ARRAY_SIZE(addressBuffer), "%02x:%02x:%02x:%02x:%02x:%02x",
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]);
addNewIp(results, name, addressBuffer, -1, newIp, isDefaultRoute);
newIp = false;
+1 -1
View File
@@ -67,7 +67,7 @@ static const char* getMedia(FFMediaResult* result)
if(result->playerId.length > 0)
{
char buf[128];
snprintf(buf, sizeof(buf), "name of app id \"%s\"", result->playerId.chars);
snprintf(buf, ARRAY_SIZE(buf), "name of app id \"%s\"", result->playerId.chars);
ffOsascript(buf, &result->player);
}
+2 -2
View File
@@ -7,9 +7,9 @@
const char* ffDetectMemory(FFMemoryResult* ram)
{
char buf[PROC_FILE_BUFFSIZ];
ssize_t nRead = ffReadFileData("/proc/meminfo", sizeof(buf) - 1, buf);
ssize_t nRead = ffReadFileData("/proc/meminfo", ARRAY_SIZE(buf) - 1, buf);
if(nRead < 0)
return "ffReadFileData(\"/proc/meminfo\", sizeof(buf)-1, buf)";
return "ffReadFileData(\"/proc/meminfo\", ARRAY_SIZE(buf)-1, buf)";
buf[nRead] = '\0';
uint64_t memTotal = 0,
+1 -1
View File
@@ -1,6 +1,6 @@
#include "memory.h"
const char* ffDetectMemory(FFMemoryResult* ram)
const char* ffDetectMemory(FF_MAYBE_UNUSED FFMemoryResult* ram)
{
return "Not supported on this platform";
}
+7 -10
View File
@@ -1,20 +1,17 @@
#include "memory.h"
#include "common/sysctl.h"
#include <sys/vmmeter.h>
#include <sys/param.h>
const char* ffDetectMemory(FFMemoryResult* ram)
{
size_t length = sizeof(ram->bytesTotal);
if (sysctl((int[]){ CTL_HW, HW_PHYSMEM }, 2, &ram->bytesTotal, &length, NULL, 0) < 0)
return "Failed to read hw.physmem";
struct uvmexp buf;
size_t length = sizeof(buf);
if (sysctl((int[]){ CTL_VM, VM_UVMEXP }, 2, &buf, &length, NULL, 0) < 0)
return "sysctl(CTL_VM, VM_UVMEXP) failed";
struct vmtotal vmtotal;
length = sizeof(vmtotal);
if (sysctl((int[]) {CTL_VM, VM_METER}, 2, &vmtotal, &length, NULL, 0) < 0)
return "sysctl(VM_METER) failed";
ram->bytesUsed = ram->bytesTotal - vmtotal.t_free * instance.state.platform.sysinfo.pageSize;
ram->bytesTotal = (uint64_t) buf.npages * instance.state.platform.sysinfo.pageSize;
ram->bytesUsed = ram->bytesTotal - (uint64_t) buf.free * instance.state.platform.sysinfo.pageSize;
return NULL;
}
+3 -27
View File
@@ -1,34 +1,10 @@
#include "memory.h"
#include <kstat.h>
static inline void kstatFreeWrap(kstat_ctl_t** pkc)
{
assert(pkc);
if (*pkc)
kstat_close(*pkc);
}
#include <unistd.h>
const char* ffDetectMemory(FFMemoryResult* ram)
{
__attribute__((__cleanup__(kstatFreeWrap))) kstat_ctl_t* kc = kstat_open();
if (!kc)
return "kstat_open() failed";
kstat_t* ks = kstat_lookup(kc, "unix", -1, "system_pages");
if (!ks)
return "kstat_lookup() failed";
if (kstat_read(kc, ks, NULL) < 0)
return "kstat_read() failed";
{
kstat_named_t* kn = kstat_data_lookup(ks, "pagestotal");
ram->bytesTotal = kn->value.ui64 * instance.state.platform.sysinfo.pageSize;
}
{
kstat_named_t* kn = kstat_data_lookup(ks, "pagesfree");
ram->bytesUsed = ram->bytesTotal - kn->value.ui64 * instance.state.platform.sysinfo.pageSize;
}
ram->bytesTotal = sysconf(_SC_PHYS_PAGES) * instance.state.platform.sysinfo.pageSize;
ram->bytesUsed = ram->bytesTotal - sysconf(_SC_AVPHYS_PAGES) * instance.state.platform.sysinfo.pageSize;
return NULL;
}
+9
View File
@@ -0,0 +1,9 @@
#include "fastfetch.h"
typedef struct FFMouseDevice
{
FFstrbuf serial;
FFstrbuf name;
} FFMouseDevice;
const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */);
+42
View File
@@ -0,0 +1,42 @@
#include "mouse.h"
#include "util/apple/cf_helpers.h"
#include "util/mallocHelper.h"
#include <IOKit/IOKitLib.h>
#include <IOKit/hid/IOHIDLib.h>
static void enumSet(IOHIDDeviceRef value, FFlist* results)
{
FFMouseDevice* device = (FFMouseDevice*) ffListAdd(results);
ffStrbufInit(&device->serial);
ffStrbufInit(&device->name);
CFStringRef product = IOHIDDeviceGetProperty(value, CFSTR(kIOHIDProductKey));
ffCfStrGetString(product, &device->name);
CFStringRef serialNumber = IOHIDDeviceGetProperty(value, CFSTR(kIOHIDSerialNumberKey));
ffCfStrGetString(serialNumber, &device->serial);
}
const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */)
{
IOHIDManagerRef FF_CFTYPE_AUTO_RELEASE manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (IOHIDManagerOpen(manager, kIOHIDOptionsTypeNone) != kIOReturnSuccess)
return "IOHIDManagerOpen() failed";
CFDictionaryRef FF_CFTYPE_AUTO_RELEASE matching1 = CFDictionaryCreate(kCFAllocatorDefault, (const void **)(CFStringRef[]){
CFSTR(kIOHIDDeviceUsagePageKey),
CFSTR(kIOHIDDeviceUsageKey)
}, (const void **)(CFNumberRef[]){
ffCfCreateInt(kHIDPage_GenericDesktop),
ffCfCreateInt(kHIDUsage_GD_Mouse)
}, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
IOHIDManagerSetDeviceMatching(manager, matching1);
CFSetRef FF_CFTYPE_AUTO_RELEASE set = IOHIDManagerCopyDevices(manager);
if (set)
CFSetApplyFunction(set, (CFSetApplierFunction) &enumSet, devices);
IOHIDManagerClose(manager, kIOHIDOptionsTypeNone);
return NULL;
}

Some files were not shown because too many files have changed in this diff Show More