mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
Define ‘symlinkat’ wrapper when supported.
* configure.ac: Detect whether ‘symlinkat’ exists. * libguile/filesys.c (scm_symlinkat): Define a Scheme binding when it exists. * libguile/filesys.h: Make the binding part of the public C API. * doc/ref/posix.texi (File System): Document the binding. * test-suite/tests/filesys.test ("symlinkat"): Test it. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
parent
9ffd297249
commit
6c350b6094
5 changed files with 58 additions and 1 deletions
|
@ -517,7 +517,7 @@ AC_CHECK_HEADERS([crt_externs.h])
|
|||
#
|
||||
AC_CHECK_FUNCS([DINFINITY DQNAN cexp chsize clog clog10 ctermid \
|
||||
fesetround ftime ftruncate fchown fchmod fchdir readlinkat \
|
||||
getcwd geteuid getsid \
|
||||
symlinkat getcwd geteuid getsid \
|
||||
gettimeofday getuid getgid gmtime_r ioctl lstat mkdir mkdtemp mknod \
|
||||
nice readlink rmdir setegid seteuid \
|
||||
setuid setgid setpgid setsid sigaction siginterrupt stat64 \
|
||||
|
|
|
@ -909,6 +909,12 @@ Create a symbolic link named @var{newpath} with the value (i.e., pointing to)
|
|||
@var{oldpath}. The return value is unspecified.
|
||||
@end deffn
|
||||
|
||||
@deffn {Scheme Procedure} symlinkat dir oldpath newpath
|
||||
@deffnx {C Function} scm_symlinkat (dir, oldpath, newpath)
|
||||
Like @code{symlink}, but resolve @var{newpath} relative to
|
||||
the directory referred to by the file port @var{dir}.
|
||||
@end deffn
|
||||
|
||||
@deffn {Scheme Procedure} mkdir path [mode]
|
||||
@deffnx {C Function} scm_mkdir (path, mode)
|
||||
Create a new directory named by @var{path}. If @var{mode} is omitted
|
||||
|
|
|
@ -1032,6 +1032,29 @@ SCM_DEFINE (scm_symlink, "symlink", 2, 0, 0,
|
|||
#undef FUNC_NAME
|
||||
#endif /* HAVE_SYMLINK */
|
||||
|
||||
#ifdef HAVE_SYMLINKAT
|
||||
SCM_DEFINE (scm_symlinkat, "symlinkat", 3, 0, 0,
|
||||
(SCM dir, SCM oldpath, SCM newpath),
|
||||
"Like @code{symlink}, but resolve @var{newpath} relative\n"
|
||||
"to the directory referred to by the file port @var{dir}.")
|
||||
#define FUNC_NAME s_scm_symlinkat
|
||||
{
|
||||
int val;
|
||||
int fdes;
|
||||
|
||||
SCM_VALIDATE_OPFPORT (SCM_ARG1, dir);
|
||||
fdes = SCM_FPORT_FDES (dir);
|
||||
STRING2_SYSCALL (oldpath, c_oldpath,
|
||||
newpath, c_newpath,
|
||||
val = symlinkat (c_oldpath, fdes, c_newpath));
|
||||
scm_remember_upto_here_1 (dir);
|
||||
if (val != 0)
|
||||
SCM_SYSERROR;
|
||||
return SCM_UNSPECIFIED;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
#endif /* HAVE_SYMLINKAT */
|
||||
|
||||
/* Static helper function for choosing between readlink
|
||||
and readlinkat. */
|
||||
static int
|
||||
|
|
|
@ -62,6 +62,7 @@ SCM_API SCM scm_select (SCM reads, SCM writes, SCM excepts, SCM secs, SCM msecs)
|
|||
SCM_API SCM scm_fcntl (SCM object, SCM cmd, SCM value);
|
||||
SCM_API SCM scm_fsync (SCM object);
|
||||
SCM_API SCM scm_symlink (SCM oldpath, SCM newpath);
|
||||
SCM_API SCM scm_symlinkat (SCM dir, SCM oldpath, SCM newpath);
|
||||
SCM_API SCM scm_readlink (SCM path);
|
||||
SCM_API SCM scm_lstat (SCM str);
|
||||
SCM_API SCM scm_copy_file (SCM oldfile, SCM newfile);
|
||||
|
|
|
@ -367,3 +367,30 @@
|
|||
|
||||
(false-if-exception (delete-file (test-symlink)))
|
||||
(false-if-exception (delete-file (test-file))))
|
||||
|
||||
(with-test-prefix "symlinkat"
|
||||
(pass-if-equal "create" (test-file)
|
||||
(unless (defined? 'symlinkat)
|
||||
(throw 'unsupported))
|
||||
(call-with-port
|
||||
(open "." O_RDONLY)
|
||||
(lambda (port)
|
||||
(symlinkat port (test-file) (test-symlink))
|
||||
(readlink (test-symlink)))))
|
||||
(false-if-exception (delete-file (test-symlink)))
|
||||
|
||||
(pass-if-exception "not a port" exception:wrong-type-arg
|
||||
(unless (defined? 'symlinkat)
|
||||
(throw 'unsupported))
|
||||
(symlinkat "bogus" (test-file) (test-symlink)))
|
||||
|
||||
(pass-if-exception "not a file port" exception:wrong-type-arg
|
||||
(unless (defined? 'symlinkat)
|
||||
(throw 'unsupported))
|
||||
(symlinkat (open-input-string "") (test-file) (test-symlink)))
|
||||
|
||||
(pass-if-exception "closed port" exception:wrong-type-arg
|
||||
(unless (defined? 'symlinkat)
|
||||
(throw 'unsupported))
|
||||
(symlinkat (call-with-port (open "." O_RDONLY) identity)
|
||||
(test-file) (test-symlink))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue