Module: Mesa
Branch: master
Commit: d4a51160ad346b22dc8a8e53c39665d5c03b3a7d
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=d4a51160ad346b22dc8a8e53c39665d5c03b3a7d

Author: Michael Tang <[email protected]>
Date:   Thu Mar 11 13:29:07 2021 -0800

util: Make os_read_file use O_BINARY on Windows

Reviewed-by: Jason Ekstrand <[email protected]>
Reviewed-by: Jesse Natalie <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9513>

---

 src/util/os_file.c | 7 ++++++-
 src/util/os_file.h | 4 +++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/util/os_file.c b/src/util/os_file.c
index 9fd3f68e3dc..1c30df6486a 100644
--- a/src/util/os_file.c
+++ b/src/util/os_file.c
@@ -111,6 +111,11 @@ readN(int fd, char *buf, size_t len)
    return total ? (ssize_t)total : err;
 }
 
+#ifndef O_BINARY
+/* Unix makes no distinction between text and binary files. */
+#define O_BINARY 0
+#endif
+
 char *
 os_read_file(const char *filename, size_t *size)
 {
@@ -121,7 +126,7 @@ os_read_file(const char *filename, size_t *size)
     */
    size_t len = 64;
 
-   int fd = open(filename, O_RDONLY);
+   int fd = open(filename, O_RDONLY | O_BINARY);
    if (fd == -1) {
       /* errno set by open() */
       return NULL;
diff --git a/src/util/os_file.h b/src/util/os_file.h
index cf0dc207595..0c69eeaafe1 100644
--- a/src/util/os_file.h
+++ b/src/util/os_file.h
@@ -33,8 +33,10 @@ os_dupfd_cloexec(int fd);
 /*
  * Read a file.
  * Returns a char* that the caller must free(), or NULL and sets errno.
- * If size is not null and no error occured it's set to the size of the
+ * If size is not null and no error occurred it's set to the size of the
  * file.
+ * Reads files as binary and includes a NUL terminator after the end of the
+ * returned buffer.
  */
 char *
 os_read_file(const char *filename, size_t *size);

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to