Global: replaces NULL to nullptr

This commit is contained in:
李通洲
2026-07-10 18:08:04 +08:00
parent 873454191f
commit ba18705d2e
387 changed files with 2411 additions and 2411 deletions
+38 -38
View File
@@ -25,7 +25,7 @@
static bool getFileVersion(const FFstrbuf* exePath, const wchar_t* stringName, FFstrbuf* version) {
wchar_t exePathW[PATH_MAX + 1];
if (!NT_SUCCESS(RtlUTF8ToUnicodeN(exePathW, (ULONG) sizeof(exePathW), NULL, exePath->chars, (ULONG) exePath->length + 1))) {
if (!NT_SUCCESS(RtlUTF8ToUnicodeN(exePathW, (ULONG) sizeof(exePathW), nullptr, exePath->chars, (ULONG) exePath->length + 1))) {
return false;
}
return ffGetFileVersion(exePathW, stringName, version);
@@ -38,7 +38,7 @@ static bool getFileVersion(const FFstrbuf* exePath, const wchar_t* stringName, F
#endif
static bool getExeVersionRaw(FFstrbuf* exe, FFstrbuf* version) {
return ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "--version", NULL }) == NULL;
return ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "--version", nullptr }) == nullptr;
}
static bool getExeVersionGeneral(FFstrbuf* exe, FFstrbuf* version) {
@@ -105,7 +105,7 @@ static bool getShellVersionPwsh(FFstrbuf* exe, FFstrbuf* version) {
}
#ifdef _WIN32
if (getFileVersion(exe, NULL, version)) {
if (getFileVersion(exe, nullptr, version)) {
ffStrbufSubstrBeforeLastC(version, '.');
return true;
}
@@ -120,14 +120,14 @@ static bool getShellVersionPwsh(FFstrbuf* exe, FFstrbuf* version) {
}
static bool getShellVersionKsh(FFstrbuf* exe, FFstrbuf* version) {
if (ffProcessAppendStdErr(version, (char* const[]) { exe->chars, "--version", NULL }) == NULL && ffStrbufSubstrAfterFirstS(version, " (AT&T Research) ")) {
if (ffProcessAppendStdErr(version, (char* const[]) { exe->chars, "--version", nullptr }) == nullptr && ffStrbufSubstrAfterFirstS(version, " (AT&T Research) ")) {
// version sh (AT&T Research) 93u+ 2012-08-01
ffStrbufSubstrBeforeFirstC(version, ' ');
return true;
}
ffStrbufClear(version);
if (ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "-c", "echo $KSH_VERSION", NULL }) == NULL && ffStrbufSubstrAfterFirstS(version, " KSH ")) {
if (ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "-c", "echo $KSH_VERSION", nullptr }) == nullptr && ffStrbufSubstrAfterFirstS(version, " KSH ")) {
// OKSH: @(#)PD KSH v5.2.14 99/07/13.2
// MKSH: @(#)MIRBSD KSH R59 2025/04/26 +Debian
// $OKSH_VERSION doesn't exist on OpenBSD
@@ -141,7 +141,7 @@ static bool getShellVersionKsh(FFstrbuf* exe, FFstrbuf* version) {
static bool getShellVersionOksh(FFstrbuf* exe, FFstrbuf* version) {
// Homebrew version
if (ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "-c", "echo $OKSH_VERSION", NULL }) != NULL) {
if (ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "-c", "echo $OKSH_VERSION", nullptr }) != nullptr) {
return false;
}
@@ -151,7 +151,7 @@ static bool getShellVersionOksh(FFstrbuf* exe, FFstrbuf* version) {
}
static bool getShellVersionOils(FFstrbuf* exe, FFstrbuf* version) {
if (ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "--version", NULL }) != NULL) {
if (ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "--version", nullptr }) != nullptr) {
return false;
}
@@ -189,9 +189,9 @@ static bool getShellVersionAsh(FFstrbuf* exe, FFstrbuf* version) {
ffBinaryExtractStrings(exe->chars, extractBusyboxVersion, version, (uint32_t) strlen("BusyBox v0.0.0"));
const char* error = ffStrbufEndsWithS(exe, "busybox")
? ffProcessAppendStdErr(version, (char* const[]) { exe->chars, "ash", "--help", NULL })
: ffProcessAppendStdErr(version, (char* const[]) { exe->chars, "--help", NULL });
if (error != NULL) {
? ffProcessAppendStdErr(version, (char* const[]) { exe->chars, "ash", "--help", nullptr })
: ffProcessAppendStdErr(version, (char* const[]) { exe->chars, "--help", nullptr });
if (error != nullptr) {
return false;
}
@@ -209,7 +209,7 @@ static bool getShellVersionXonsh(FF_A_UNUSED FFstrbuf* exe, FFstrbuf* version) {
}
// exe is python here
if (ffProcessAppendStdErr(version, (char* const[]) { "xonsh", "--version", NULL }) != NULL) {
if (ffProcessAppendStdErr(version, (char* const[]) { "xonsh", "--version", nullptr }) != nullptr) {
return false;
}
@@ -249,13 +249,13 @@ static bool getShellVersionWinPowerShell(FFstrbuf* exe, FFstrbuf* version) {
return true;
}
FF_AUTO_CLOSE_FD HANDLE hKey = NULL;
if (ffRegOpenSubkeyForRead(ffRegGetRootKeyHandle(HKEY_LOCAL_MACHINE), L"SOFTWARE\\Microsoft\\PowerShell\\3\\PowerShellEngine", &hKey, NULL) && ffRegReadStrbuf(hKey, L"PowerShellVersion", version, NULL)) {
FF_AUTO_CLOSE_FD HANDLE hKey = nullptr;
if (ffRegOpenSubkeyForRead(ffRegGetRootKeyHandle(HKEY_LOCAL_MACHINE), L"SOFTWARE\\Microsoft\\PowerShell\\3\\PowerShellEngine", &hKey, nullptr) && ffRegReadStrbuf(hKey, L"PowerShellVersion", version, nullptr)) {
return true;
}
// Extremely slow
return ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "-NoLogo", "-NoProfile", "-Command", "$PSVersionTable.PSVersion.ToString()", NULL }) == NULL;
return ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "-NoLogo", "-NoProfile", "-Command", "$PSVersionTable.PSVersion.ToString()", nullptr }) == nullptr;
}
#endif
@@ -309,7 +309,7 @@ bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version)
return getShellVersionWinPowerShell(exe, version);
}
return getFileVersion(exe, NULL, version);
return getFileVersion(exe, nullptr, version);
#endif
return false;
@@ -341,7 +341,7 @@ FF_A_UNUSED static bool getTerminalVersionGnome(FFstrbuf* exe, FFstrbuf* version
}
}
if (ffProcessAppendStdOut(version, (char* const[]) { "gnome-terminal", "--version", NULL })) {
if (ffProcessAppendStdOut(version, (char* const[]) { "gnome-terminal", "--version", nullptr })) {
return false;
}
@@ -363,7 +363,7 @@ FF_A_UNUSED static bool getTerminalVersionXfce4Terminal(FFstrbuf* exe, FFstrbuf*
}
FF_A_UNUSED static bool getTerminalVersionKgx(FFstrbuf* version) {
if (ffProcessAppendStdOut(version, (char* const[]) { "kgx", "--version", NULL })) {
if (ffProcessAppendStdOut(version, (char* const[]) { "kgx", "--version", nullptr })) {
return false;
}
@@ -377,7 +377,7 @@ FF_A_UNUSED static bool getTerminalVersionKonsole(FFstrbuf* exe, FFstrbuf* versi
const char* konsoleVersion = getenv("KONSOLE_VERSION");
if (konsoleVersion) {
// 221201
long major = strtol(konsoleVersion, NULL, 10);
long major = strtol(konsoleVersion, nullptr, 10);
if (major >= 0) {
long patch = major % 100;
major /= 100;
@@ -397,7 +397,7 @@ FF_A_UNUSED static bool getTerminalVersionKonsole(FFstrbuf* exe, FFstrbuf* versi
FF_A_UNUSED static bool getTerminalVersionFoot(FFstrbuf* exe, FFstrbuf* version) {
uint32_t major = 0, minor = 0, patch = 0;
if (ffGetTerminalResponse("\e[>c", 3, "\e[>1;%2u%2u%2u;0c", &major, &minor, &patch) == NULL) {
if (ffGetTerminalResponse("\e[>c", 3, "\e[>1;%2u%2u%2u;0c", &major, &minor, &patch) == nullptr) {
ffStrbufSetF(version, "%u.%u.%u", major, minor, patch);
return true;
}
@@ -441,7 +441,7 @@ FF_A_UNUSED static bool getTerminalVersionCockpit(FFstrbuf* exe, FFstrbuf* versi
FF_A_UNUSED static bool getTerminalVersionXterm(FFstrbuf* exe, FFstrbuf* version) {
ffStrbufSetS(version, getenv("XTERM_VERSION"));
if (!version->length) {
if (ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "-v", NULL })) {
if (ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "-v", nullptr })) {
return false;
}
}
@@ -453,7 +453,7 @@ FF_A_UNUSED static bool getTerminalVersionXterm(FFstrbuf* exe, FFstrbuf* version
}
FF_A_UNUSED static bool getTerminalVersionBlackbox(FFstrbuf* exe, FFstrbuf* version) {
if (ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "--version", NULL })) {
if (ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "--version", nullptr })) {
return false;
}
@@ -466,7 +466,7 @@ FF_A_UNUSED static bool getTerminalVersionBlackbox(FFstrbuf* exe, FFstrbuf* vers
FF_A_UNUSED static bool getTerminalVersionUrxvt(FF_A_UNUSED FFstrbuf* exe, FFstrbuf* version) {
if (ffProcessAppendStdErr(version, (char* const[]) { "urxvt", // Don't use exe because of urxvtd
"-invalid",
NULL })) {
nullptr })) {
return false;
}
@@ -479,7 +479,7 @@ FF_A_UNUSED static bool getTerminalVersionUrxvt(FF_A_UNUSED FFstrbuf* exe, FFstr
}
FF_A_UNUSED static bool getTerminalVersionSt(FF_A_UNUSED FFstrbuf* exe, FFstrbuf* version) {
if (ffProcessAppendStdErr(version, (char* const[]) { exe->chars, "-v", NULL })) {
if (ffProcessAppendStdErr(version, (char* const[]) { exe->chars, "-v", nullptr })) {
return false;
}
@@ -500,7 +500,7 @@ FF_A_UNUSED static bool getTerminalVersionLxterminal(FFstrbuf* exe, FFstrbuf* ve
FF_A_UNUSED static bool getTerminalVersionWeston(FF_A_UNUSED FFstrbuf* exe, FFstrbuf* version) {
// weston-terminal doesn't report a version, use weston version instead
if (ffProcessAppendStdOut(version, (char* const[]) { "weston", "--version", NULL })) {
if (ffProcessAppendStdOut(version, (char* const[]) { "weston", "--version", nullptr })) {
return false;
}
@@ -565,7 +565,7 @@ static bool getTerminalVersionScreen(FFstrbuf* exe, FFstrbuf* version) {
}
static bool getTerminalVersionTmux(FFstrbuf* exe, FFstrbuf* version) {
if (ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "-V", NULL }) != NULL) {
if (ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "-V", nullptr }) != nullptr) {
return false;
}
@@ -593,7 +593,7 @@ static bool getTerminalVersionZed(FFstrbuf* exe, FFstrbuf* version) {
#endif
);
if (ffProcessAppendStdOut(version, (char* const[]) { cli.chars, "--version", NULL }) != NULL) {
if (ffProcessAppendStdOut(version, (char* const[]) { cli.chars, "--version", nullptr }) != nullptr) {
return false;
}
@@ -621,7 +621,7 @@ static bool getTerminalVersionSshd(FFstrbuf* exe, FFstrbuf* version) {
FF_STRBUF_AUTO_DESTROY exePath = ffStrbufCreate();
if (ffIsAbsolutePath(exe->chars)) {
ffStrbufSet(&exePath, exe);
} else if (ffFindExecutableInPath("sshd", &exePath) != NULL) {
} else if (ffFindExecutableInPath("sshd", &exePath) != nullptr) {
return false;
}
@@ -630,7 +630,7 @@ static bool getTerminalVersionSshd(FFstrbuf* exe, FFstrbuf* version) {
return true;
}
if (ffProcessAppendStdOut(version, (char* const[]) { exePath.chars, "-V", NULL }) != NULL) {
if (ffProcessAppendStdOut(version, (char* const[]) { exePath.chars, "-V", nullptr }) != nullptr) {
return false;
}
@@ -669,7 +669,7 @@ static bool getTerminalVersionKitty(FFstrbuf* exe, FFstrbuf* version) {
}
}
#elif __APPLE__
if (ffGetAppNameAndVersion(exe->chars, NULL, version)) {
if (ffGetAppNameAndVersion(exe->chars, nullptr, version)) {
return true;
}
#endif
@@ -680,7 +680,7 @@ static bool getTerminalVersionKitty(FFstrbuf* exe, FFstrbuf* version) {
"\eP+q6b697474792d71756572792d76657273696f6e\e\\", // kitty-query-version
1,
"\eP1+r%*[^=]=%63[^\e]\e\\\\",
versionHex) == NULL) {
versionHex) == nullptr) {
// decode hex string
for (const char* p = versionHex; p[0] && p[1]; p += 2) {
unsigned value;
@@ -696,7 +696,7 @@ static bool getTerminalVersionKitty(FFstrbuf* exe, FFstrbuf* version) {
}
FF_A_UNUSED static bool getTerminalVersionPtyxis(FF_A_UNUSED FFstrbuf* exe, FFstrbuf* version) {
if (ffProcessAppendStdOut(version, (char* const[]) { "ptyxis", "--version", NULL }) != NULL) {
if (ffProcessAppendStdOut(version, (char* const[]) { "ptyxis", "--version", nullptr }) != nullptr) {
return false;
}
@@ -713,7 +713,7 @@ FF_A_UNUSED static bool getTerminalVersionTilix(FFstrbuf* exe, FFstrbuf* version
}
}
if (ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "--version", NULL }) != NULL) {
if (ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "--version", nullptr }) != nullptr) {
return false;
}
@@ -731,7 +731,7 @@ FF_A_UNUSED static bool getTerminalVersionTilix(FFstrbuf* exe, FFstrbuf* version
}
FF_A_UNUSED static bool getTerminalVersionSakura(FFstrbuf* exe, FFstrbuf* version) {
if (ffProcessAppendStdErr(version, (char* const[]) { exe->chars, "--version", NULL }) != NULL) { // sakura version is 3.8.8
if (ffProcessAppendStdErr(version, (char* const[]) { exe->chars, "--version", nullptr }) != nullptr) { // sakura version is 3.8.8
return false;
}
@@ -740,7 +740,7 @@ FF_A_UNUSED static bool getTerminalVersionSakura(FFstrbuf* exe, FFstrbuf* versio
}
FF_A_UNUSED static bool getTerminalVersionTermite(FFstrbuf* exe, FFstrbuf* version) {
if (ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "--version", NULL }) != NULL) { // termite v16.9\nvte 0.78.1 +BIDI +GNUTLS +ICU +SYSTEMD
if (ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "--version", nullptr }) != nullptr) { // termite v16.9\nvte 0.78.1 +BIDI +GNUTLS +ICU +SYSTEMD
return false;
}
@@ -762,7 +762,7 @@ static bool getTerminalVersionWindowsTerminal(FFstrbuf* exe, FFstrbuf* version)
return true;
}
return getFileVersion(exe, NULL, version);
return getFileVersion(exe, nullptr, version);
}
static bool getTerminalVersionConEmu(FFstrbuf* exe, FFstrbuf* version) {
@@ -772,7 +772,7 @@ static bool getTerminalVersionConEmu(FFstrbuf* exe, FFstrbuf* version) {
return true;
}
return getFileVersion(exe, NULL, version);
return getFileVersion(exe, nullptr, version);
}
#endif
@@ -980,11 +980,11 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_A_UNUSED FFstrbuf* exe, FF
#ifdef _WIN32
return getFileVersion(exe, NULL, version);
return getFileVersion(exe, nullptr, version);
#elif __APPLE__
return ffGetAppNameAndVersion(exe->chars, NULL, version);
return ffGetAppNameAndVersion(exe->chars, nullptr, version);
#else
@@ -21,7 +21,7 @@ static pid_t getShellInfo(FFShellResult* result, pid_t pid) {
pid_t ppid = 0;
int32_t tty = -1;
const char* userShellName = NULL;
const char* userShellName = nullptr;
{
uint32_t index = ffStrbufLastIndexC(&instance.state.platform.userShell, '/');
if (index == instance.state.platform.userShell.length) {
@@ -31,7 +31,7 @@ static pid_t getShellInfo(FFShellResult* result, pid_t pid) {
}
}
while (pid > 1 && ffProcessGetBasicInfoLinux(pid, &result->processName, &ppid, &tty) == NULL) {
while (pid > 1 && ffProcessGetBasicInfoLinux(pid, &result->processName, &ppid, &tty) == nullptr) {
if (!ffStrbufEqualS(&result->processName, userShellName)) {
// Common programs that are between terminal and own process, but are not the shell
if (
@@ -79,7 +79,7 @@ static pid_t getShellInfo(FFShellResult* result, pid_t pid) {
static pid_t getTerminalInfo(FFTerminalResult* result, pid_t pid) {
pid_t ppid = 0;
while (pid > 1 && ffProcessGetBasicInfoLinux(pid, &result->processName, &ppid, NULL) == NULL) {
while (pid > 1 && ffProcessGetBasicInfoLinux(pid, &result->processName, &ppid, nullptr) == nullptr) {
// Known shells
if (
pid == 1 || // init/systemd
@@ -130,7 +130,7 @@ static pid_t getTerminalInfo(FFTerminalResult* result, pid_t pid) {
break;
}
}
if (pLeft == pRight && ffProcessGetBasicInfoLinux(ppid, &result->processName, &ppid, NULL) != NULL) {
if (pLeft == pRight && ffProcessGetBasicInfoLinux(ppid, &result->processName, &ppid, nullptr) != nullptr) {
return 0;
}
}
@@ -147,13 +147,13 @@ static pid_t getTerminalInfo(FFTerminalResult* result, pid_t pid) {
static bool getTerminalInfoByPidEnv(FFTerminalResult* result, const char* pidEnv) {
const char* envStr = getenv(pidEnv);
if (envStr == NULL) {
if (envStr == nullptr) {
return false;
}
pid_t pid = (pid_t) strtol(envStr, NULL, 10);
pid_t pid = (pid_t) strtol(envStr, nullptr, 10);
result->pid = (uint32_t) pid;
if (ffProcessGetBasicInfoLinux(pid, &result->processName, (pid_t*) &result->ppid, NULL) == NULL) {
if (ffProcessGetBasicInfoLinux(pid, &result->processName, (pid_t*) &result->ppid, nullptr) == nullptr) {
ffProcessGetInfoLinux(pid, &result->processName, &result->exe, &result->exeName, &result->exePath);
return true;
}
@@ -185,15 +185,15 @@ static void getTerminalFromEnv(FFTerminalResult* result) {
result->pid = result->ppid = 0;
}
const char* term = NULL;
const char* term = nullptr;
// SSH
if (
getenv("SSH_TTY") != NULL) {
getenv("SSH_TTY") != nullptr) {
term = getenv("SSH_TTY");
} else if (
getenv("KITTY_PID") != NULL ||
getenv("KITTY_INSTALLATION_DIR") != NULL) {
getenv("KITTY_PID") != nullptr ||
getenv("KITTY_INSTALLATION_DIR") != nullptr) {
if (getTerminalInfoByPidEnv(result, "KITTY_PID")) {
return;
}
@@ -203,29 +203,29 @@ static void getTerminalFromEnv(FFTerminalResult* result) {
#ifdef __linux__ // WSL
// Windows Terminal
else if (
getenv("WT_SESSION") != NULL ||
getenv("WT_PROFILE_ID") != NULL)
getenv("WT_SESSION") != nullptr ||
getenv("WT_PROFILE_ID") != nullptr)
term = "Windows Terminal";
// ConEmu
else if (
getenv("ConEmuPID") != NULL) {
getenv("ConEmuPID") != nullptr) {
term = "ConEmu";
}
#endif
// Alacritty
else if (
getenv("ALACRITTY_SOCKET") != NULL ||
getenv("ALACRITTY_LOG") != NULL ||
getenv("ALACRITTY_WINDOW_ID") != NULL) {
getenv("ALACRITTY_SOCKET") != nullptr ||
getenv("ALACRITTY_LOG") != nullptr ||
getenv("ALACRITTY_WINDOW_ID") != nullptr) {
term = "Alacritty";
}
#ifdef __ANDROID__
// Termux
else if (
getenv("TERMUX_VERSION") != NULL ||
getenv("TERMUX_MAIN_PACKAGE_FORMAT") != NULL) {
getenv("TERMUX_VERSION") != nullptr ||
getenv("TERMUX_MAIN_PACKAGE_FORMAT") != nullptr) {
if (getTerminalInfoByPidEnv(result, "TERMUX_APP__PID")) {
return;
}
@@ -236,22 +236,22 @@ static void getTerminalFromEnv(FFTerminalResult* result) {
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__GNU__)
// Konsole
else if (
getenv("KONSOLE_VERSION") != NULL)
getenv("KONSOLE_VERSION") != nullptr)
term = "konsole";
else if (
getenv("GNOME_TERMINAL_SCREEN") != NULL ||
getenv("GNOME_TERMINAL_SERVICE") != NULL) {
getenv("GNOME_TERMINAL_SCREEN") != nullptr ||
getenv("GNOME_TERMINAL_SERVICE") != nullptr) {
term = "gnome-terminal";
}
#endif
// MacOS, mintty
else if (getenv("TERM_PROGRAM") != NULL) {
else if (getenv("TERM_PROGRAM") != nullptr) {
term = getenv("TERM_PROGRAM");
}
else if (getenv("LC_TERMINAL") != NULL) {
else if (getenv("LC_TERMINAL") != nullptr) {
term = getenv("LC_TERMINAL");
}
@@ -398,7 +398,7 @@ const FFShellResult* ffDetectShell() {
const char* ignoreParent = getenv("FFTS_IGNORE_PARENT");
if (ignoreParent && ffStrEquals(ignoreParent, "1")) {
FF_STRBUF_AUTO_DESTROY _ = ffStrbufCreate();
ffProcessGetBasicInfoLinux(ppid, &_, &ppid, NULL);
ffProcessGetBasicInfoLinux(ppid, &_, &ppid, nullptr);
}
ppid = getShellInfo(&result, ppid);
@@ -36,7 +36,7 @@ static uint32_t getShellInfo(FFShellResult* result, uint32_t pid) {
ffStrbufClear(&result->processName);
ffStrbufClear(&result->prettyName);
ffStrbufClear(&result->exe);
result->exeName = NULL;
result->exeName = nullptr;
pid = ppid;
continue;
}
@@ -70,7 +70,7 @@ static void setShellInfoDetails(FFShellResult* result) {
ffStrbufSetS(&result->prettyName, "CMD");
if (instance.config.general.detectVersion) {
FF_AUTO_CLOSE_FD HANDLE snapshot = NULL;
FF_AUTO_CLOSE_FD HANDLE snapshot = nullptr;
while (!(snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, result->pid)) && GetLastError() == ERROR_BAD_LENGTH) {}
if (snapshot) {
@@ -79,7 +79,7 @@ static void setShellInfoDetails(FFShellResult* result) {
for (BOOL success = Module32FirstW(snapshot, &module); success; success = Module32NextW(snapshot, &module)) {
if (wcsncmp(module.szModule, L"clink_dll_", strlen("clink_dll_")) == 0) {
FF_STRBUF_AUTO_DESTROY clinkVersion = ffStrbufCreate();
if (ffGetFileVersion(module.szExePath, NULL, &clinkVersion)) {
if (ffGetFileVersion(module.szExePath, nullptr, &clinkVersion)) {
ffStrbufAppendF(&result->prettyName, " (with Clink %s)", clinkVersion.chars);
} else {
ffStrbufAppendS(&result->prettyName, " (with Clink)");
@@ -109,9 +109,9 @@ static bool getTerminalFromEnv(FFTerminalResult* result) {
if (term) {
// ConEmu
uint32_t pid = (uint32_t) strtoul(term, NULL, 10);
uint32_t pid = (uint32_t) strtoul(term, nullptr, 10);
result->pid = pid;
if (ffProcessGetInfoWindows(pid, NULL, &result->processName, &result->exe, &result->exeName, &result->exePath, NULL)) {
if (ffProcessGetInfoWindows(pid, nullptr, &result->processName, &result->exe, &result->exeName, &result->exePath, nullptr)) {
ffStrbufSet(&result->prettyName, &result->processName);
if (ffStrbufEndsWithIgnCaseS(&result->prettyName, ".exe")) {
ffStrbufSubstrBefore(&result->prettyName, result->prettyName.length - 4);
@@ -123,17 +123,17 @@ static bool getTerminalFromEnv(FFTerminalResult* result) {
}
// SSH
if (getenv("SSH_TTY") != NULL) {
if (getenv("SSH_TTY") != nullptr) {
term = getenv("SSH_TTY");
}
// Windows Terminal
if (!term && (getenv("WT_SESSION") != NULL || getenv("WT_PROFILE_ID") != NULL)) {
if (!term && (getenv("WT_SESSION") != nullptr || getenv("WT_PROFILE_ID") != nullptr)) {
term = "WindowsTerminal";
}
// Alacritty
if (!term && (getenv("ALACRITTY_SOCKET") != NULL || getenv("ALACRITTY_LOG") != NULL || getenv("ALACRITTY_WINDOW_ID") != NULL)) {
if (!term && (getenv("ALACRITTY_SOCKET") != nullptr || getenv("ALACRITTY_LOG") != nullptr || getenv("ALACRITTY_WINDOW_ID") != nullptr)) {
term = "Alacritty";
}
@@ -160,32 +160,32 @@ static bool getTerminalFromEnv(FFTerminalResult* result) {
static bool detectDefaultTerminal(FFTerminalResult* result) {
wchar_t regPath[128] = L"SOFTWARE\\Classes\\PackagedCom\\ClassIndex\\";
wchar_t* uuid = regPath + strlen("SOFTWARE\\Classes\\PackagedCom\\ClassIndex\\");
FF_AUTO_CLOSE_FD HANDLE hkcu = NULL;
if (ffRegOpenKeyForRead(HKEY_CURRENT_USER, L"Console\\%%Startup", &hkcu, NULL) &&
FF_AUTO_CLOSE_FD HANDLE hkcu = nullptr;
if (ffRegOpenKeyForRead(HKEY_CURRENT_USER, L"Console\\%%Startup", &hkcu, nullptr) &&
ffRegReadData(hkcu, L"DelegationTerminal", &(FFArgBuffer) {
.data = uuid,
.length = (uint32_t) (sizeof(regPath) - (size_t) (uuid - regPath) * sizeof(wchar_t)),
},
NULL)) {
nullptr)) {
if (wcscmp(uuid, L"{00000000-0000-0000-0000-000000000000}") == 0 || // Let Windows decide
wcscmp(uuid, L"{B23D10C0-E52E-411E-9D5B-C09FDF709C7D}") == 0) // Conhost
{
goto conhost;
}
FF_AUTO_CLOSE_FD HANDLE hklm = NULL;
if (ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, regPath, &hklm, NULL)) {
FF_AUTO_CLOSE_FD HANDLE hklm = nullptr;
if (ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, regPath, &hklm, nullptr)) {
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();
if (ffRegGetSubKey(hklm, 0, &path, NULL)) {
if (ffRegGetSubKey(hklm, 0, &path, nullptr)) {
if (ffStrbufStartsWithS(&path, "Microsoft.WindowsTerminal")) {
ffStrbufSetS(&result->processName, "WindowsTerminal.exe");
ffStrbufSetS(&result->prettyName, "WindowsTerminal");
PWSTR programFiles = NULL;
if (SUCCEEDED(SHGetKnownFolderPath(&FOLDERID_ProgramFiles, KF_FLAG_DEFAULT, NULL, &programFiles))) {
PWSTR programFiles = nullptr;
if (SUCCEEDED(SHGetKnownFolderPath(&FOLDERID_ProgramFiles, KF_FLAG_DEFAULT, nullptr, &programFiles))) {
ffStrbufSetWS(&result->exe, programFiles);
CoTaskMemFree(programFiles);
programFiles = NULL;
programFiles = nullptr;
ffStrbufAppendS(&result->exe, "\\WindowsApps\\");
ffStrbufAppend(&result->exe, &path);
@@ -211,7 +211,7 @@ conhost:;
ULONG size;
if (NT_SUCCESS(NtQueryInformationProcess(NtCurrentProcess(), ProcessConsoleHostProcess, &conhostPid, sizeof(conhostPid), &size)) && conhostPid != 0) {
// For Windows Terminal, it reports the PID of OpenConsole
if (ffProcessGetInfoWindows((uint32_t) conhostPid, NULL, &result->processName, &result->exe, &result->exeName, &result->exePath, NULL)) {
if (ffProcessGetInfoWindows((uint32_t) conhostPid, nullptr, &result->processName, &result->exe, &result->exeName, &result->exePath, nullptr)) {
ffStrbufSet(&result->prettyName, &result->processName);
if (ffStrbufEndsWithIgnCaseS(&result->prettyName, ".exe")) {
ffStrbufSubstrBefore(&result->prettyName, result->prettyName.length - 4);
@@ -311,13 +311,13 @@ const FFShellResult* ffDetectShell(void) {
result.tty = -1;
uint32_t ppid;
if (!ffProcessGetInfoWindows(0, &ppid, NULL, NULL, NULL, NULL, NULL)) {
if (!ffProcessGetInfoWindows(0, &ppid, nullptr, nullptr, nullptr, nullptr, nullptr)) {
return &result;
}
const char* ignoreParent = getenv("FFTS_IGNORE_PARENT");
if (ignoreParent && ffStrEquals(ignoreParent, "1")) {
ffProcessGetInfoWindows(ppid, &ppid, NULL, NULL, NULL, NULL, NULL);
ffProcessGetInfoWindows(ppid, &ppid, nullptr, nullptr, nullptr, nullptr, nullptr);
}
ppid = getShellInfo(&result, ppid);