From dee3c3e7ba434c9890c5d3abea5908d76fba5e66 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 2 Mar 2019 05:45:55 -0500 Subject: [PATCH] Workaround seccomp on MagiskBoot Close #1150 --- native/jni/utils/file.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/native/jni/utils/file.cpp b/native/jni/utils/file.cpp index 236db143d..abd5a1de3 100644 --- a/native/jni/utils/file.cpp +++ b/native/jni/utils/file.cpp @@ -358,9 +358,13 @@ void full_read_at(int dirfd, const char *filename, void **buf, size_t *size) { } void write_zero(int fd, size_t size) { - size_t pos = lseek(fd, 0, SEEK_CUR); - ftruncate(fd, pos + size); - lseek(fd, pos + size, SEEK_SET); + char buf[4096] = {0}; + size_t len; + while (size > 0) { + len = sizeof(buf) > size ? size : sizeof(buf); + write(fd, buf, len); + size -= len; + } } void file_readline(const char *filename, const function &fn, bool trim) {