mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Replace all uses of POSIX realpath
Use `<filesystem>` instead of `realpath` and remove wrapper. Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
This commit is contained in:
parent
6b4ecbdc40
commit
8336e679af
4 changed files with 10 additions and 31 deletions
|
|
@ -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
|
||||
//
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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 <cerrno>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
|
||||
#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
|
||||
|
|
|
|||
Loading…
Reference in a new issue