summaryrefslogtreecommitdiff
path: root/libguile
diff options
context:
space:
mode:
authorMaxime Devos <maximedevos@telenet.be>2021-11-16 11:06:34 +0000
committerLudovic Courtès <ludo@gnu.org>2022-10-21 17:40:37 +0200
commit0af3c2f5092cb52ee0ea0b4ab2b1285237441a85 (patch)
tree128578b1793f01222e95aff59f185cfd3f64f879 /libguile
parent3b45185d8f40b5c41abfe15571550ce1a7fd4011 (diff)
downloadguile-0af3c2f5092cb52ee0ea0b4ab2b1285237441a85.tar.gz
Define a Scheme binding to ‘fchownat’ when it exists.
* 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. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'libguile')
-rw-r--r--libguile/filesys.c35
-rw-r--r--libguile/filesys.h1
2 files changed, 36 insertions, 0 deletions
diff --git a/libguile/filesys.c b/libguile/filesys.c
index ee7fc5bfa..af00a98d4 100644
--- a/libguile/filesys.c
+++ b/libguile/filesys.c
@@ -180,6 +180,41 @@ SCM_DEFINE (scm_chown, "chown", 3, 0, 0,
#undef FUNC_NAME
#endif /* HAVE_CHOWN */
+#ifdef HAVE_FCHOWNAT
+SCM_DEFINE (scm_chownat, "chown-at", 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);