summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-21 09:58:53 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-21 09:58:53 -0700
commitb963e5050aaa83ac59c323a2a0382aa6637f1338 (patch)
tree6b5ff4b1c10dc54057aab817dfe631b52a40f3fe
parent60782a5351d2306ac69f700bfb5ab458648190d7 (diff)
downloadtxr-b963e5050aaa83ac59c323a2a0382aa6637f1338.tar.gz
txr-b963e5050aaa83ac59c323a2a0382aa6637f1338.tar.bz2
txr-b963e5050aaa83ac59c323a2a0382aa6637f1338.zip
Adding realpath function.
* configure: New test for realpath. * sysif.c (realpath_wrap): New static function. (sysif_init): Registered realpath intrinsic. * txr.1: Documented.
-rwxr-xr-xconfigure18
-rw-r--r--sysif.c17
-rw-r--r--txr.125
3 files changed, 60 insertions, 0 deletions
diff --git a/configure b/configure
index 8c1b5c67..3eb16e7d 100755
--- a/configure
+++ b/configure
@@ -2863,6 +2863,24 @@ else
printf "no\n"
fi
+printf "Checking for realpath ... "
+cat > conftest.c <<!
+#include <stdlib.h>
+
+int main(void)
+{
+ char *rp = realpath("/var/lib", 0);
+ return 0;
+}
+!
+
+if conftest ; then
+ printf "yes\n"
+ printf "#define HAVE_REALPATH 1\n" >> config.h
+else
+ printf "no\n"
+fi
+
#
# Dependent variables
#
diff --git a/sysif.c b/sysif.c
index 3e14ba97..3e41514b 100644
--- a/sysif.c
+++ b/sysif.c
@@ -1572,6 +1572,19 @@ static val dlvsym_checked(val dlptr, val name, val ver)
#endif
+#if HAVE_REALPATH
+static val realpath_wrap(val path)
+{
+ const wchar_t *path_ws = c_str(path);
+ char *path_u8 = utf8_dup_to(path_ws);
+ char *rp_u8 = realpath(path_u8, 0);
+ val rp = if2(rp_u8, string_utf8(rp_u8));
+ free(rp_u8);
+ free(path_u8);
+ return rp;
+}
+#endif
+
void sysif_init(void)
{
prot1(&at_exit_list);
@@ -1943,4 +1956,8 @@ void sysif_init(void)
reg_varl(intern(lit("rtld-deepbind"), user_package), num_fast(RTLD_DEEPBIND));
#endif
#endif
+
+#if HAVE_REALPATH
+ reg_fun(intern(lit("realpath"), user_package), func_n1(realpath_wrap));
+#endif
}
diff --git a/txr.1 b/txr.1
index ae73c821..1e19a9f9 100644
--- a/txr.1
+++ b/txr.1
@@ -47135,6 +47135,31 @@ function reads the contents of that symbolic link and returns it
as a string. Otherwise, it fails by throwing an exception of type
.codn file-error .
+.coNP Function @ realpath
+.synb
+.mets (realpath << path )
+.syne
+.desc
+The
+.code realpath
+function provides access to the same-named POSIX function.
+It processes the input string
+.meta path
+by expanding all symbolic links, removes all superfluous
+.str ".."
+and
+.str "."
+path components, and extra path-separating slash characters,
+to produce a canonical absolute path name.
+
+If the underlying POSIX function indicates failure, then
+.code nil
+is returned. In that situation the
+.code errno
+value is available using the
+.code errno
+function.
+
.SS* Unix Filesystem Object Existence, Type and Access Tests
The following functions all accept, as the