diff --git a/lib/chibi/filesystem.scm b/lib/chibi/filesystem.scm index f596bb2f..bb253e9c 100644 --- a/lib/chibi/filesystem.scm +++ b/lib/chibi/filesystem.scm @@ -162,3 +162,12 @@ (define (renumber-file-descriptor old new) (and (duplicate-file-descriptor-to old new) (close-file-descriptor old))) + +;;> Returns the path the symbolic link \var{file} points to, or +;;> \scheme{#f} on error. + +(define (read-link file) + (let* ((buf (make-string 512)) + (res (readlink file buf 512))) + (and (positive? res) + (substring buf 0 res)))) diff --git a/lib/chibi/filesystem.sld b/lib/chibi/filesystem.sld index c660f0a3..cee82d27 100644 --- a/lib/chibi/filesystem.sld +++ b/lib/chibi/filesystem.sld @@ -14,6 +14,7 @@ create-directory create-directory* current-directory change-directory with-directory open open-pipe make-fifo + read-link file-status file-link-status file-device file-inode file-mode file-num-links diff --git a/lib/chibi/filesystem.stub b/lib/chibi/filesystem.stub index 2a4c8ddd..89dddbe6 100644 --- a/lib/chibi/filesystem.stub +++ b/lib/chibi/filesystem.stub @@ -66,6 +66,8 @@ (define-c errno fstat (int (result stat))) (define-c errno (file-link-status "lstat") (string (result stat))) +(define-c int readlink (string string int)) + ;; Creates a new input-port from the file descriptor \var{int}. ;; (define-c input-port (open-input-file-descriptor "fdopen")