diff --git a/lib/chibi/filesystem.scm b/lib/chibi/filesystem.scm index 96577ccd..6dc71e94 100644 --- a/lib/chibi/filesystem.scm +++ b/lib/chibi/filesystem.scm @@ -157,6 +157,15 @@ ;;> is satisfied, and \scheme{#f} otherwise. ;;/ +(define (file-is-readable? path) (zero? (file-access path access/read))) +(define (file-is-writable? path) (zero? (file-access path access/write))) +(define (file-is-executable? path) (zero? (file-access path access/execute))) + +;;> File access tests. Returns true iff the current real UID and GID +;;> have the corresponding permissions on path. Equivalent to the +;;> test -r, -w, -x operators in sh. +;;/ + ;;> Equivalent to duplicating the file descriptor \var{old} to ;;> \var{new} and closing \var{old}. diff --git a/lib/chibi/filesystem.sld b/lib/chibi/filesystem.sld index b3b28538..bbaa20f6 100644 --- a/lib/chibi/filesystem.sld +++ b/lib/chibi/filesystem.sld @@ -31,6 +31,7 @@ open/create open/exclusive open/truncate open/append open/non-block file-lock file-truncate + file-is-readable? file-is-writable? file-is-executable? lock/shared lock/exclusive lock/non-blocking lock/unlock is-a-tty?) (import (chibi) (chibi string)) diff --git a/lib/chibi/filesystem.stub b/lib/chibi/filesystem.stub index b26d8138..f5dc1843 100644 --- a/lib/chibi/filesystem.stub +++ b/lib/chibi/filesystem.stub @@ -193,6 +193,12 @@ (define-c int (file-truncate "ftruncate") (port-or-fileno off_t)) +;; Used for file-is-readable?, file-is-writable?, file-is-executable?. +(define-c-const int (access/read "R_OK")) +(define-c-const int (access/write "W_OK")) +(define-c-const int (access/execute "X_OK")) +(define-c int (file-access "access") (string int)) + ;;> Applies the specified locking operation using flock(2) to the port ;;> or file-descriptor.