~ chicken-core (chicken-5) 536e2351cf5836e76df79395813501fcb2c4b034


commit 536e2351cf5836e76df79395813501fcb2c4b034
Author:     Vasilij Schneidermann <mail@vasilij.de>
AuthorDate: Sat Oct 14 16:59:02 2017 +0200
Commit:     Evan Hanson <evhan@foldling.org>
CommitDate: Fri Oct 20 17:32:54 2017 +1300

    Handle other errors than EACCES for access(3)
    
    Fixes #1386.
    
    Signed-off-by: Peter Bex <peter@more-magic.net>
    Signed-off-by: Evan Hanson <evhan@foldling.org>

diff --git a/NEWS b/NEWS
index b7dc2ea1..acce52f6 100644
--- a/NEWS
+++ b/NEWS
@@ -59,6 +59,9 @@
   - Renamed bit-set? to bit->boolean because of swapped argument order
     with respect to SRFI-33 and SRFI-60, which was confusing (fixes
     #1385, thanks to Lemonboy).
+  - file-{read,write,execute}-access will now raise an exception when
+    the file doesn't exist or some other non-access related problem is
+    detected (fixes #1386, thanks to Vasilij Schneidermann).
 
 - Module system
   - The compiler has been modularised, for improved namespacing.  This
diff --git a/posix-common.scm b/posix-common.scm
index 553725a9..58342176 100644
--- a/posix-common.scm
+++ b/posix-common.scm
@@ -369,9 +369,12 @@ EOF
 (let ()
   (define (check filename acc loc)
     (##sys#check-string filename loc)
-    (let ((r (fx= 0 (##core#inline "C_test_access" (##sys#make-c-string filename loc) acc))))
-      (unless r (##sys#update-errno))
-      r) )
+    (let ((r (##core#inline "C_test_access" (##sys#make-c-string filename loc) acc)))
+      (if (fx= r -1)
+	  (if (fx= (##sys#update-errno) _eacces)
+	      #f
+	      (posix-error #:file-error loc "cannot access file" filename))
+	  #t)))
   (set! file-read-access? (lambda (filename) (check filename _r_ok 'file-read-access?)))
   (set! file-write-access? (lambda (filename) (check filename _w_ok 'file-write-access?)))
   (set! file-execute-access? (lambda (filename) (check filename _x_ok 'file-execute-access?))) )
Trap