From 8892764b468beed94c9f408909a56a234a7d92f2 Mon Sep 17 00:00:00 2001 From: Vasilij Schneidermann Date: Sat, 14 Oct 2017 16:59:02 +0200 Subject: [PATCH] Handle other errors than EACCES for access(3). Fixes #1386 Signed-off-by: Peter Bex --- NEWS | 3 +++ posix-common.scm | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 0e615c07..77bdbcba 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..ce323c54 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?))) ) -- 2.11.0