mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-11-05 13:20:11 +00:00
Apply review request from 2026-10-27: change the libkernel_sys Api.hpp declaration of revoke_nid_postfix to take the path, and drop the local revoke/stat/__error declarations from Export.Discovery.cpp and GuestKernelSysRevoke.cpp in favour of the canonical headers. Co-authored-by: DavidSamir <[email protected]>
54 lines
1.6 KiB
C++
54 lines
1.6 KiB
C++
#include "prx/libc/include/GuestErrno.hpp"
|
|
#include "prx/libc/include/general/VabiMacros.hpp"
|
|
#include "prx/libkernel_sys/include/Api.hpp"
|
|
#include <chrono>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <source_location>
|
|
#include <string>
|
|
|
|
namespace {
|
|
|
|
constexpr int Enoent = 2;
|
|
constexpr int Efault = 14;
|
|
constexpr int Enotdir = 20;
|
|
constexpr int Einval = 22;
|
|
constexpr int Enametoolong = 63;
|
|
|
|
void Require(bool condition, std::source_location location = std::source_location::current()) {
|
|
if (condition) return;
|
|
std::fprintf(stderr, "check failed at line %u\n", static_cast<unsigned>(location.line()));
|
|
std::exit(1);
|
|
}
|
|
|
|
int Error() {
|
|
return *__error_nid_postfix();
|
|
}
|
|
|
|
bool Fails(const std::string& path, int error) {
|
|
return revoke_nid_postfix(path.c_str()) == -1 && Error() == error;
|
|
}
|
|
|
|
}
|
|
|
|
int main() {
|
|
const auto root = std::filesystem::path("anyps5-revoke-" + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
|
|
Require(std::filesystem::create_directory(root));
|
|
const auto file = (root / "file.txt").string();
|
|
std::ofstream(file).put('x');
|
|
|
|
Require(Fails(file, Einval));
|
|
Require(Fails(root.string(), Einval));
|
|
Require(Fails((root / "missing").string(), Enoent));
|
|
Require(Fails(file + "/below", Enotdir));
|
|
Require(Fails("", Enoent));
|
|
Require(Fails(std::string(1024, 'a'), Enametoolong));
|
|
Require(revoke_nid_postfix(nullptr) == -1 && Error() == Efault);
|
|
|
|
std::filesystem::remove_all(root);
|
|
std::puts("guest_kernel_sys_revoke passed");
|
|
return 0;
|
|
}
|