[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2] ios: open files in binary mode on windows
From: |
Hannes Domani |
Subject: |
[PATCH v2] ios: open files in binary mode on windows |
Date: |
Wed, 21 Feb 2024 17:53:08 +0100 |
2024-02-21 Hannes Domani <ssbssa@yahoo.de>
* libpoke/ios-dev-file.c (ios_dev_file_open): Open files in
binary mode on windows.
---
libpoke/ios-dev-file.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/libpoke/ios-dev-file.c b/libpoke/ios-dev-file.c
index 62820082..63074f8c 100644
--- a/libpoke/ios-dev-file.c
+++ b/libpoke/ios-dev-file.c
@@ -108,6 +108,14 @@ ios_dev_file_open (const char *handler, uint64_t flags,
int *error,
int flags_for_open = 0;
int fd;
+#ifdef _WIN32
+ /* On windows the O_BINARY flag is needed to open files in binary mode. */
+ int bin_flag = O_BINARY;
+#else
+ /* For other targets use 0 to keep the original flags. */
+ int bin_flag = 0;
+#endif
+
if (mode_flags != 0)
{
/* Decide what mode to use to open the file. */
@@ -118,7 +126,8 @@ ios_dev_file_open (const char *handler, uint64_t flags, int
*error,
internal_error = IOD_EFLAGS;
goto err;
}
- fd = open (handler, flags_for_open, S_IRUSR | S_IWUSR | S_IRGRP |
S_IROTH);
+ fd = open (handler, flags_for_open | bin_flag,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd == -1)
goto err;
f = fdopen (fd, mode_for_fdopen);
@@ -130,19 +139,19 @@ ios_dev_file_open (const char *handler, uint64_t flags,
int *error,
If that fails, then try write-only. */
const char *mode_for_fdopen;
- fd = open (handler, O_RDWR, 0);
+ fd = open (handler, O_RDWR | bin_flag, 0);
flags |= (IOS_F_READ | IOS_F_WRITE);
mode_for_fdopen = "r+b";
if (fd == -1)
{
- fd = open (handler, O_RDONLY, 0);
+ fd = open (handler, O_RDONLY | bin_flag, 0);
if (fd != -1)
flags &= ~IOS_F_WRITE;
mode_for_fdopen = "rb";
}
if (fd == -1)
{
- fd = open (handler, O_WRONLY, 0);
+ fd = open (handler, O_WRONLY | bin_flag, 0);
if (fd != -1)
flags &= ~IOS_F_READ;
mode_for_fdopen = "wb";
--
2.35.1
- [PATCH v2] ios: open files in binary mode on windows,
Hannes Domani <=