Files
FEX-Emu--FEX/Source/Common/FDUtils.h
T
Ryan Houdek 955595be8a FDUtils: Don't make unknown get_fdpath fatal
Encountered this while running wine things.
Non-fatal so don't explode
2022-08-19 02:28:19 -07:00

27 lines
604 B
C++

#pragma once
#include <FEXCore/Utils/LogManager.h>
#include <fcntl.h>
#include <filesystem>
#include <linux/limits.h>
#include <optional>
#include <unistd.h>
namespace FEX {
[[maybe_unused]]
static
std::optional<std::string> get_fdpath(int fd) {
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 std::string(SymlinkPath, Result);
}
// Not fatal if an FD doesn't point to a file
return std::nullopt;
}
}