From bf1217e9e78edc3b709cdbac920b677a8f718912 Mon Sep 17 00:00:00 2001 From: chiteroman Date: Sun, 9 Feb 2025 09:37:28 +0100 Subject: [PATCH] improve xread, xwrite removed useless code --- app/src/main/cpp/main.cpp | 48 +++++++-------------------------------- 1 file changed, 8 insertions(+), 40 deletions(-) diff --git a/app/src/main/cpp/main.cpp b/app/src/main/cpp/main.cpp index 6737111..7036f05 100644 --- a/app/src/main/cpp/main.cpp +++ b/app/src/main/cpp/main.cpp @@ -20,61 +20,29 @@ #define CUSTOM_JSON_FORK "/data/adb/modules/playintegrityfix/custom.pif.json" #define CUSTOM_JSON "/data/adb/pif.json" -static inline ssize_t xread(int fd, void *buffer, size_t count) { - auto *buf = static_cast(buffer); +static ssize_t xread(int fd, void *buffer, size_t count) { ssize_t total = 0; - + char *buf = static_cast(buffer); while (count > 0) { - ssize_t ret = read(fd, buf, count); - - if (ret < 0) { - // Retry if interrupted - if (errno == EINTR) { - continue; - } - - return -1; - } - - // If 0, we've hit EOF (read no more data) - if (ret == 0) { - break; - } - + ssize_t ret = TEMP_FAILURE_RETRY(read(fd, buf, count)); + if (ret < 0) return -1; buf += ret; total += ret; count -= ret; } - return total; } -static inline ssize_t xwrite(int fd, const void *buffer, size_t count) { - auto *buf = static_cast(buffer); +static ssize_t xwrite(int fd, const void *buffer, size_t count) { ssize_t total = 0; - + char *buf = (char *) buffer; while (count > 0) { - ssize_t ret = write(fd, buf, count); - - if (ret < 0) { - // Retry if interrupted - if (errno == EINTR) { - continue; - } - - return -1; - } - - // Technically, write returning 0 is unusual (e.g., disk full); handle it if needed - if (ret == 0) { - break; - } - + ssize_t ret = TEMP_FAILURE_RETRY(write(fd, buf, count)); + if (ret < 0) return -1; buf += ret; total += ret; count -= ret; } - return total; }