[PATCH] D38984: Use O_BINARY when opening GCDA file on Windows

Marco Castelluccio via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 17 06:01:42 PDT 2017


marco-c updated this revision to Diff 119299.
marco-c retitled this revision from "Use fopen instead of fdopen for opening GCDA files as fdopen seems to cause files to get corrupted" to "Use O_BINARY when opening GCDA file on Windows".
marco-c edited the summary of this revision.
marco-c added a comment.

Replaced **fopen** with **fdopen** again, added O_BINARY when originally opening file with **open**.


https://reviews.llvm.org/D38984

Files:
  lib/profile/GCDAProfiling.c


Index: lib/profile/GCDAProfiling.c
===================================================================
--- lib/profile/GCDAProfiling.c
+++ lib/profile/GCDAProfiling.c
@@ -37,7 +37,10 @@
 #ifndef MAP_FILE
 #define MAP_FILE 0
 #endif
+#ifndef O_BINARY
+#define O_BINARY 0
 #endif
+#endif
 
 #if defined(__FreeBSD__) && defined(__i386__)
 #define I386_FREEBSD 1
@@ -238,17 +241,17 @@
 
   /* Try just opening the file. */
   new_file = 0;
-  fd = open(filename, O_RDWR);
+  fd = open(filename, O_RDWR | O_BINARY);
 
   if (fd == -1) {
     /* Try opening the file, creating it if necessary. */
     new_file = 1;
     mode = "w+b";
-    fd = open(filename, O_RDWR | O_CREAT, 0644);
+    fd = open(filename, O_RDWR | O_CREAT | O_BINARY, 0644);
     if (fd == -1) {
       /* Try creating the directories first then opening the file. */
       __llvm_profile_recursive_mkdir(filename);
-      fd = open(filename, O_RDWR | O_CREAT, 0644);
+      fd = open(filename, O_RDWR | O_CREAT | O_BINARY, 0644);
       if (fd == -1) {
         /* Bah! It's hopeless. */
         int errnum = errno;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38984.119299.patch
Type: text/x-patch
Size: 1083 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171017/b0687bf0/attachment.bin>


More information about the llvm-commits mailing list