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

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 17 07:17:15 PDT 2017


Did you confirm this fixes it? Because i was just speculating :)
On Tue, Oct 17, 2017 at 6:01 AM Marco Castelluccio via Phabricator <
reviews at reviews.llvm.org> wrote:

> 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 --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171017/be3ace91/attachment.html>


More information about the llvm-commits mailing list