From aaeca7b0009eb56f9176a316d996805a2653644c Mon Sep 17 00:00:00 2001 From: pastdue <30942300+past-due@users.noreply.github.com> Date: Fri, 23 Jul 2021 01:48:48 -0400 Subject: [PATCH] [physfs] Patches to fix behavior on macOS / Linux (#15962) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [physfs] Patches to fix behavior on macOS / Linux * Run x-add-version physfs * Update ports/physfs/portfile.cmake * Update ports/physfs/portfile.cmake * Update versions/p-/physfs.json Co-authored-by: Jack·Boos·Yu <47264268+JackBoosY@users.noreply.github.com> --- ...ch => 001-fix-lzmasdk-arm64-windows.patch} | 0 ports/physfs/002-fix-posix-eintr.patch | 73 +++++++++++++++++++ ports/physfs/003-fix-posix-cloexec.patch | 34 +++++++++ ports/physfs/portfile.cmake | 4 +- ports/physfs/vcpkg.json | 2 +- versions/baseline.json | 2 +- versions/p-/physfs.json | 5 ++ 7 files changed, 117 insertions(+), 3 deletions(-) rename ports/physfs/{fix-lzmasdk-arm64-windows.patch => 001-fix-lzmasdk-arm64-windows.patch} (100%) create mode 100644 ports/physfs/002-fix-posix-eintr.patch create mode 100644 ports/physfs/003-fix-posix-cloexec.patch diff --git a/ports/physfs/fix-lzmasdk-arm64-windows.patch b/ports/physfs/001-fix-lzmasdk-arm64-windows.patch similarity index 100% rename from ports/physfs/fix-lzmasdk-arm64-windows.patch rename to ports/physfs/001-fix-lzmasdk-arm64-windows.patch diff --git a/ports/physfs/002-fix-posix-eintr.patch b/ports/physfs/002-fix-posix-eintr.patch new file mode 100644 index 0000000000..08d314af1c --- /dev/null +++ b/ports/physfs/002-fix-posix-eintr.patch @@ -0,0 +1,73 @@ +diff --git a/src/physfs_platform_posix.c b/src/physfs_platform_posix.c +--- a/src/physfs_platform_posix.c ++++ b/src/physfs_platform_posix.c +@@ -6,8 +6,6 @@ + * This file written by Ryan C. Gordon. + */ + +-/* !!! FIXME: check for EINTR? */ +- + #define __PHYSICSFS_INTERNAL__ + #include "physfs_platforms.h" + +@@ -167,7 +165,9 @@ static void *doOpen(const char *filename, int mode) + /* O_APPEND doesn't actually behave as we'd like. */ + mode &= ~O_APPEND; + +- fd = open(filename, mode, S_IRUSR | S_IWUSR); ++ do { ++ fd = open(filename, mode, S_IRUSR | S_IWUSR); ++ } while ((fd < 0) && (errno == EINTR)); + BAIL_IF(fd < 0, errcodeFromErrno(), NULL); + + if (appending) +@@ -219,7 +219,9 @@ PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer, + if (!__PHYSFS_ui64FitsAddressSpace(len)) + BAIL(PHYSFS_ERR_INVALID_ARGUMENT, -1); + +- rc = read(fd, buffer, (size_t) len); ++ do { ++ rc = read(fd, buffer, (size_t) len); ++ } while ((rc == -1) && (errno == EINTR)); + BAIL_IF(rc == -1, errcodeFromErrno(), -1); + assert(rc >= 0); + assert(rc <= len); +@@ -236,7 +238,9 @@ PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer, + if (!__PHYSFS_ui64FitsAddressSpace(len)) + BAIL(PHYSFS_ERR_INVALID_ARGUMENT, -1); + +- rc = write(fd, (void *) buffer, (size_t) len); ++ do { ++ rc = write(fd, (void *) buffer, (size_t) len); ++ } while ((rc == -1) && (errno == EINTR)); + BAIL_IF(rc == -1, errcodeFromErrno(), rc); + assert(rc >= 0); + assert(rc <= len); +@@ -275,8 +279,13 @@ PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque) + int __PHYSFS_platformFlush(void *opaque) + { + const int fd = *((int *) opaque); +- if ((fcntl(fd, F_GETFL) & O_ACCMODE) != O_RDONLY) +- BAIL_IF(fsync(fd) == -1, errcodeFromErrno(), 0); ++ int rc = -1; ++ if ((fcntl(fd, F_GETFL) & O_ACCMODE) != O_RDONLY) { ++ do { ++ rc = fsync(fd); ++ } while ((rc == -1) && (errno == EINTR)); ++ BAIL_IF(rc == -1, errcodeFromErrno(), 0); ++ } + return 1; + } /* __PHYSFS_platformFlush */ + +@@ -284,7 +293,10 @@ int __PHYSFS_platformFlush(void *opaque) + void __PHYSFS_platformClose(void *opaque) + { + const int fd = *((int *) opaque); +- (void) close(fd); /* we don't check this. You should have used flush! */ ++ int rc = -1; ++ do { ++ rc = close(fd); /* we don't check this. You should have used flush! */ ++ } while ((rc == -1) && (errno == EINTR)); + allocator.Free(opaque); + } /* __PHYSFS_platformClose */ + diff --git a/ports/physfs/003-fix-posix-cloexec.patch b/ports/physfs/003-fix-posix-cloexec.patch new file mode 100644 index 0000000000..6ff2114a5e --- /dev/null +++ b/ports/physfs/003-fix-posix-cloexec.patch @@ -0,0 +1,34 @@ +diff --git a/src/physfs_platform_posix.c b/src/physfs_platform_posix.c +--- a/src/physfs_platform_posix.c ++++ b/src/physfs_platform_posix.c +@@ -160,16 +160,30 @@ static void *doOpen(const char *filename, int mode) + const int appending = (mode & O_APPEND); + int fd; + int *retval; ++ int flags; ++ flags = -1; + errno = 0; + + /* O_APPEND doesn't actually behave as we'd like. */ + mode &= ~O_APPEND; ++ ++#ifdef O_CLOEXEC ++ /* Add O_CLOEXEC if defined */ ++ mode |= O_CLOEXEC; ++#endif + + do { + fd = open(filename, mode, S_IRUSR | S_IWUSR); + } while ((fd < 0) && (errno == EINTR)); + BAIL_IF(fd < 0, errcodeFromErrno(), NULL); + ++#if !defined(O_CLOEXEC) && defined(FD_CLOEXEC) ++ flags = fcntl(fd, F_GETFD); ++ if (flags != -1) { ++ fcntl(fd, F_SETFD, flags | FD_CLOEXEC); ++ } ++#endif ++ + if (appending) + { + if (lseek(fd, 0, SEEK_END) < 0) diff --git a/ports/physfs/portfile.cmake b/ports/physfs/portfile.cmake index 2ce216e4d7..593c84293e 100644 --- a/ports/physfs/portfile.cmake +++ b/ports/physfs/portfile.cmake @@ -12,7 +12,9 @@ vcpkg_extract_source_archive_ex( ARCHIVE ${ARCHIVE} REF ${PHYSFS_VERSION} PATCHES - "fix-lzmasdk-arm64-windows.patch" + "001-fix-lzmasdk-arm64-windows.patch" + "002-fix-posix-eintr.patch" # Remove this patch in the next update + "003-fix-posix-cloexec.patch" # Remove this patch in the next update ) string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" PHYSFS_STATIC) diff --git a/ports/physfs/vcpkg.json b/ports/physfs/vcpkg.json index 0c0dfceb9d..a61a338818 100644 --- a/ports/physfs/vcpkg.json +++ b/ports/physfs/vcpkg.json @@ -1,7 +1,7 @@ { "name": "physfs", "version-string": "3.0.2", - "port-version": 4, + "port-version": 5, "description": "a library to provide abstract access to various archives", "homepage": "https://icculus.org/physfs/", "dependencies": [ diff --git a/versions/baseline.json b/versions/baseline.json index 4e7866e203..781b50eb62 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -4866,7 +4866,7 @@ }, "physfs": { "baseline": "3.0.2", - "port-version": 4 + "port-version": 5 }, "physx": { "baseline": "4.1.2", diff --git a/versions/p-/physfs.json b/versions/p-/physfs.json index 3a3b9371c1..ba352ec877 100644 --- a/versions/p-/physfs.json +++ b/versions/p-/physfs.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "5976d673e48ec47164efd0ea8ec86728f0e259be", + "version-string": "3.0.2", + "port-version": 5 + }, { "git-tree": "bef97b95b7c30545c4ec9d0a55f672c3a6e3325f", "version-string": "3.0.2",