From 1e322e6298ebed31e982bb4ad3a4132f8e7b2036 Mon Sep 17 00:00:00 2001 From: Maxime Devos Date: Fri, 12 Mar 2021 17:30:58 +0100 Subject: [PATCH 11/17] =?UTF-8?q?Define=20a=20Scheme=20binding=20to=20?= =?UTF-8?q?=E2=80=98fchownat=E2=80=99=20when=20available.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * configure.ac: Detect whether ‘fchownat’ is available. * libguile/filesys.c (scm_chownat): Define a Scheme binding to ‘fchownat’ when available. * libguile/filesys.h (scm_chownat): Make it part of the API. * doc/ref/posix.texi (File System): Document it. --- configure.ac | 3 ++- doc/ref/posix.texi | 11 +++++++++++ libguile/filesys.c | 35 +++++++++++++++++++++++++++++++++++ libguile/filesys.h | 1 + 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index dea94a364..5f8389b82 100644 --- a/configure.ac +++ b/configure.ac @@ -482,7 +482,8 @@ AC_CHECK_HEADERS([assert.h crt_externs.h]) # AC_CHECK_FUNCS([DINFINITY DQNAN cexp chsize clog clog10 ctermid \ fesetround ftime ftruncate fchown fchmod fchdir readlinkat \ - symlinkat mkdirat renameat fchmodat unlinkat getcwd geteuid getsid \ + symlinkat mkdirat renameat fchmodat unlinkat fchownat \ + 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 dcea0352a..077ba8c79 100644 --- a/doc/ref/posix.texi +++ b/doc/ref/posix.texi @@ -817,6 +817,17 @@ unsupported at present). If @var{owner} or @var{group} is specified as @code{-1}, then that ID is not changed. @end deffn +@findex fchownat +@deffn {Scheme Procedure} chownat dir name owner group [flags] +@deffnx {C Function} scm_chownat (dir, name, owner, group, flags) +Like @code{chown}, but modify the owner and/or group of +the file named @var{name} in the directory referred to +by the file port @var{dir} instead. The optional argument +@var{flags} is a bitmask. If @code{AT_SYMLINK_NOFOLLOW} is +present, then @var{name} will not be dereferenced if it is a +symbolic link. +@end deffn + @findex fchmod @deffn {Scheme Procedure} chmod object mode @deffnx {C Function} scm_chmod (object, mode) diff --git a/libguile/filesys.c b/libguile/filesys.c index baa149a33..a319d9794 100644 --- a/libguile/filesys.c +++ b/libguile/filesys.c @@ -193,6 +193,41 @@ SCM_DEFINE (scm_chown, "chown", 3, 0, 0, #undef FUNC_NAME #endif /* HAVE_CHOWN */ +#ifdef HAVE_FCHOWNAT +SCM_DEFINE (scm_chownat, "chownat", 4, 1, 0, + (SCM dir, SCM name, SCM owner, SCM group, SCM flags), + "Like @code{chown}, but modify the owner and/or group of\n" + "the file named @var{name} in the directory referred to\n" + "by the file port @var{dir} instead. The optional argument\n" + "@var{flags} is a bitmask. If @code{AT_SYMLINK_NOFOLLOW} is\n" + "present, then @var{name} will not be dereferenced if it is a\n" + "symbolic link.") +#define FUNC_NAME s_scm_chownat +{ + int rv; + int dir_fdes; + int c_flags; + + if (SCM_UNBNDP (flags)) + c_flags = 0; + else + c_flags = scm_to_int (flags); + + SCM_VALIDATE_OPFPORT (SCM_ARG1, dir); + dir_fdes = SCM_FPORT_FDES (dir); + + STRING_SYSCALL (name, c_name, + rv = fchownat (dir_fdes, c_name, + scm_to_int (owner), scm_to_int (group), + c_flags)); + scm_remember_upto_here_1 (dir); + if (rv == -1) + SCM_SYSERROR; + return SCM_UNSPECIFIED; +} +#undef FUNC_NAME +#endif /* HAVE_FCHOWNAT */ + SCM_DEFINE (scm_open_fdes, "open-fdes", 2, 1, 0, diff --git a/libguile/filesys.h b/libguile/filesys.h index 37d084cd5..7673c8051 100644 --- a/libguile/filesys.h +++ b/libguile/filesys.h @@ -39,6 +39,7 @@ SCM_API scm_t_bits scm_tc16_dir; SCM_API SCM scm_chown (SCM object, SCM owner, SCM group); +SCM_API SCM scm_chownat (SCM dir, SCM object, SCM owner, SCM group, SCM flags); SCM_API SCM scm_chmod (SCM object, SCM mode); SCM_API SCM scm_chmodat (SCM dir, SCM pathname, SCM mode, SCM flags); SCM_API SCM scm_umask (SCM mode); -- 2.30.2