From: Ben Pfaff Date: Wed, 2 Sep 2020 04:42:35 +0000 (-0700) Subject: make-file: Pass O_BINARY or O_TEXT to open() call in replace_file_start(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f36eb1c4b91f2ba7d95314e9b49cd643a01df46;hp=96edf7b5604826c430869f789197db1286e2e73c;p=pspp make-file: Pass O_BINARY or O_TEXT to open() call in replace_file_start(). It's hard to imagine why this would make a difference on a real system, because the file descriptor obtained from open() is passed to fdopen(), which is documented to determine whether the stream is text or binary based on the mode string. However, bug #40223 implies that it makes a difference. I hope that this commit fixes the problem (if any!). Thanks to the anonymous submitter of bug #40223. --- diff --git a/src/data/make-file.c b/src/data/make-file.c index fdbb4643eb..a1a541a5d0 100644 --- a/src/data/make-file.c +++ b/src/data/make-file.c @@ -265,7 +265,10 @@ replace_file_start (const struct file_handle *fh, const char *mode, rf->tmp_name = convert_to_filename_encoding (rf->tmp_name_verbatim, strlen (rf->tmp_name_verbatim), fh_get_file_name_encoding (fh)); /* Create file by that name. */ - fd = Topen (rf->tmp_name, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, permissions); + bool binary = strchr (mode, 'b') != NULL; + fd = Topen (rf->tmp_name, + O_WRONLY | O_CREAT | O_EXCL | (binary ? O_BINARY : O_TEXT), + permissions); if (fd >= 0) break; if (errno != EEXIST)