Wrap rename and renameat

This commit is contained in:
LoveSy
2023-09-02 04:24:24 -07:00
committed by John Wu
parent 2dbb812126
commit c072b4254d
2 changed files with 22 additions and 6 deletions
+21 -3
View File
@@ -1,8 +1,6 @@
// This file implements all missing symbols that should exist in normal API 23
// libc.a but missing in our extremely lean libc.a replacements.
#if !defined(__LP64__)
#include <stdlib.h>
#include <string.h>
#include <errno.h>
@@ -12,6 +10,11 @@
extern "C" {
#if !defined(__LP64__)
// Add "hacky" libc.a missing symbols back
// All symbols in this file are weak, so a vanilla NDK should still link properly
#include "fortify.hpp"
// Original source: https://github.com/freebsd/freebsd/blob/master/contrib/file/src/getline.c
@@ -111,5 +114,20 @@ extern FILE __sF[];
[[gnu::weak]] FILE* stdout = &__sF[1];
[[gnu::weak]] FILE* stderr = &__sF[2];
#endif // !defined(__LP64__)
[[maybe_unused]]
int __wrap_renameat(int old_dir_fd, const char *old_path, int new_dir_fd, const char *new_path) {
long out = syscall(__NR_renameat, old_dir_fd, old_path, new_dir_fd, new_path);
if (out == -1 && errno == ENOSYS) {
out = syscall(__NR_renameat2, old_dir_fd, old_path, new_dir_fd, new_path, 0);
}
return static_cast<int>(out);
}
[[maybe_unused]]
int __wrap_rename(const char *old_path, const char *new_path) {
return __wrap_renameat(AT_FDCWD, old_path, AT_FDCWD, new_path);
}
} // extern "C"
#endif