diff options
author | Mike Gran <spk121@yahoo.com> | 2019-02-09 16:59:38 -0800 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2019-05-23 17:30:33 +0200 |
commit | a5df94e78c3aaed257c9b8dbaafff28cf506cca8 (patch) | |
tree | f040bfd6df774af96940fd045149b9b723b0b8ec | |
parent | 08926cdcd092c741f7fac726c70fff8f178daeea (diff) | |
download | guile-a5df94e78c3aaed257c9b8dbaafff28cf506cca8.tar.gz |
Fix binary output on files created by mkstemp!
Some operating systems require a O_BINARY flag.
* libguile/filesys.c (scm_i_mkstemp): Don't mask out O_BINARY flag
* test-suite/tests/posix.test ("binary mode honored"): new test
-rw-r--r-- | libguile/filesys.c | 6 | ||||
-rw-r--r-- | test-suite/tests/posix.test | 17 |
2 files changed, 19 insertions, 4 deletions
diff --git a/libguile/filesys.c b/libguile/filesys.c index 113cf784b..ccec10b8b 100644 --- a/libguile/filesys.c +++ b/libguile/filesys.c @@ -1513,9 +1513,9 @@ SCM_DEFINE (scm_i_mkstemp, "mkstemp!", 1, 1, 0, /* mkostemp(2) only defines O_APPEND, O_SYNC, and O_CLOEXEC to be useful, as O_RDWR|O_CREAT|O_EXCL are implicitly added. It also notes that other flags may error on some systems, which turns - out to be the case. Of those flags, O_APPEND is the only one - of interest anyway, so limit to that flag. */ - open_flags &= O_APPEND; + out to be the case. Of those flags, O_APPEND and O_BINARY are + the only ones of interest anyway, so limit to those flags. */ + open_flags &= O_APPEND | O_BINARY; mode_bits = scm_i_mode_bits (mode); } diff --git a/test-suite/tests/posix.test b/test-suite/tests/posix.test index aa1605a6b..aa0dbc1b2 100644 --- a/test-suite/tests/posix.test +++ b/test-suite/tests/posix.test @@ -76,7 +76,22 @@ (result (not (string=? str template)))) (close-port port) (delete-file str) - result))) + result)) + + (pass-if "binary mode honored" + (let* ((template "T-XXXXXX") + (str (string-copy template)) + (outport (mkstemp! str "wb"))) + (display "\n" outport) + (close-port outport) + (let* ((inport (open-input-file str #:binary #t)) + (char1 (read-char inport)) + (char2 (read-char inport)) + (result (and (char=? char1 #\newline) + (eof-object? char2)))) + (close-port inport) + (delete-file str) + result)))) ;; ;; putenv |