summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-01-28 05:58:05 -0800
committerKaz Kylheku <kaz@kylheku.com>2020-01-28 05:58:05 -0800
commit9c5fbe2bfbd85f5fd14973d4fe83cde34f00a1a9 (patch)
tree643b98fc461e77126794e8b2a28982412a4eaf98
parent354824aeceb339dbd854c90f397d9a6c8a27505b (diff)
downloadtxr-9c5fbe2bfbd85f5fd14973d4fe83cde34f00a1a9.tar.gz
txr-9c5fbe2bfbd85f5fd14973d4fe83cde34f00a1a9.tar.bz2
txr-9c5fbe2bfbd85f5fd14973d4fe83cde34f00a1a9.zip
New function: rmdir.
* sysif.c (rmdir_wrap): New static function. (sysif_init): rmdir intrinsic registered. * txr.1: Documented.
-rw-r--r--sysif.c16
-rw-r--r--txr.120
2 files changed, 36 insertions, 0 deletions
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 ])