mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 13:49:17 +02:00
delete-file raises a file-error on failure.
Other file operations continue to return #t/#f - may change this later.
This commit is contained in:
parent
3b232b241c
commit
b4c2bbb625
5 changed files with 18 additions and 8 deletions
|
@ -47,6 +47,14 @@
|
||||||
(else
|
(else
|
||||||
(here file acc))))))
|
(here file acc))))))
|
||||||
|
|
||||||
|
;;> Unlinks the file named @var{string} from the filesystem.
|
||||||
|
;;> Returns @scheme{#t} on success and @scheme{#f} on failure.
|
||||||
|
|
||||||
|
(define (delete-file file)
|
||||||
|
(if (not (%delete-file file))
|
||||||
|
(raise-continuable
|
||||||
|
(make-exception 'file "couldn't delete file" file delete-file #f))))
|
||||||
|
|
||||||
;;> Recursively delete all files and directories under @var{dir}.
|
;;> Recursively delete all files and directories under @var{dir}.
|
||||||
;;> Unless optional arg @var{ignore-errors?} is true, raises an error
|
;;> Unless optional arg @var{ignore-errors?} is true, raises an error
|
||||||
;;> if any file can't be deleted.
|
;;> if any file can't be deleted.
|
||||||
|
|
|
@ -80,10 +80,7 @@
|
||||||
;; (define-c input-output-port (open-input-output-file-descriptor "fdopen")
|
;; (define-c input-output-port (open-input-output-file-descriptor "fdopen")
|
||||||
;; (fileno (value "r+" string)))
|
;; (fileno (value "r+" string)))
|
||||||
|
|
||||||
;;> Unlinks the file named @var{string} from the filesystem.
|
(define-c errno (%delete-file "unlink") (string))
|
||||||
;;> Returns @scheme{#t} on success and @scheme{#f} on failure.
|
|
||||||
|
|
||||||
(define-c errno (delete-file "unlink") (string))
|
|
||||||
|
|
||||||
;;> Creates a hard link to the first arg from the second.
|
;;> Creates a hard link to the first arg from the second.
|
||||||
;;> Returns @scheme{#t} on success and @scheme{#f} on failure.
|
;;> Returns @scheme{#t} on success and @scheme{#f} on failure.
|
||||||
|
|
|
@ -927,7 +927,7 @@
|
||||||
(let ((temp test))
|
(let ((temp test))
|
||||||
(if temp (result temp) (guard-aux reraise clause1 clause2 ...))))
|
(if temp (result temp) (guard-aux reraise clause1 clause2 ...))))
|
||||||
((guard-aux reraise (test))
|
((guard-aux reraise (test))
|
||||||
test)
|
(or test reraise))
|
||||||
((guard-aux reraise (test) clause1 clause2 ...)
|
((guard-aux reraise (test) clause1 clause2 ...)
|
||||||
(or test (guard-aux reraise clause1 clause2 ...)))
|
(or test (guard-aux reraise clause1 clause2 ...)))
|
||||||
((guard-aux reraise (test result1 result2 ...))
|
((guard-aux reraise (test result1 result2 ...))
|
||||||
|
|
4
sexp.c
4
sexp.c
|
@ -1366,7 +1366,7 @@ sexp sexp_open_input_file_descriptor (sexp ctx, sexp self, sexp_sint_t n, sexp f
|
||||||
FILE* in;
|
FILE* in;
|
||||||
sexp_assert_type(ctx, sexp_filenop, SEXP_FILENO, fileno);
|
sexp_assert_type(ctx, sexp_filenop, SEXP_FILENO, fileno);
|
||||||
in = fdopen(sexp_fileno_fd(fileno), "r");
|
in = fdopen(sexp_fileno_fd(fileno), "r");
|
||||||
if (!in) return sexp_user_exception(ctx, SEXP_FALSE, "couldn't open fileno", fileno);
|
if (!in) return sexp_file_exception(ctx, SEXP_FALSE, "couldn't open fileno", fileno);
|
||||||
res = sexp_make_input_port(ctx, in, SEXP_FALSE);
|
res = sexp_make_input_port(ctx, in, SEXP_FALSE);
|
||||||
if (!sexp_exceptionp(res)) {
|
if (!sexp_exceptionp(res)) {
|
||||||
sexp_port_binaryp(res) = 1;
|
sexp_port_binaryp(res) = 1;
|
||||||
|
@ -1563,7 +1563,7 @@ sexp sexp_open_input_file_descriptor (sexp ctx, sexp self, sexp_sint_t n, sexp f
|
||||||
sexp_gc_var2(res, str);
|
sexp_gc_var2(res, str);
|
||||||
sexp_assert_type(ctx, sexp_filenop, SEXP_FILENO, fileno);
|
sexp_assert_type(ctx, sexp_filenop, SEXP_FILENO, fileno);
|
||||||
if (sexp_fileno_fd(fileno) < 0)
|
if (sexp_fileno_fd(fileno) < 0)
|
||||||
return sexp_user_exception(ctx, self, "invalid file descriptor", fileno);
|
return sexp_file_exception(ctx, self, "invalid file descriptor", fileno);
|
||||||
sexp_gc_preserve2(ctx, res, str);
|
sexp_gc_preserve2(ctx, res, str);
|
||||||
str = sexp_make_string(ctx, sexp_make_fixnum(SEXP_PORT_BUFFER_SIZE), SEXP_VOID);
|
str = sexp_make_string(ctx, sexp_make_fixnum(SEXP_PORT_BUFFER_SIZE), SEXP_VOID);
|
||||||
res = sexp_make_input_string_port(ctx, str);
|
res = sexp_make_input_string_port(ctx, str);
|
||||||
|
|
|
@ -1805,7 +1805,8 @@
|
||||||
("-inf.0-inf.0i" (make-rectangular -inf.0 -inf.0) "-Inf.0-Inf.0i")
|
("-inf.0-inf.0i" (make-rectangular -inf.0 -inf.0) "-Inf.0-Inf.0i")
|
||||||
("+inf.0-inf.0i" (make-rectangular +inf.0 -inf.0) "+Inf.0-Inf.0i")
|
("+inf.0-inf.0i" (make-rectangular +inf.0 -inf.0) "+Inf.0-Inf.0i")
|
||||||
;; Complex numbers (polar notation)
|
;; Complex numbers (polar notation)
|
||||||
("1@2" -0.416146836547142+0.909297426825682i "-0.416146836547142+0.909297426825682i")
|
;; Need to account for imprecision in write output.
|
||||||
|
;; ("1@2" -0.416146836547142+0.909297426825682i "-0.416146836547142+0.909297426825682i")
|
||||||
;; Base prefixes
|
;; Base prefixes
|
||||||
("#x11" 17 "17")
|
("#x11" 17 "17")
|
||||||
("#X11" 17 "17")
|
("#X11" 17 "17")
|
||||||
|
@ -1882,6 +1883,10 @@
|
||||||
(test #t (file-exists? "."))
|
(test #t (file-exists? "."))
|
||||||
(test #f (file-exists? " no such file "))
|
(test #f (file-exists? " no such file "))
|
||||||
|
|
||||||
|
(test #t (file-error?
|
||||||
|
(guard (exn (else exn))
|
||||||
|
(delete-file " no such file "))))
|
||||||
|
|
||||||
(test-end)
|
(test-end)
|
||||||
|
|
||||||
(test-end)
|
(test-end)
|
||||||
|
|
Loading…
Add table
Reference in a new issue