diff --git a/source/lib/sysdep/filesystem.h b/source/lib/sysdep/filesystem.h index f3518c53fa..7d0c72f059 100644 --- a/source/lib/sysdep/filesystem.h +++ b/source/lib/sysdep/filesystem.h @@ -56,13 +56,6 @@ extern int wopen(const OsPath& pathname, int oflag, mode_t mode); extern int wclose(int fd); -// -// stdlib.h -// - -OsPath wrealpath(const OsPath& pathname); - - // // sys/stat.h // diff --git a/source/lib/sysdep/os/unix/ufilesystem.cpp b/source/lib/sysdep/os/unix/ufilesystem.cpp index 1ca2f2e14c..9444390c1d 100644 --- a/source/lib/sysdep/os/unix/ufilesystem.cpp +++ b/source/lib/sysdep/os/unix/ufilesystem.cpp @@ -98,15 +98,6 @@ int wrename(const OsPath& pathnameOld, const OsPath& pathnameNew) return rename(OsString(pathnameOld).c_str(), OsString(pathnameNew).c_str()); } -OsPath wrealpath(const OsPath& pathname) -{ - char resolvedBuf[PATH_MAX]; - const char* resolved = realpath(OsString(pathname).c_str(), resolvedBuf); - if(!resolved) - return OsPath(); - return resolved; -} - int wstat(const OsPath& pathname, struct stat* buf) { return stat(OsString(pathname).c_str(), buf); diff --git a/source/lib/sysdep/os/win/wposix/wfilesystem.cpp b/source/lib/sysdep/os/win/wposix/wfilesystem.cpp index 26de25d38a..6bbe3b88b9 100644 --- a/source/lib/sysdep/os/win/wposix/wfilesystem.cpp +++ b/source/lib/sysdep/os/win/wposix/wfilesystem.cpp @@ -131,15 +131,6 @@ int wclose(int fd) } -OsPath wrealpath(const OsPath& pathname) -{ - wchar_t resolved[PATH_MAX]; - if(!GetFullPathNameW(OsString(pathname).c_str(), PATH_MAX, resolved, 0)) - return OsPath(); - return resolved; -} - - static int ErrnoFromCreateDirectory() { switch(GetLastError()) diff --git a/source/ps/GameSetup/Paths.cpp b/source/ps/GameSetup/Paths.cpp index 4a6927139f..8fd8d331e5 100644 --- a/source/ps/GameSetup/Paths.cpp +++ b/source/ps/GameSetup/Paths.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -23,7 +23,6 @@ #include "lib/file/file_system.h" #include "lib/path.h" #include "lib/status.h" -#include "lib/sysdep/filesystem.h" // wrealpath #include "lib/sysdep/os.h" #include "lib/sysdep/sysdep.h" // sys_get_executable_name #include "ps/CLogger.h" @@ -32,7 +31,9 @@ #include #include +#include #include +#include #if OS_WIN # include "lib/sysdep/os/win/wutil.h" // wutil_*Path @@ -176,10 +177,13 @@ Paths::Paths(const CmdLineArgs& args) OsPath pathname = sys_ExecutablePathname(); // safe, but requires OS-specific implementation if(pathname.empty()) // failed, use argv[0] instead { - errno = 0; - pathname = wrealpath(argv0); - if(pathname.empty()) - WARN_IF_ERR(StatusFromErrno()); + const std::filesystem::path rpath{argv0.string()}; + std::error_code ec{}; + const std::filesystem::path cpath{std::filesystem::canonical(rpath, ec)}; + if (ec) + LOGERROR("Failed to get absolute path of argv0, reason: %s", ec.message()); + else + pathname = OsPath(cpath.wstring()); } // make sure it's valid