~ chicken-core (chicken-5) ffe55397b5b106e03297f984c43471dd62ff32df
commit ffe55397b5b106e03297f984c43471dd62ff32df
Author: Evan Hanson <evhan@foldling.org>
AuthorDate: Wed May 13 17:50:39 2020 +1200
Commit: felix <felix@call-with-current-continuation.org>
CommitDate: Mon Jun 1 13:56:13 2020 +0200
Use 0666 as default file-open mode
There doesn't seem to be a default mode for open(2) specified anywhere,
so let's make `file-open' match fopen(3) so the permissions of files
created using the posix unit match files created with the normal
`open-output-file' procedure, rather than making them executable by
default. This closes #1698.
Signed-off-by: felix <felix@call-with-current-continuation.org>
diff --git a/posixunix.scm b/posixunix.scm
index 23ff157e..1bddc429 100644
--- a/posixunix.scm
+++ b/posixunix.scm
@@ -335,7 +335,7 @@ static int set_file_mtime(char *filename, C_word atime, C_word mtime)
res ) ) ) ) )
(set! chicken.file.posix#file-open
- (let ((defmode (bitwise-ior _s_irwxu (bitwise-ior _s_irgrp _s_iroth))) )
+ (let ((defmode (bitwise-ior _s_irusr _s_iwusr _s_irgrp _s_iwgrp _s_iroth _s_iwoth)))
(lambda (filename flags . mode)
(let ([mode (if (pair? mode) (car mode) defmode)])
(##sys#check-string filename 'file-open)
diff --git a/posixwin.scm b/posixwin.scm
index c279c58e..cb31a07b 100644
--- a/posixwin.scm
+++ b/posixwin.scm
@@ -517,7 +517,7 @@ static int set_file_mtime(char *filename, C_word atime, C_word mtime)
(set! chicken.file.posix#open/noinherit _o_noinherit)
(set! chicken.file.posix#file-open
- (let ((defmode (bitwise-ior _s_irwxu (fxior _s_irgrp _s_iroth))))
+ (let ((defmode (bitwise-ior _s_irusr _s_iwusr _s_irgrp _s_iwgrp _s_iroth _s_iwoth)))
(lambda (filename flags . mode)
(let ([mode (if (pair? mode) (car mode) defmode)])
(##sys#check-string filename 'file-open)
diff --git a/tests/posix-tests.scm b/tests/posix-tests.scm
index 807730e6..361f55c1 100644
--- a/tests/posix-tests.scm
+++ b/tests/posix-tests.scm
@@ -87,3 +87,43 @@
(assert (equal? (get-environment-variable "FOO") "bar"))
(unset-environment-variable! "FOO")
(assert (not (get-environment-variable "FOO")))
+
+;; file creation and umask interaction
+(letrec-syntax ((test (syntax-rules ()
+ ((test umask expected)
+ (test umask "expected" expected "given"))
+ ((test umask given expected)
+ (test umask "expected" expected "given" given))
+ ((test umask "expected" expected "given" given ...)
+ (let ((mode (file-creation-mode)))
+ (set! (file-creation-mode) umask)
+ (delete-file* "posix-tests.out")
+ (file-open "posix-tests.out" open/creat given ...)
+ (assert (equal? (file-permissions "posix-tests.out") expected))
+ (set! (file-creation-mode) mode))))))
+ ;; default file mode
+ (test #o000 #o666)
+ (test #o002 #o664)
+ (test #o020 #o646)
+ (test #o022 #o644)
+ (test #o027 #o640)
+ (test #o072 #o604)
+ (test #o077 #o600)
+ (test #o777 #o000)
+ ;; explicit file mode argument
+ (test #o000 #o644 #o644)
+ (test #o002 #o644 #o644)
+ (test #o020 #o644 #o644)
+ (test #o022 #o644 #o644)
+ (test #o027 #o644 #o640)
+ (test #o072 #o644 #o604)
+ (test #o077 #o644 #o600)
+ (test #o777 #o644 #o000)
+ (test #o000 #o777 #o777)
+ (test #o002 #o777 #o775)
+ (test #o020 #o777 #o757)
+ (test #o022 #o777 #o755)
+ (test #o027 #o777 #o750)
+ (test #o072 #o777 #o705)
+ (test #o077 #o777 #o700)
+ (test #o777 #o777 #o000))
Trap