~ chicken-core (chicken-5) 27e912e0aad2824bb36b689ceba57112a5bbe703


commit 27e912e0aad2824bb36b689ceba57112a5bbe703
Author:     Peter Bex <peter.bex@xs4all.nl>
AuthorDate: Tue Oct 1 22:16:26 2013 +0200
Commit:     Christian Kellermann <ckeen@pestilenz.org>
CommitDate: Wed Oct 2 14:12:45 2013 +0200

    A few fixes for file-creation-mode.
    
    - Don't pass #f to C_umask as if it were a fixnum
    - Ensure it always returns the old value even if no new value is set
    - Document the fact that MODE is optional
    
    Signed-off-by: Christian Kellermann <ckeen@pestilenz.org>

diff --git a/manual/Unit posix b/manual/Unit posix
index 961fbf15..d27fa88a 100644
--- a/manual/Unit posix	
+++ b/manual/Unit posix	
@@ -598,10 +598,11 @@ exact integers) using the {{chown()}} system call.
 
 ==== file-creation-mode
 
-<procedure>(file-creation-mode MODE)</procedure>
+<procedure>(file-creation-mode [MODE])</procedure>
 
 Returns the initial file permissions used for newly created files
-(as with {{umask(2)}}. You can set the mode by executing
+(as with {{umask(2)}}).  If {{MODE}} is supplied, the mode is
+changed to this value.  You can set the mode by executing
 
   (set! (file-creation-mode) MODE)
 
diff --git a/posix-common.scm b/posix-common.scm
index 99c03150..99a840cf 100644
--- a/posix-common.scm
+++ b/posix-common.scm
@@ -470,9 +470,9 @@ EOF
   (getter-with-setter
    (lambda (#!optional um)
      (when um (##sys#check-exact um 'file-creation-mode))
-     (let ((um2 (##core#inline "C_umask" um)))
-       (unless um (##core#inline "C_umask" um2)
-       um2)))
+     (let ((um2 (##core#inline "C_umask" (or um 0))))
+       (unless um (##core#inline "C_umask" um2)) ; restore
+       um2))
    (lambda (um)
      (##sys#check-exact um 'file-creation-mode)
      (##core#inline "C_umask" um))
Trap