summaryrefslogtreecommitdiff
path: root/libguile
diff options
context:
space:
mode:
authorMaxime Devos <maximedevos@telenet.be>2021-11-16 11:06:24 +0000
committerLudovic Courtès <ludo@gnu.org>2022-10-21 17:39:38 +0200
commit273bfe7510da8ab740e65df11b72d9bb801885f3 (patch)
treedd7639cfb3b9f137289d3bc10044729dc18e2a12 /libguile
parent1ddc4eb964171a6ea9628b0c537040e0e10c8ad1 (diff)
downloadguile-273bfe7510da8ab740e65df11b72d9bb801885f3.tar.gz
Allow file ports in ‘chdir’ when supported.
* configure.ac: Check for ‘fchdir’. * libguile/filesys.c (scm_chdir): Support file ports. (scm_init_filesys): Report support of file ports. * doc/ref/posix.texi (Processes): Update accordingly. * doc/ref/guile.texi: Add copyright line for new documentation in this patch and later patches. * test-suite/tests/filesys.test ("chdir"): Test it. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'libguile')
-rw-r--r--libguile/filesys.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/libguile/filesys.c b/libguile/filesys.c
index 7f8377815..43e55beb4 100644
--- a/libguile/filesys.c
+++ b/libguile/filesys.c
@@ -1,5 +1,6 @@
/* Copyright 1996-2002,2004,2006,2009-2019,2021
Free Software Foundation, Inc.
+ Copyright 2021 Maxime Devos <maximedevos@telenet.be>
This file is part of Guile.
@@ -608,12 +609,28 @@ SCM_DEFINE (scm_link, "link", 2, 0, 0,
SCM_DEFINE (scm_chdir, "chdir", 1, 0, 0,
(SCM str),
"Change the current working directory to @var{str}.\n"
+ "@var{str} can be a string containing a file name,\n"
+ "or a port if supported by the system.\n"
+ "@code{(provided? 'chdir-port)} reports whether ports "
+ "are supported."
"The return value is unspecified.")
#define FUNC_NAME s_scm_chdir
{
int ans;
- STRING_SYSCALL (str, c_str, ans = chdir (c_str));
+#ifdef HAVE_FCHDIR
+ if (SCM_OPFPORTP (str))
+ {
+ int fdes;
+ fdes = SCM_FPORT_FDES (str);
+ SCM_SYSCALL (ans = fchdir (fdes));
+ scm_remember_upto_here_1 (str);
+ }
+ else
+#endif
+ {
+ STRING_SYSCALL (str, c_str, ans = chdir (c_str));
+ }
if (ans != 0)
SCM_SYSERROR;
return SCM_UNSPECIFIED;
@@ -2053,5 +2070,9 @@ scm_init_filesys ()
scm_dot_string = scm_from_utf8_string (".");
+#ifdef HAVE_FCHDIR
+ scm_add_feature("chdir-port");
+#endif
+
#include "filesys.x"
}