summaryrefslogtreecommitdiff
path: root/libguile
diff options
context:
space:
mode:
authorMaxime Devos <maximedevos@telenet.be>2021-11-16 11:06:35 +0000
committerLudovic Courtès <ludo@gnu.org>2022-10-21 17:41:10 +0200
commitcf255dd3a4f01da5e88c6da3738e7745ad8b9594 (patch)
tree165543a2197864ef12dbde8eae8a03e431a48911 /libguile
parent0af3c2f5092cb52ee0ea0b4ab2b1285237441a85 (diff)
downloadguile-cf255dd3a4f01da5e88c6da3738e7745ad8b9594.tar.gz
Define a Scheme binding to ‘fstatat’ when available.
* configure.ac: Detect if ‘fstatat’ is defined. * libguile/filesys.c (scm_statat): Define a Scheme binding to ‘fstatat’. * libguile/filesys.h (scm_statat): Make it part of the C API. * doc/ref/posix.texi (File System): Document it. * libguile/syscalls.h (fstatat_or_fstatat64): Choose between ‘fstatat’ and ‘fstatat64’. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'libguile')
-rw-r--r--libguile/filesys.c39
-rw-r--r--libguile/filesys.h1
-rw-r--r--libguile/syscalls.h1
3 files changed, 41 insertions, 0 deletions
diff --git a/libguile/filesys.c b/libguile/filesys.c
index af00a98d4..6fa641d16 100644
--- a/libguile/filesys.c
+++ b/libguile/filesys.c
@@ -588,6 +588,45 @@ SCM_DEFINE (scm_stat, "stat", 1, 1, 0,
}
#undef FUNC_NAME
+#ifdef HAVE_FSTATAT
+SCM_DEFINE (scm_statat, "statat", 2, 1, 0,
+ (SCM dir, SCM filename, SCM flags),
+ "Like @code{stat}, but resolve @var{filename} relative to the\n"
+ "directory referred to by the file port @var{dir} instead.\n\n"
+ "The optional argument @var{flags} argument can be\n"
+ "@code{AT_SYMLINK_NOFOLLOW}, in which case @var{filename} will\n"
+ "not be dereferenced even if it is a symbolic link.")
+#define FUNC_NAME s_scm_statat
+{
+ int rv;
+ int dir_fdes;
+ int c_flags;
+ struct stat_or_stat64 stat_temp;
+
+ 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 (filename, c_filename,
+ rv = fstatat_or_fstatat64 (dir_fdes, c_filename,
+ &stat_temp, c_flags));
+ scm_remember_upto_here_1 (dir);
+ if (rv != 0)
+ {
+ int en = errno;
+ SCM_SYSERROR_MSG ("~A: ~S",
+ scm_list_2 (scm_strerror (scm_from_int (en)), filename),
+ en);
+ }
+ return scm_stat2scm (&stat_temp);
+}
+#undef FUNC_NAME
+#endif /* HAVE_FSTATAT */
+
SCM_DEFINE (scm_lstat, "lstat", 1, 0, 0,
(SCM str),
"Similar to @code{stat}, but does not follow symbolic links, i.e.,\n"
diff --git a/libguile/filesys.h b/libguile/filesys.h
index 7673c8051..8af0f989a 100644
--- a/libguile/filesys.h
+++ b/libguile/filesys.h
@@ -48,6 +48,7 @@ SCM_API SCM scm_open (SCM path, SCM flags, SCM mode);
SCM_API SCM scm_close (SCM fd_or_port);
SCM_API SCM scm_close_fdes (SCM fd);
SCM_API SCM scm_stat (SCM object, SCM exception_on_error);
+SCM_API SCM scm_statat (SCM dir, SCM filename, SCM flags);
SCM_API SCM scm_link (SCM oldpath, SCM newpath);
SCM_API SCM scm_rename (SCM oldname, SCM newname);
SCM_API SCM scm_renameat (SCM olddir, SCM oldname, SCM newdir, SCM newname);
diff --git a/libguile/syscalls.h b/libguile/syscalls.h
index 30b99c193..37d532e60 100644
--- a/libguile/syscalls.h
+++ b/libguile/syscalls.h
@@ -65,6 +65,7 @@
# define readdir_r_or_readdir64_r readdir_r
#endif
#define stat_or_stat64 CHOOSE_LARGEFILE(stat,stat64)
+#define fstatat_or_fstatat64 CHOOSE_LARGEFILE(fstatat,fstatat64)
#define truncate_or_truncate64 CHOOSE_LARGEFILE(truncate,truncate64)
#define scm_from_off_t_or_off64_t CHOOSE_LARGEFILE(scm_from_off_t,scm_from_int64)
#define scm_from_ino_t_or_ino64_t CHOOSE_LARGEFILE(scm_from_ulong,scm_from_uint64)