mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-04 03:36:36 +02:00
Adding call-with-locked-file utility.
This commit is contained in:
parent
061f7f57f5
commit
9f518e56c4
2 changed files with 10 additions and 0 deletions
|
@ -106,6 +106,15 @@
|
||||||
thunk
|
thunk
|
||||||
(lambda () (change-directory pwd)))))
|
(lambda () (change-directory pwd)))))
|
||||||
|
|
||||||
|
;;> Calls \var{proc} on a read/write opened file descriptor for
|
||||||
|
;;> \var{path}, locked with \scheme{file-lock}, and automatically
|
||||||
|
;;> removes the lock when \var{proc} returns the first time.
|
||||||
|
|
||||||
|
(define (call-with-locked-file path proc)
|
||||||
|
(let ((fd (open path open/read-write)))
|
||||||
|
(file-lock fd lock/exclusive)
|
||||||
|
(exception-protect (proc fd) (file-lock fd lock/unlock))))
|
||||||
|
|
||||||
;;> Returns the \scheme{status} object for the given \var{file},
|
;;> Returns the \scheme{status} object for the given \var{file},
|
||||||
;;> which should be a string indicating the path or a file
|
;;> which should be a string indicating the path or a file
|
||||||
;;> descriptor.
|
;;> descriptor.
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
open/create open/exclusive open/truncate
|
open/create open/exclusive open/truncate
|
||||||
open/append open/non-block
|
open/append open/non-block
|
||||||
file-lock file-truncate
|
file-lock file-truncate
|
||||||
|
call-with-locked-file
|
||||||
lock/shared lock/exclusive lock/non-blocking lock/unlock
|
lock/shared lock/exclusive lock/non-blocking lock/unlock
|
||||||
is-a-tty?)
|
is-a-tty?)
|
||||||
(import (chibi) (chibi string))
|
(import (chibi) (chibi string))
|
||||||
|
|
Loading…
Add table
Reference in a new issue