From 3c2615e2a7b4fdd4ae7221b7bd98ce7245273725 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sun, 27 Dec 2009 00:45:28 +0900 Subject: [PATCH] moving file-exists? to (chibi filesystem) --- eval.c | 9 --------- lib/chibi/filesystem.module | 2 +- lib/chibi/filesystem.scm | 1 + opcodes.c | 1 - opt/plan9-opcodes.c | 1 + 5 files changed, 3 insertions(+), 11 deletions(-) diff --git a/eval.c b/eval.c index 4546318f..0c87270d 100644 --- a/eval.c +++ b/eval.c @@ -2038,15 +2038,6 @@ static sexp sexp_close_port (sexp ctx, sexp port) { return SEXP_VOID; } -#ifndef PLAN9 -static sexp sexp_file_exists_p (sexp ctx, sexp path) { - struct stat buf; - if (! sexp_stringp(path)) - return sexp_type_exception(ctx, "not a string", path); - return (stat(sexp_string_data(path), &buf) ? SEXP_FALSE : SEXP_TRUE); -} -#endif - void sexp_warn_undefs (sexp ctx, sexp from, sexp to, sexp out) { sexp x; for (x=from; sexp_pairp(x) && x!=to; x=sexp_cdr(x)) diff --git a/lib/chibi/filesystem.module b/lib/chibi/filesystem.module index 82a8ebda..38a8fab1 100644 --- a/lib/chibi/filesystem.module +++ b/lib/chibi/filesystem.module @@ -14,7 +14,7 @@ file-access-time file-modification-time file-change-time file-regular? file-directory? file-character? file-block? file-fifo? file-link? - file-socket? + file-socket? file-exists? get-file-descriptor-flags set-file-descriptor-flags! get-file-descriptor-status set-file-descriptor-status! open/read open/write open/read-write diff --git a/lib/chibi/filesystem.scm b/lib/chibi/filesystem.scm index b3995221..d1fe36ba 100644 --- a/lib/chibi/filesystem.scm +++ b/lib/chibi/filesystem.scm @@ -37,3 +37,4 @@ (define (file-link? x) (S_ISLNK (file-mode x))) (define (file-socket? x) (S_ISSOCK (file-mode x))) +(define (file-exists? x) (and (file-status file) #t)) diff --git a/opcodes.c b/opcodes.c index 8f9825d9..5b943e6f 100644 --- a/opcodes.c +++ b/opcodes.c @@ -142,7 +142,6 @@ _FN2OPTP(SEXP_PROCEDURE, SEXP_OPORT, "disasm", (sexp)"*current-error-port*", sex #if PLAN9 #include "opt/plan9-opcodes.c" #endif -_FN1(SEXP_STRING, "file-exists?", 0, sexp_file_exists_p), #if SEXP_USE_MODULES _FN1(SEXP_ENV, "env-exports", 0, sexp_env_exports), _FN1(SEXP_STRING, "find-module-file", 0, sexp_find_module_file_op), diff --git a/opt/plan9-opcodes.c b/opt/plan9-opcodes.c index e64dd8a8..9f7cac33 100644 --- a/opt/plan9-opcodes.c +++ b/opt/plan9-opcodes.c @@ -16,3 +16,4 @@ _FN1(SEXP_STRING, "change-directory", 0, sexp_chdir), _FN0("wait", 0, sexp_wait), _FN2(SEXP_FIXNUM, SEXP_STRING, "post-note", 0, sexp_postnote), _FN4(SEXP_PAIR, SEXP_STRING, "%postmountsrv", 0, sexp_postmountsrv), +_FN1(SEXP_STRING, "file-exists?", 0, sexp_file_exists_p),