forked from microsoft/vcpkg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[physfs] Patches to fix behavior on macOS / Linux (microsoft#15962)
* [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 <[email protected]>
- Loading branch information
Showing
7 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters