From af8c3fdfad9343dec8b44dedfb05da9c99cc8269 Mon Sep 17 00:00:00 2001 From: Maxime Devos Date: Tue, 9 Mar 2021 15:59:36 +0100 Subject: [PATCH 02/17] =?UTF-8?q?Allow=20file=20ports=20in=20=E2=80=98chdi?= =?UTF-8?q?r=E2=80=99=20when=20supported..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * configure.ac: Check for ‘fchdir’. * libguile/filesys.c (scm_chdir): Suppport file ports. * doc/ref/posix.texi (Processes): Update accordingly. --- configure.ac | 3 ++- doc/ref/posix.texi | 2 ++ libguile/filesys.c | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 271ac3c2d..a23249d95 100644 --- a/configure.ac +++ b/configure.ac @@ -481,7 +481,8 @@ AC_CHECK_HEADERS([assert.h crt_externs.h]) # sendfile - non-POSIX, found in glibc # AC_CHECK_FUNCS([DINFINITY DQNAN cexp chsize clog clog10 ctermid \ - fesetround ftime ftruncate fchown fchmod getcwd geteuid getsid \ + fesetround ftime ftruncate fchown fchmod fchdir \ + getcwd geteuid getsid \ gettimeofday getuid getgid gmtime_r ioctl lstat mkdir mkdtemp mknod \ nice readlink rename rmdir setegid seteuid \ setlocale setuid setgid setpgid setsid sigaction siginterrupt stat64 \ diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi index 2b2d6eb4f..54c564cb0 100644 --- a/doc/ref/posix.texi +++ b/doc/ref/posix.texi @@ -1641,6 +1641,8 @@ The return value is unspecified. @deffnx {C Function} scm_chdir (str) @cindex current directory Change the current working directory to @var{str}. +@var{str} can be a string containing a file name, +or a port if the @code{fchdir} system call is supported. The return value is unspecified. @end deffn diff --git a/libguile/filesys.c b/libguile/filesys.c index b97614498..a8879f0e1 100644 --- a/libguile/filesys.c +++ b/libguile/filesys.c @@ -658,12 +658,26 @@ 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 the @code{fchdir} system call is supported.\n" "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; -- 2.30.2