diff --git a/.gitignore b/.gitignore index 23c2e5d..d44cf7e 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,5 @@ Makefile result /include/ subprojects/* -!subprojects/*.wrap \ No newline at end of file +!subprojects/*.wrap +subprojects/sqlite3.wrap diff --git a/src/os/bsd.cpp b/src/os/bsd.cpp index ec696fa..c34c154 100644 --- a/src/os/bsd.cpp +++ b/src/os/bsd.cpp @@ -7,10 +7,9 @@ #include // ucred, getsockopt, SOL_SOCKET, SO_PEERCRED #include // statvfs #include // sysctlbyname -#include -#include -#include // utsname, uname -#include +#include // LOCAL_PEERCRED +#include // uname, utsname +#include // readlink #if defined(__FreeBSD__) || defined(__DragonFly__) #include // kenv @@ -36,14 +35,14 @@ namespace { fn GetPathByPid(pid_t pid) -> Result { Array exePathBuf; usize size = exePathBuf.size(); - int mib[4]; + Array mib; - mib[0] = CTL_KERN; - mib[1] = KERN_PROC_ARGS; // Use KERN_PROC_ARGS which includes path - mib[2] = pid; - mib[3] = KERN_PROC_PATHNAME; // The specific subcommand + mib.at(0) = CTL_KERN; + mib.at(1) = KERN_PROC_ARGS; + mib.at(2) = pid; + mib.at(3) = KERN_PROC_PATHNAME; - if (sysctl(mib, 4, exePathBuf.data(), &size, nullptr, 0) == -1) + if (sysctl(mib.data(), 4, exePathBuf.data(), &size, nullptr, 0) == -1) return Err(DracError::withErrno(std::format("sysctl KERN_PROC_PATHNAME failed for pid {}", pid))); if (size == 0 || exePathBuf[0] == '\0') @@ -51,7 +50,7 @@ namespace { DracError(DracErrorCode::NotFound, std::format("sysctl KERN_PROC_PATHNAME returned empty path for pid {}", pid)) ); - exePathBuf[std::min(size, exePathBuf.size() - 1)] = '\0'; + exePathBuf.at(std::min(size, exePathBuf.size() - 1)) = '\0'; return String(exePathBuf.data()); } @@ -145,7 +144,7 @@ namespace { if (fileDescriptor < 0) return Err(DracError(DracErrorCode::ApiUnavailable, "Failed to get Wayland file descriptor")); - pid_t peer_pid = -1; // Initialize PID + pid_t peerPid = -1; // Initialize PID #if defined(__FreeBSD__) || defined(__DragonFly__) struct xucred cred; @@ -155,10 +154,7 @@ namespace { if (getsockopt(fileDescriptor, SOL_SOCKET, LOCAL_PEERCRED, &cred, &len) == -1) return Err(DracError::withErrno("Failed to get socket credentials (LOCAL_PEERCRED)")); - if (len != sizeof(cred) || cred.cr_version != XUCRED_VERSION) - return Err(DracError(DracErrorCode::PlatformSpecific, "Invalid xucred structure received")); - - peer_pid = cred.cr_pid; + peerPid = cred.cr_pid; #elif defined(__NetBSD__) uid_t euid; gid_t egid; @@ -169,10 +165,10 @@ namespace { return "Wayland Compositor (Unknown Path)"; #endif - if (peer_pid <= 0) + if (peerPid <= 0) return Err(DracError(DracErrorCode::PlatformSpecific, "Failed to obtain a valid peer PID")); - Result exePathResult = GetPathByPid(peer_pid); + Result exePathResult = GetPathByPid(peerPid); if (!exePathResult) { return Err(std::move(exePathResult).error()); @@ -447,14 +443,14 @@ namespace os { if (sysctlbyname("hw.model", buffer.data(), &size, nullptr, 0) == -1) return Err(DracError::withErrno("kenv smbios.system.product failed and sysctl hw.model also failed")); - buffer[std::min(size, buffer.size() - 1)] = '\0'; + buffer.at(std::min(size, buffer.size() - 1)) = '\0'; return String(buffer.data()); } if (result > 0) - buffer[result] = '\0'; + buffer.at(result) = '\0'; else - buffer[0] = '\0'; + buffer.at(0) = '\0'; #elif defined(__NetBSD__) if (sysctlbyname("machdep.dmi.system-product", buffer.data(), &size, nullptr, 0) == -1) diff --git a/src/wrappers/dbus.hpp b/src/wrappers/dbus.hpp index cc1e25a..4eab1df 100644 --- a/src/wrappers/dbus.hpp +++ b/src/wrappers/dbus.hpp @@ -1,8 +1,9 @@ #pragma once -#include +#if defined(__linux__) || defined(__FreeBSD__) // clang-format off +#include #include // DBus Library #include // std::exchange, std::forward #include // std::format @@ -384,3 +385,5 @@ namespace dbus { } }; } // namespace dbus + +#endif // __linux__ || __FreeBSD__ diff --git a/src/wrappers/wayland.hpp b/src/wrappers/wayland.hpp index f780c03..316e676 100644 --- a/src/wrappers/wayland.hpp +++ b/src/wrappers/wayland.hpp @@ -1,10 +1,14 @@ #pragma once +#if defined(__linux__) || defined(__FreeBSD__) + +// clang-format off #include // Wayland client library #include "src/util/defs.hpp" #include "src/util/logging.hpp" #include "src/util/types.hpp" +// clang-format on struct wl_display; @@ -91,3 +95,5 @@ namespace wl { [[nodiscard]] fn fd() const -> util::types::i32 { return get_fd(m_display); } }; } // namespace wl + +#endif // __linux__ || __FreeBSD__ diff --git a/src/wrappers/xcb.hpp b/src/wrappers/xcb.hpp index b062e27..9d806b0 100644 --- a/src/wrappers/xcb.hpp +++ b/src/wrappers/xcb.hpp @@ -1,5 +1,7 @@ #pragma once +#if defined(__linux__) || defined(__FreeBSD__) + // clang-format off #include // XCB library @@ -31,7 +33,7 @@ namespace xcb { ReqLenExceed = XCB_CONN_CLOSED_REQ_LEN_EXCEED, ParseErr = XCB_CONN_CLOSED_PARSE_ERR, InvalidScreen = XCB_CONN_CLOSED_INVALID_SCREEN, - FdPassingFailed = XCB_CONN_CLOSED_FDPASSING_FAILED + FdPassingFailed = XCB_CONN_CLOSED_FDPASSING_FAILED, }; // NOLINTBEGIN(readability-identifier-naming) @@ -168,3 +170,5 @@ namespace xcb { [[nodiscard]] fn operator*() const->T& { return *m_reply; } }; } // namespace xcb + +#endif // __linux__ || __FreeBSD__