This is an automated email from Gerrit.

"Erhan Kurubas <erhan.kuru...@espressif.com>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/7018

-- gerrit

commit c5c93f5b29fbc3f4aa8114a5ec2191abad1de49a
Author: Erhan Kurubas <erhan.kuru...@espressif.com>
Date:   Tue Jun 7 18:12:26 2022 +0200

    semihosting: force to open files in binary mode on windows host
    
    On a UNIX system, when an application reads from a file it gets
    exactly what's in the file on disk, on a DOS/Windows world,
    a file can be opened in two modes. Binary or text.
    In the binary mode the system behaves the same as in UNIX.
    But in the text mode writing a NL transformed into CR + NL
    This patch prevents the EOL conversion by forcing the file
    to open in binary mode.
    
    Signed-off-by: Erhan Kurubas <erhan.kuru...@espressif.com>
    Change-Id: I623ccaaa74be5c12f39a43358b4133f64901fbe0

diff --git a/src/target/semihosting_common.c b/src/target/semihosting_common.c
index 2df6e38aea..270ee7e37e 100644
--- a/src/target/semihosting_common.c
+++ b/src/target/semihosting_common.c
@@ -83,18 +83,25 @@ static const int open_gdb_modeflags[12] = {
        TARGET_O_RDWR   | TARGET_O_CREAT | TARGET_O_APPEND
 };
 
+/* Windows host needs O_BINARY flag for proper handling of EOLs */
+#ifdef _WIN32
+#define WIN_FORCE_BINARY O_BINARY
+#else
+#define WIN_FORCE_BINARY 0
+#endif
+
 static const int open_host_modeflags[12] = {
-       O_RDONLY,
+       O_RDONLY | WIN_FORCE_BINARY,
        O_RDONLY | O_BINARY,
-       O_RDWR,
+       O_RDWR   | WIN_FORCE_BINARY,
        O_RDWR   | O_BINARY,
-       O_WRONLY | O_CREAT | O_TRUNC,
+       O_WRONLY | O_CREAT | O_TRUNC  | WIN_FORCE_BINARY,
        O_WRONLY | O_CREAT | O_TRUNC  | O_BINARY,
-       O_RDWR   | O_CREAT | O_TRUNC,
+       O_RDWR   | O_CREAT | O_TRUNC  | WIN_FORCE_BINARY,
        O_RDWR   | O_CREAT | O_TRUNC  | O_BINARY,
-       O_WRONLY | O_CREAT | O_APPEND,
+       O_WRONLY | O_CREAT | O_APPEND | WIN_FORCE_BINARY,
        O_WRONLY | O_CREAT | O_APPEND | O_BINARY,
-       O_RDWR   | O_CREAT | O_APPEND,
+       O_RDWR   | O_CREAT | O_APPEND | WIN_FORCE_BINARY,
        O_RDWR   | O_CREAT | O_APPEND | O_BINARY
 };
 

-- 

Reply via email to