Providing read-link utility.

This commit is contained in:
Alex Shinn 2014-03-09 20:19:53 +09:00
parent fe80e56db9
commit 9d1f046385
3 changed files with 12 additions and 0 deletions

View file

@ -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))))

View file

@ -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

View file

@ -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")