From 9c5fbe2bfbd85f5fd14973d4fe83cde34f00a1a9 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 28 Jan 2020 05:58:05 -0800 Subject: New function: rmdir. * sysif.c (rmdir_wrap): New static function. (sysif_init): rmdir intrinsic registered. * txr.1: Documented. --- sysif.c | 16 ++++++++++++++++ txr.1 | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/sysif.c b/sysif.c index e6402858..567cff44 100644 --- a/sysif.c +++ b/sysif.c @@ -437,6 +437,21 @@ val getcwd_wrap(void) } } } + +static val rmdir_wrap(val path) +{ + char *u8path = utf8_dup_to(c_str(path)); + int err = rmdir(u8path); + free(u8path); + + if (err < 0) { + int eno = errno; + uw_throwf(errno_to_file_error(eno), lit("rmdir ~a: ~d/~s"), + path, num(eno), string_utf8(strerror(eno)), nao); + } + + return t; +} #endif #if HAVE_MAKEDEV @@ -2116,6 +2131,7 @@ void sysif_init(void) #if HAVE_UNISTD_H reg_fun(intern(lit("chdir"), user_package), func_n1(chdir_wrap)); reg_fun(intern(lit("pwd"), user_package), func_n0(getcwd_wrap)); + reg_fun(intern(lit("rmdir"), user_package), func_n1(rmdir_wrap)); #endif #if HAVE_MAKEDEV diff --git a/txr.1 b/txr.1 index 0510b7f9..ebce3c06 100644 --- a/txr.1 +++ b/txr.1 @@ -57536,6 +57536,26 @@ other than .codn ERANGE , an exception will be thrown. +.coNP Function @ rmdir +.synb +.mets (rmdir << path ) +.syne +.desc +The +.code rmdir +function removes the directory named by +.codn path . +If successful, it returns +.metn t , +otherwise it throws an exception of type +.codn file-error . + +Note: +.code rmdir +calls the same-named POSIX function, which requires +.code path +to be the name of an empty directory. + .coNP Function @ remove-path .synb .mets (remove-path < path <> [ throw-on-error-p ]) -- cgit v1.2.3