#include "base/test/test_file_util.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "build/build_config.h"
#if BUILDFLAG(IS_ANDROID)
#include <asm/unistd.h>
#include <errno.h>
#include <linux/fadvise.h>
#include <sys/syscall.h>
#endif
#include "base/files/file_path.h"
#include "base/files/scoped_file.h"
#include "base/notreached.h"
namespace base {
#if BUILDFLAG(IS_ANDROID) && __ANDROID_API__ < 21
namespace {
int posix_fadvise(int fd, off_t offset, off_t len, int advice) {
#if defined(ARCH_CPU_ARMEL)
return syscall(__NR_arm_fadvise64_64, fd, advice,
0,
offset,
0,
len);
#endif
NOTIMPLEMENTED();
return ENOSYS;
}
}
#endif
bool EvictFileFromSystemCache(const FilePath& file) {
ScopedFD fd(open(file.value().c_str(), O_RDONLY));
if (!fd.is_valid())
return false;
if (fdatasync(fd.get()) != 0)
return false;
if (posix_fadvise(fd.get(), 0, 0, POSIX_FADV_DONTNEED) != 0)
return false;
return true;
}
}