Chore: IndentPPDirectives: BeforeHash [ci skip]

This commit is contained in:
李通洲
2026-04-15 16:16:46 +08:00
parent b63bd5b8c9
commit abc6c0593c
133 changed files with 1329 additions and 1329 deletions
+11 -11
View File
@@ -12,17 +12,17 @@
#include <paths.h>
#ifdef __APPLE__
# include <mach-o/dyld.h>
# include <sys/sysctl.h>
#include <mach-o/dyld.h>
#include <sys/sysctl.h>
#elif defined(__FreeBSD__) || defined(__NetBSD__)
# include <sys/sysctl.h>
#include <sys/sysctl.h>
#elif defined(__OpenBSD__)
# include <sys/sysctl.h>
# include <kvm.h>
# include "common/path.h"
#include <sys/sysctl.h>
#include <kvm.h>
#include "common/path.h"
#elif defined(__HAIKU__)
# include <image.h>
# include <OS.h>
#include <image.h>
#include <OS.h>
#endif
static void getExePath(FFPlatform* platform) {
@@ -43,15 +43,15 @@ static void getExePath(FFPlatform* platform) {
size_t exePathLen = sizeof(exePath);
if (sysctl(
(int[]) { CTL_KERN,
# ifdef __FreeBSD__
#ifdef __FreeBSD__
KERN_PROC,
KERN_PROC_PATHNAME,
(pid_t) platform->pid
# else
#else
KERN_PROC_ARGS,
(pid_t) platform->pid,
KERN_PROC_PATHNAME
# endif
#endif
},
4,
exePath,
+5 -5
View File
@@ -2,12 +2,12 @@
#if defined(FF_HAVE_ELF) || defined(__sun) || (defined(__FreeBSD__) && !defined(__DragonFly__)) || defined(__OpenBSD__) || defined(__NetBSD__)
# include "common/io.h"
# include "common/library.h"
# include "common/stringUtils.h"
#include "common/io.h"
#include "common/library.h"
#include "common/stringUtils.h"
# include <libelf.h> // #1254
# include <fcntl.h>
#include <libelf.h> // #1254
#include <fcntl.h>
/**
* Structure to hold dynamically loaded libelf function pointers
+2 -2
View File
@@ -2,8 +2,8 @@
#ifdef FF_HAVE_DBUS
# include "common/thread.h"
# include "common/stringUtils.h"
#include "common/thread.h"
#include "common/stringUtils.h"
static bool loadLibSymbols(FFDBusLibrary* lib) {
FF_LIBRARY_LOAD(dbus, false, "libdbus-1" FF_LIBRARY_EXTENSION, 4);
+3 -3
View File
@@ -11,10 +11,10 @@
#include <unistd.h>
#include <locale.h>
#ifdef _WIN32
# include <windows.h>
# include "common/windows/unicode.h"
#include <windows.h>
#include "common/windows/unicode.h"
#else
# include <signal.h>
#include <signal.h>
#endif
FFinstance instance; // Global singleton
+8 -8
View File
@@ -8,15 +8,15 @@
#include <dirent.h>
#include <errno.h>
#ifndef __APPLE__
# include <poll.h>
#include <poll.h>
#else
# include <sys/select.h>
#include <sys/select.h>
#endif
#if FF_HAVE_WORDEXP
# include <wordexp.h>
#include <wordexp.h>
#else
# include <glob.h>
#include <glob.h>
#endif
static void createSubfolders(const char* fileName) {
@@ -112,12 +112,12 @@ bool ffPathExpandEnv(const char* in, FFstrbuf* out) {
glob_t gb;
if (glob(in, GLOB_NOSORT
# ifdef GLOB_TILDE
#ifdef GLOB_TILDE
| GLOB_TILDE
# endif
# ifdef GLOB_BRACE
#endif
#ifdef GLOB_BRACE
| GLOB_BRACE
# endif
#endif
,
NULL,
&gb) != 0)
+21 -21
View File
@@ -2,35 +2,35 @@
#include "common/library.h"
#if _WIN32
# include "common/debug.h"
# include "common/windows/nt.h"
# include <errno.h>
# include <ntstatus.h>
#include "common/debug.h"
#include "common/windows/nt.h"
#include <errno.h>
#include <ntstatus.h>
#endif
#ifndef FF_DISABLE_DLOPEN
# include <stdarg.h>
#include <stdarg.h>
// Clang doesn't define __SANITIZE_ADDRESS__ but defines __has_feature(address_sanitizer)
# if !defined(__SANITIZE_ADDRESS__) && defined(__has_feature)
# if __has_feature(address_sanitizer)
# define __SANITIZE_ADDRESS__
# endif
# endif
// Clang doesn't define __SANITIZE_ADDRESS__ but defines __has_feature(address_sanitizer)
#if !defined(__SANITIZE_ADDRESS__) && defined(__has_feature)
#if __has_feature(address_sanitizer)
#define __SANITIZE_ADDRESS__
#endif
#endif
# ifndef FF_DLOPEN_FLAGS
# ifdef __SANITIZE_ADDRESS__
# define FF_DLOPEN_FLAGS RTLD_LAZY | RTLD_NODELETE
# else
# define FF_DLOPEN_FLAGS RTLD_LAZY
# endif
# endif
#ifndef FF_DLOPEN_FLAGS
#ifdef __SANITIZE_ADDRESS__
#define FF_DLOPEN_FLAGS RTLD_LAZY | RTLD_NODELETE
#else
#define FF_DLOPEN_FLAGS RTLD_LAZY
#endif
#endif
static void* libraryLoad(const char* path, int maxVersion) {
void* result = dlopen(path, FF_DLOPEN_FLAGS);
# ifdef _WIN32
#ifdef _WIN32
// libX.dll.1 never exists on Windows, while libX-1.dll may exist
FF_UNUSED(maxVersion)
@@ -48,7 +48,7 @@ static void* libraryLoad(const char* path, int maxVersion) {
strcpy(mempcpy(absPath, instance.state.platform.exePath.chars, pathLen + 1), path);
return dlopen(absPath, FF_DLOPEN_FLAGS);
# else
#else
if (result != NULL || maxVersion < 0) {
return result;
@@ -70,7 +70,7 @@ static void* libraryLoad(const char* path, int maxVersion) {
ffStrbufSubstrBefore(&pathbuf, originalLength);
}
# endif
#endif
return result;
}
+2 -2
View File
@@ -1,8 +1,8 @@
#include "common/netif.h"
#ifndef _WIN32
# include <net/if.h>
# include <netinet/in.h>
#include <net/if.h>
#include <netinet/in.h>
#endif
const FFNetifDefaultRouteResult* ffNetifGetDefaultRouteV4(void) {
+5 -5
View File
@@ -11,13 +11,13 @@
#define ROUNDUP2(a, n) ((a) > 0 ? (1 + (((a) - 1U) | ((n) - 1))) : (n))
#if __APPLE__
// https://github.com/apple-oss-distributions/network_cmds/blob/8f38231438e6a4d16ef8015e97e12c2c05105644/rtsol.tproj/if.c#L243
# define ROUNDUP(a) ROUNDUP2((a), sizeof(uint32_t))
// https://github.com/apple-oss-distributions/network_cmds/blob/8f38231438e6a4d16ef8015e97e12c2c05105644/rtsol.tproj/if.c#L243
#define ROUNDUP(a) ROUNDUP2((a), sizeof(uint32_t))
#elif __sun
// https://github.com/illumos/illumos-gate/blob/95b8c88950fa7b19af46bc63230137cf96b0bff7/usr/src/cmd/cmd-inet/usr.sbin/route.c#L339
# define ROUNDUP(a) ROUNDUP2((a), sizeof(long))
// https://github.com/illumos/illumos-gate/blob/95b8c88950fa7b19af46bc63230137cf96b0bff7/usr/src/cmd/cmd-inet/usr.sbin/route.c#L339
#define ROUNDUP(a) ROUNDUP2((a), sizeof(long))
#else
# error unknown platform
#error unknown platform
#endif
static struct sockaddr*
+9 -9
View File
@@ -12,19 +12,19 @@
#define ROUNDUP2(a, n) ((a) > 0 ? (1 + (((a) - 1U) | ((n) - 1))) : (n))
#if __DragonFly__
// https://github.com/DragonFlyBSD/DragonFlyBSD/blob/cf0aa2f1e47a3f0a6055fe427563cb3f3e627064/sys/net/route.h#L315C9-L315C19
# define ROUNDUP(a) ROUNDUP2((a), sizeof(long))
// https://github.com/DragonFlyBSD/DragonFlyBSD/blob/cf0aa2f1e47a3f0a6055fe427563cb3f3e627064/sys/net/route.h#L315C9-L315C19
#define ROUNDUP(a) ROUNDUP2((a), sizeof(long))
#elif __FreeBSD__
// https://github.com/freebsd/freebsd-src/blob/e4c0ecba44b20ebb2e4d80978c2cb6d16b730cb9/sys/net/route.h#L368C9-L368C16
# define ROUNDUP(a) ROUNDUP2((a), sizeof(long))
// https://github.com/freebsd/freebsd-src/blob/e4c0ecba44b20ebb2e4d80978c2cb6d16b730cb9/sys/net/route.h#L368C9-L368C16
#define ROUNDUP(a) ROUNDUP2((a), sizeof(long))
#elif __NetBSD__
// https://github.com/NetBSD/src/blob/29beb637d057520c0ed37ac2cde966f7cc0cadf4/sys/net/route.h#L330
# define ROUNDUP(a) ROUNDUP2((a), sizeof(uint64_t))
// https://github.com/NetBSD/src/blob/29beb637d057520c0ed37ac2cde966f7cc0cadf4/sys/net/route.h#L330
#define ROUNDUP(a) ROUNDUP2((a), sizeof(uint64_t))
#elif __OpenBSD__
// https://github.com/openbsd/src/blob/ca647cfa4ec3ccb8360714bc0ebc32a394f7fb6a/regress/sys/netinet/bindconnect/bindconnect.c#L250
# define ROUNDUP(a) ROUNDUP2((a), sizeof(long))
// https://github.com/openbsd/src/blob/ca647cfa4ec3ccb8360714bc0ebc32a394f7fb6a/regress/sys/netinet/bindconnect/bindconnect.c#L250
#define ROUNDUP(a) ROUNDUP2((a), sizeof(long))
#else
# error unknown platform
#error unknown platform
#endif
static struct sockaddr*
+4 -4
View File
@@ -5,7 +5,7 @@
#include "common/debug.h"
#ifdef FF_HAVE_ZLIB
# include <zlib.h>
#include <zlib.h>
struct FFZlibLibrary {
FF_LIBRARY_SYMBOL(inflateInit2_)
@@ -19,11 +19,11 @@ const char* ffNetworkingLoadZlibLibrary(void) {
if (!zlibData.inited) {
zlibData.inited = true;
FF_LIBRARY_LOAD_MESSAGE(zlib,
# ifdef _WIN32
#ifdef _WIN32
"zlib1"
# else
#else
"libz"
# endif
#endif
FF_LIBRARY_EXTENSION,
2)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(zlib, zlibData, inflateInit2_)
+29 -29
View File
@@ -20,56 +20,56 @@ static const char* tryNonThreadingFastPath(FFNetworkingState* state) {
#if defined(TCP_FASTOPEN) || __APPLE__
if (!state->tfo) {
# if __linux__ || __GNU__
#if __linux__ || __GNU__
// Linux doesn't support sendto() on unconnected sockets
FF_DEBUG("TCP Fast Open disabled, skipping");
return "TCP Fast Open disabled";
# endif
#endif
} else {
FF_DEBUG("Attempting to use TCP Fast Open to connect");
# ifndef __APPLE__ // On macOS, TCP_FASTOPEN doesn't seem to be needed
#ifndef __APPLE__ // On macOS, TCP_FASTOPEN doesn't seem to be needed
// Set TCP Fast Open
int flag = 1;
if (setsockopt(state->sockfd, IPPROTO_TCP,
# ifdef __APPLE__
#ifdef __APPLE__
// https://github.com/rust-lang/libc/pull/3135
0x218 // TCP_FASTOPEN_FORCE_ENABLE
# else
#else
TCP_FASTOPEN
# endif
#endif
,
&flag,
sizeof(flag)) != 0) {
FF_DEBUG("Failed to set TCP_FASTOPEN option: %s", strerror(errno));
return "setsockopt(TCP_FASTOPEN) failed";
} else {
# if __linux__ || __GNU__
#if __linux__ || __GNU__
FF_DEBUG("Successfully set TCP_FASTOPEN option, queue length: %d", flag);
# elif defined(__APPLE__)
#elif defined(__APPLE__)
FF_DEBUG("Successfully set TCP_FASTOPEN_FORCE_ENABLE option");
# else
#else
FF_DEBUG("Successfully set TCP_FASTOPEN option");
# endif
#endif
}
# endif
#endif
}
# ifndef __APPLE__
#ifndef __APPLE__
FF_DEBUG("Using sendto() + MSG_DONTWAIT to send %u bytes of data", state->command.length);
ssize_t sent = sendto(state->sockfd,
state->command.chars,
state->command.length,
# ifdef MSG_FASTOPEN
#ifdef MSG_FASTOPEN
MSG_FASTOPEN |
# endif
# ifdef MSG_NOSIGNAL
#endif
#ifdef MSG_NOSIGNAL
MSG_NOSIGNAL |
# endif
#endif
MSG_DONTWAIT,
state->addr->ai_addr,
state->addr->ai_addrlen);
# else
#else
if (fcntl(state->sockfd, F_SETFL, O_NONBLOCK) == -1) {
FF_DEBUG("fcntl(F_SETFL) failed: %s", strerror(errno));
return "fcntl(F_SETFL) failed";
@@ -97,20 +97,20 @@ static const char* tryNonThreadingFastPath(FFNetworkingState* state) {
FF_DEBUG("fcntl(F_SETFL) failed: %s", strerror(errno));
return "fcntl(F_SETFL) failed";
}
# endif
#endif
if (sent > 0 || (errno == EAGAIN || errno == EWOULDBLOCK
# ifdef __APPLE__
#ifdef __APPLE__
// On macOS EINPROGRESS means the connection cannot be completed immediately
// On Linux, it means the TFO cookie is not available locally
|| errno == EINPROGRESS
# endif
#endif
)) {
FF_DEBUG(
# ifdef __APPLE__
#ifdef __APPLE__
"connectx()"
# else
#else
"sendto()"
# endif
#endif
" %s (sent=%zd, %s)",
errno == 0 ? "succeeded" : "was in progress",
sent,
@@ -122,18 +122,18 @@ static const char* tryNonThreadingFastPath(FFNetworkingState* state) {
}
FF_DEBUG(
# ifdef __APPLE__
#ifdef __APPLE__
"connectx()"
# else
#else
"sendto()"
# endif
#endif
" failed: %s",
strerror(errno));
# ifdef __APPLE__
#ifdef __APPLE__
return "connectx() failed";
# else
#else
return "sendto() failed";
# endif
#endif
#else
FF_UNUSED(state);
return "TFO support is not available";
+3 -3
View File
@@ -4,8 +4,8 @@
#include <ctype.h>
#ifdef _WIN32
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"
#endif
void ffParseSemver(FFstrbuf* buffer, const FFstrbuf* major, const FFstrbuf* minor, const FFstrbuf* patch) {
@@ -124,5 +124,5 @@ void ffParseGTK(FFstrbuf* buffer, const FFstrbuf* gtk2, const FFstrbuf* gtk3, co
}
#ifdef _WIN32
# pragma GCC diagnostic pop
#pragma GCC diagnostic pop
#endif
+15 -15
View File
@@ -9,17 +9,17 @@ const char* ffFindExecutableInPath(const char* name, FFstrbuf* result) {
return "$PATH not set";
}
# ifdef _WIN32
#ifdef _WIN32
const bool appendExe = !ffStrEndsWithIgnCase(name, ".exe");
# endif
#endif
for (char* token = path; *token; path = token + 1) {
token = strchr(path,
# ifdef _WIN32
#ifdef _WIN32
';'
# else
#else
':'
# endif
#endif
);
if (!token) {
token = path + strlen(path);
@@ -27,25 +27,25 @@ const char* ffFindExecutableInPath(const char* name, FFstrbuf* result) {
ffStrbufSetNS(result, (uint32_t) (token - path), path);
ffStrbufEnsureEndsWithC(result,
# ifdef _WIN32
#ifdef _WIN32
'\\'
# else
#else
'/'
# endif
#endif
);
ffStrbufAppendS(result, name);
# ifdef _WIN32
#ifdef _WIN32
if (appendExe) {
ffStrbufAppendS(result, ".exe");
}
if (!ffPathExists(result->chars, FF_PATHTYPE_FILE)) {
continue;
}
# else
#else
if (access(result->chars, X_OK) != 0) {
continue;
}
# endif
#endif
return NULL;
}
@@ -53,10 +53,10 @@ const char* ffFindExecutableInPath(const char* name, FFstrbuf* result) {
return "Executable not found";
}
#else
# include <windows.h>
# include <winioctl.h>
# include <errno.h>
# include <stdalign.h>
#include <windows.h>
#include <winioctl.h>
#include <errno.h>
#include <stdalign.h>
const char* ffFindExecutableInPath(const char* name, FFstrbuf* result) {
char buffer[MAX_PATH + 1];
+33 -33
View File
@@ -13,28 +13,28 @@
#include <sys/wait.h>
#if !(__ANDROID__ || __OpenBSD__)
# include <spawn.h>
#include <spawn.h>
#endif
#if defined(__FreeBSD__) || defined(__APPLE__)
# include <sys/types.h>
# include <sys/user.h>
# include <sys/sysctl.h>
#include <sys/types.h>
#include <sys/user.h>
#include <sys/sysctl.h>
#endif
#if defined(__APPLE__)
# include <libproc.h>
#include <libproc.h>
#elif defined(__sun)
# include <procfs.h>
#include <procfs.h>
#elif defined(__OpenBSD__)
# include <sys/param.h>
# include <sys/sysctl.h>
# include <kvm.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <kvm.h>
#elif defined(__NetBSD__)
# include <sys/types.h>
# include <sys/sysctl.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#elif defined(__HAIKU__)
# include <OS.h>
# include <image.h>
#include <OS.h>
#include <image.h>
#endif
#ifndef environ
@@ -234,9 +234,9 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
// For interpreters, try to find the real script path in the arguments
if (ffStrStartsWith(name, "python")
# ifndef __ANDROID__
#ifndef __ANDROID__
|| ffStrEquals(name, "guile") // for shepherd
# endif
#endif
) {
// `cmdline` always ends with a trailing '\0', and ffReadFileBuffer appends another \0
// So `exe->chars` is always double '\0' terminated
@@ -341,15 +341,15 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
static_assert(ARG_MAX > PATH_MAX, "");
if (exePath && sysctl((int[]) { CTL_KERN,
# if __FreeBSD__
#if __FreeBSD__
KERN_PROC,
KERN_PROC_PATHNAME,
pid
# else
#else
KERN_PROC_ARGS,
pid,
KERN_PROC_PATHNAME
# endif
#endif
},
4,
args,
@@ -361,15 +361,15 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
size = ARG_MAX;
if (sysctl(
(int[]) { CTL_KERN,
# if __FreeBSD__
#if __FreeBSD__
KERN_PROC,
KERN_PROC_ARGS,
pid
# else
#else
KERN_PROC_ARGS,
pid,
KERN_PROC_ARGV,
# endif
#endif
},
4,
args,
@@ -476,9 +476,9 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i
#if defined(__linux__) || defined(__GNU__)
char procFilePath[64];
# if __linux__
#if __linux__
if (ppid || tty)
# endif
#endif
{
snprintf(procFilePath, sizeof(procFilePath), "/proc/%d/stat", (int) pid);
char buf[PROC_FILE_BUFFSIZ];
@@ -509,9 +509,9 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i
pState = end + 2; // skip ") "
}
# if !__linux__
#if !__linux__
if (ppid || tty)
# endif
#endif
{
int ppid_, tty_;
if (sscanf(pState + 2, "%d %*d %*d %d", &ppid_, &tty_) < 2) {
@@ -526,7 +526,7 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i
}
}
}
# if __linux__
#if __linux__
else {
snprintf(procFilePath, sizeof(procFilePath), "/proc/%d/comm", (int) pid);
ssize_t nRead = ffReadFileBuffer(procFilePath, name);
@@ -535,7 +535,7 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i
}
ffStrbufTrimRightSpace(name);
}
# endif
#endif
#elif defined(__APPLE__)
@@ -558,12 +558,12 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i
#elif defined(__FreeBSD__)
# ifdef __DragonFly__
# define ki_comm kp_comm
# define ki_ppid kp_ppid
# define ki_tdev kp_tdev
# define ki_flag kp_flags
# endif
#ifdef __DragonFly__
#define ki_comm kp_comm
#define ki_ppid kp_ppid
#define ki_tdev kp_tdev
#define ki_flag kp_flags
#endif
struct kinfo_proc proc;
size_t size = sizeof(proc);
+1 -1
View File
@@ -6,7 +6,7 @@
#include <stdlib.h>
#include <ctype.h>
#ifdef _WIN32
# include "common/windows/getline.h"
#include "common/windows/getline.h"
#endif
bool ffParsePropLinePointer(const char** line, const char* start, FFstrbuf* buffer) {
+7 -7
View File
@@ -7,7 +7,7 @@
#include <string.h>
#ifdef FF_HAVE_GIO
# include <gio/gio.h>
#include <gio/gio.h>
typedef struct GVariantGetters {
FF_LIBRARY_SYMBOL(g_variant_dup_string)
@@ -124,7 +124,7 @@ FFvariant ffSettingsGetGSettings(const char* schemaName, const char* path, const
#endif // FF_HAVE_GIO
#ifdef FF_HAVE_DCONF
# include <dconf.h>
#include <dconf.h>
typedef struct DConfData {
FF_LIBRARY_SYMBOL(dconf_client_read_full)
@@ -200,7 +200,7 @@ FFvariant ffSettingsGetGnome(const char* dconfKey, const char* gsettingsSchemaNa
}
#ifdef FF_HAVE_DBUS
# include "common/dbus.h"
#include "common/dbus.h"
FFvariant ffSettingsGetXFConf(const char* channelName, const char* propertyName, FFvarianttype type) {
FF_DBUS_AUTO_DESTROY_DATA FFDBusData dbus = {};
@@ -248,7 +248,7 @@ FFvariant ffSettingsGetXFConf(const char* channelName, const char* propertyName,
return FF_VARIANT_NULL;
}
# define FF_DBUS_ITER_CONTINUE(dbus, iterator) \
#define FF_DBUS_ITER_CONTINUE(dbus, iterator) \
{ \
if (!(dbus).lib->ffdbus_message_iter_next(iterator)) \
break; \
@@ -334,7 +334,7 @@ FFvariant ffSettingsGetXFConfFirstMatch(const char* channelName, const char* pro
#endif // FF_HAVE_DBUS
#ifdef FF_HAVE_SQLITE3
# include <sqlite3.h>
#include <sqlite3.h>
typedef struct SQLiteData {
FF_LIBRARY_SYMBOL(sqlite3_open_v2)
@@ -454,7 +454,7 @@ bool ffSettingsGetSQLite3String(const char* dbPath, const char* query, FFstrbuf*
#endif // FF_HAVE_SQLITE3
#ifdef __ANDROID__
# include <sys/system_properties.h>
#include <sys/system_properties.h>
bool ffSettingsGetAndroidProperty(const char* propName, FFstrbuf* result) {
ffStrbufEnsureFree(result, PROP_VALUE_MAX);
int len = __system_property_get(propName, result->chars + result->length);
@@ -466,7 +466,7 @@ bool ffSettingsGetAndroidProperty(const char* propName, FFstrbuf* result) {
return true;
}
#elif defined(__FreeBSD__)
# include <kenv.h>
#include <kenv.h>
bool ffSettingsGetFreeBSDKenv(const char* propName, FFstrbuf* result) {
// https://wiki.ghostbsd.org/index.php/Kenv
ffStrbufEnsureFree(result, KENV_MVALLEN);
+41 -41
View File
@@ -141,21 +141,21 @@ static bool parseSmbiosTable(const uint8_t* data, uint32_t length) {
}
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) || defined(__HAIKU__) || defined(__OpenBSD__) || defined(__GNU__)
# include <fcntl.h>
# include <sys/stat.h>
# include <sys/types.h>
# include <sys/mman.h>
# include <stddef.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <stddef.h>
# ifdef __linux__
# include "common/properties.h"
# elif defined(__FreeBSD__)
# include "common/settings.h"
# elif defined(__NetBSD__)
# include "common/sysctl.h"
# endif
#ifdef __linux__
#include "common/properties.h"
#elif defined(__FreeBSD__)
#include "common/settings.h"
#elif defined(__NetBSD__)
#include "common/sysctl.h"
#endif
# ifdef __linux__
#ifdef __linux__
bool ffGetSmbiosValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer) {
// /sys/class/dmi/id/* are all pseudo-files with very small content
// so reading the whole file at once is efficient
@@ -186,10 +186,10 @@ bool ffGetSmbiosValue(const char* devicesPath, const char* classPath, FFstrbuf*
ffStrbufClear(buffer);
return false;
}
# endif
#endif
static bool readPhysicalMemory(int fd, off_t address, size_t length, void* buffer) {
# if !defined(__FreeBSD__) // Either causes kernel panic or returns EFAULT
#if !defined(__FreeBSD__) // Either causes kernel panic or returns EFAULT
// -1: unknown, 0: failed before (stop trying), 1: succeeded before
static int preadState = -1;
if (preadState != 0) {
@@ -208,7 +208,7 @@ static bool readPhysicalMemory(int fd, off_t address, size_t length, void* buffe
} else {
FF_DEBUG("Skipping pread due to cached failure; using mmap");
}
# endif
#endif
off_t alignedAddress = address & ~((off_t) instance.state.platform.sysinfo.pageSize - 1);
size_t pageOffset = (size_t) (address - alignedAddress);
@@ -270,11 +270,11 @@ typedef union FFSmbiosEntryPoint {
static bool fillTableBufferFallback(FFstrbuf* buffer) {
const char* devMem =
# if __HAIKU__
#if __HAIKU__
"/dev/misc/mem";
# else
#else
"/dev/mem"; // kern.securelevel must be -1
# endif
#endif
FF_DEBUG("Using physical memory searching implementation: %s", devMem);
uint32_t tableLength = 0;
@@ -355,7 +355,7 @@ static bool fillTableBufferFallback(FFstrbuf* buffer) {
return true;
}
# ifdef __OpenBSD__
#ifdef __OpenBSD__
static bool detectSmbiosTableLength(const uint8_t* data, uint32_t bufferLength, uint32_t* tableLength) {
const uint8_t* p = data;
const uint8_t* end = data + bufferLength;
@@ -500,26 +500,26 @@ static bool fillTableBufferPlatform(FFstrbuf* buffer) {
ffStrbufClear(buffer);
return false;
}
# else
#else
static bool fillTableBufferPlatform(FFstrbuf* buffer) {
# if __HAIKU__ && __GNU__
#if __HAIKU__ && __GNU__
return false;
# elif defined(__linux__)
#elif defined(__linux__)
FF_DEBUG("Using Linux implementation - trying /sys/firmware/dmi/tables/DMI");
if (!ffAppendFileBuffer("/sys/firmware/dmi/tables/DMI", buffer))
# else
#else
{
# if !defined(__sun) && !defined(__NetBSD__)
#if !defined(__sun) && !defined(__NetBSD__)
FF_DEBUG("Using memory-mapped implementation");
FF_STRBUF_AUTO_DESTROY strEntryAddress = ffStrbufCreate();
# ifdef __FreeBSD__
#ifdef __FreeBSD__
FF_DEBUG("Using FreeBSD kenv implementation");
if (!ffSettingsGetFreeBSDKenv("hint.smbios.0.mem", &strEntryAddress)) {
FF_DEBUG("Failed to get SMBIOS address from FreeBSD kenv");
return false; // non-UEFI systems
}
FF_DEBUG("Got SMBIOS address from kenv: %s", strEntryAddress.chars);
# elif defined(__linux__)
#elif defined(__linux__)
{
FF_DEBUG("Using Linux EFI systab implementation");
FF_STRBUF_AUTO_DESTROY systab = ffStrbufCreate();
@@ -534,7 +534,7 @@ static bool fillTableBufferPlatform(FFstrbuf* buffer) {
}
FF_DEBUG("Found SMBIOS entry in systab: %s", strEntryAddress.chars);
}
# endif
#endif
off_t entryAddress = (off_t) strtol(strEntryAddress.chars, NULL, 16);
if (entryAddress == 0) {
@@ -558,14 +558,14 @@ static bool fillTableBufferPlatform(FFstrbuf* buffer) {
return false;
}
FF_DEBUG("Successfully read SMBIOS entry point data");
# else
#else
// Sun or NetBSD
FF_DEBUG("Using %s specific implementation",
# ifdef __NetBSD__
#ifdef __NetBSD__
"NetBSD"
# else
#else
"SunOS"
# endif
#endif
);
FF_AUTO_CLOSE_FD int fd = open("/dev/smbios", O_RDONLY | O_CLOEXEC);
@@ -576,7 +576,7 @@ static bool fillTableBufferPlatform(FFstrbuf* buffer) {
FF_DEBUG("/dev/smbios opened successfully with fd=%d", fd);
FFSmbiosEntryPoint entryPoint;
# ifdef __NetBSD__
#ifdef __NetBSD__
off_t addr = (off_t) ffSysctlGetInt64("machdep.smbios", 0);
if (addr == 0) {
FF_DEBUG("Failed to get SMBIOS address from sysctl");
@@ -589,15 +589,15 @@ static bool fillTableBufferPlatform(FFstrbuf* buffer) {
return false;
}
FF_DEBUG("Successfully read SMBIOS entry point");
# else
#else
FF_DEBUG("Reading SMBIOS entry point from /dev/smbios");
if (ffReadFDData(fd, sizeof(entryPoint), &entryPoint) < 1) {
FF_DEBUG("Failed to read SMBIOS entry point: %s", strerror(errno));
return false;
}
FF_DEBUG("Successfully read SMBIOS entry point");
# endif
# endif
#endif
#endif
uint32_t tableLength = 0;
off_t tableAddress = 0;
@@ -649,11 +649,11 @@ static bool fillTableBufferPlatform(FFstrbuf* buffer) {
return false;
}
}
# endif
#endif
return true;
}
# endif
#endif
const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable() {
static FFstrbuf buffer;
@@ -684,9 +684,9 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable() {
return &smbiosTable;
}
#elif defined(_WIN32)
# include "common/windows/nt.h"
#include "common/windows/nt.h"
# pragma GCC diagnostic ignored "-Wmultichar"
#pragma GCC diagnostic ignored "-Wmultichar"
typedef struct FFRawSmbiosData {
uint8_t Used20CallingMethod;
@@ -754,7 +754,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable() {
return &smbiosTable;
}
#elif defined(__APPLE__)
# include "common/apple/cf_helpers.h"
#include "common/apple/cf_helpers.h"
const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable() {
static CFDataRef smbiosDataBuffer;
+3 -3
View File
@@ -5,8 +5,8 @@
char ffTimeInternalBuffer[64]; // Reduce memory usage and prevent redundant allocations
#ifdef _WIN32
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"
#endif
const char* ffTimeToFullStr(uint64_t msec) {
@@ -45,7 +45,7 @@ const char* ffTimeToTimeStr(uint64_t msec) {
}
#ifdef _WIN32
# pragma GCC diagnostic pop
#pragma GCC diagnostic pop
#endif
FFTimeGetAgeResult ffTimeGetAge(uint64_t birthMs, uint64_t nowMs) {