24 lines
911 B
C++
24 lines
911 B
C++
#include "prx/libc/include/FilesystemError.hpp"
|
|
#include "prx/libc/include/General.hpp"
|
|
#include <cerrno>
|
|
#include <new>
|
|
|
|
extern "C" int APS5_VABI rename_nid_postfix(const char* from, const char* to) {
|
|
if (!from || !to) { errno = 14; return -1; }
|
|
if (!*from || !*to) { errno = 2; return -1; }
|
|
try {
|
|
const auto source = ResolvePath_nid_no_patch(from);
|
|
const auto destination = ResolvePath_nid_no_patch(to);
|
|
std::error_code error;
|
|
std::filesystem::rename(source, destination, error);
|
|
if (error) { errno = FilesystemError(error); return -1; }
|
|
RecordWrittenPath_nid_no_patch(source);
|
|
RecordWrittenPath_nid_no_patch(destination);
|
|
return 0;
|
|
} catch (const std::bad_alloc&) { errno = 12; return -1; }
|
|
catch (const std::filesystem::filesystem_error& error) {
|
|
errno = FilesystemError(error.code());
|
|
return -1;
|
|
}
|
|
}
|