mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-13 16:00:45 +02:00
This ensures that when we enable glibc fault testing these sections won't break CI.
36 lines
925 B
C++
36 lines
925 B
C++
#pragma once
|
|
|
|
#include <FEXCore/Utils/Allocator.h>
|
|
#include <FEXCore/Utils/LogManager.h>
|
|
#include <FEXCore/fextl/string.h>
|
|
|
|
#include <fcntl.h>
|
|
#include <filesystem>
|
|
#include <linux/limits.h>
|
|
#include <optional>
|
|
#include <unistd.h>
|
|
|
|
namespace FEX {
|
|
[[maybe_unused]]
|
|
static
|
|
std::optional<fextl::string> get_fdpath(int fd) {
|
|
FEXCore::Allocator::YesIKnowImNotSupposedToUseTheGlibcAllocator glibc;
|
|
char SymlinkPath[PATH_MAX];
|
|
std::filesystem::path Path = std::filesystem::path("/proc/self/fd") / std::to_string(fd);
|
|
int Result = readlinkat(AT_FDCWD, Path.c_str(), SymlinkPath, sizeof(SymlinkPath));
|
|
if (Result != -1) {
|
|
return fextl::string(SymlinkPath, Result);
|
|
}
|
|
|
|
// Not fatal if an FD doesn't point to a file
|
|
return std::nullopt;
|
|
}
|
|
|
|
inline
|
|
int get_fdpath(int fd, char *SymlinkPath) {
|
|
auto Path = fmt::format("/proc/self/fd/{}", fd);
|
|
return readlinkat(AT_FDCWD, Path.c_str(), SymlinkPath, PATH_MAX);
|
|
}
|
|
|
|
}
|