diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-05-21 09:58:53 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-05-21 09:58:53 -0700 |
commit | b963e5050aaa83ac59c323a2a0382aa6637f1338 (patch) | |
tree | 6b5ff4b1c10dc54057aab817dfe631b52a40f3fe | |
parent | 60782a5351d2306ac69f700bfb5ab458648190d7 (diff) | |
download | txr-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-x | configure | 18 | ||||
-rw-r--r-- | sysif.c | 17 | ||||
-rw-r--r-- | txr.1 | 25 |
3 files changed, 60 insertions, 0 deletions
@@ -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 # @@ -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 } @@ -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 |