klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

commit 07706c4ee8604c61f93542f36aa495ba471b77e6
parent 2e789a4968487495a200fab0ef4c25c34e315475
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Fri, 21 Oct 2011 14:35:44 -0300

Added delete-file to the ground environment.

Diffstat:
Msrc/kgports.c | 23+++++++++++++++++++++++
Msrc/kgports.h | 3+++
2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/src/kgports.c b/src/kgports.c @@ -600,6 +600,26 @@ void file_existsp(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) kapply_cc(K, res); } +/* 15.1.? delete-file */ +void delete_file(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) +{ + UNUSED(xparams); + UNUSED(denv); + + bind_1tp(K, ptree, "string", ttisstring, filename); + + /* TEMP: this should probably be done in a operating system specific + manner, but this will do for now */ + if (remove(kstring_buf(filename))) { + /* TODO: more meaningful error msg, include errno */ + klispE_throw_simple(K, "the file couldn't be deleted"); + return; + } else { + kapply_cc(K, KINERT); + return; + } +} + /* init ground */ void kinit_ports_ground_env(klisp_State *K) { @@ -695,4 +715,7 @@ void kinit_ports_ground_env(klisp_State *K) /* 15.1.? file-exists? */ add_applicative(K, ground_env, "file-exists?", file_existsp, 0); + + /* 15.1.? delete-file */ + add_applicative(K, ground_env, "delete-file", delete_file, 0); } diff --git a/src/kgports.h b/src/kgports.h @@ -93,6 +93,9 @@ void flush(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); /* 15.1.? file-exists? */ void file_existsp(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); +/* 15.1.? delete-file */ +void delete_file(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); + /* init ground */ void kinit_ports_ground_env(klisp_State *K);