From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxime Devos Newsgroups: gmane.lisp.guile.devel Subject: [PATCH v2 04/14] =?UTF-8?q?Define=20=E2=80=98symlinkat=E2=80=99?= =?UTF-8?q?=20wrapper=20when=20supported.?= Date: Tue, 16 Nov 2021 11:06:27 +0000 Message-ID: <20211116110637.125579-5-maximedevos@telenet.be> References: <175c3a6572e832d84927937b309a3095cadf5702.camel@telenet.be> <20211116110637.125579-1-maximedevos@telenet.be> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19843"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Maxime Devos To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Tue Nov 16 12:14:46 2021 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mmwQI-0004zl-07 for guile-devel@m.gmane-mx.org; Tue, 16 Nov 2021 12:14:46 +0100 Original-Received: from localhost ([::1]:44644 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmwQH-00054l-1W for guile-devel@m.gmane-mx.org; Tue, 16 Nov 2021 06:14:45 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:33650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmwOq-0003t1-N2 for guile-devel@gnu.org; Tue, 16 Nov 2021 06:13:16 -0500 Original-Received: from [2a02:1800:120:4::f00:d] (port=51418 helo=newton.telenet-ops.be) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmwOl-0005yu-QV for guile-devel@gnu.org; Tue, 16 Nov 2021 06:13:16 -0500 Original-Received: from baptiste.telenet-ops.be (baptiste.telenet-ops.be [IPv6:2a02:1800:120:4::f00:13]) by newton.telenet-ops.be (Postfix) with ESMTPS id 4Htjtg5L2wzMvwBL for ; Tue, 16 Nov 2021 12:06:51 +0100 (CET) Original-Received: from localhost.localdomain ([IPv6:2a02:1811:8c09:9d00:3c5f:2eff:feb0:ba5a]) by baptiste.telenet-ops.be with bizsmtp id Jz6j2600Q4UW6Th01z6pHz; Tue, 16 Nov 2021 12:06:50 +0100 X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211116110637.125579-1-maximedevos@telenet.be> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1637060810; bh=gZTJm5QJrXq2376rNUE6O5Tu7bR7cNUvtjrN6ZpcVYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UvDxu11GD7H7xxpUC477izyP0pk4APou/Hdy+BGUa5zX3gintSctbcLKrJZt5nU76 YW3KJcfzWW469HlPhU3hgpm83wLVYmcmvQ5TU1x4scODYaa45+5MiHzKLiFy7iFZrl /ls0mheqHQZQxwrj1Xig13C8Z0Nc1RrV0zJ9XYjv0myphyKdMwdno19d33h/xghtmA lcQVWaPsAOYSU02Aw/wArgRRVBEbFLU1lHhsxO/cyqNw6yGuqMmLpEe1Tqm2CWglN/ VT+C3281pIt9OCu+AnXr6l7yVCaRWE7txiKoTWYW9wcTIfyVyU0ds1tR52PqrKt4G4 Cyy9GVjWphwDw== X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a02:1800:120:4::f00:d (failed) Received-SPF: pass client-ip=2a02:1800:120:4::f00:d; envelope-from=maximedevos@telenet.be; helo=newton.telenet-ops.be X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:20940 Archived-At: * 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. --- configure.ac | 2 +- doc/ref/posix.texi | 6 ++++++ libguile/filesys.c | 23 +++++++++++++++++++++++ libguile/filesys.h | 1 + test-suite/tests/filesys.test | 27 +++++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index ddf330d96..b2e9ef3e9 100644 --- a/configure.ac +++ b/configure.ac @@ -485,7 +485,7 @@ 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 \ - getcwd geteuid getsid \ + symlinkat 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 b6deffd43..a329eec39 100644 --- a/doc/ref/posix.texi +++ b/doc/ref/posix.texi @@ -891,6 +891,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 diff --git a/libguile/filesys.c b/libguile/filesys.c index c5bedec07..bfd223434 100644 --- a/libguile/filesys.c +++ b/libguile/filesys.c @@ -1045,6 +1045,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 diff --git a/libguile/filesys.h b/libguile/filesys.h index a3b257c12..d181aca52 100644 --- a/libguile/filesys.h +++ b/libguile/filesys.h @@ -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); diff --git a/test-suite/tests/filesys.test b/test-suite/tests/filesys.test index 7feb3492f..64bf92333 100644 --- a/test-suite/tests/filesys.test +++ b/test-suite/tests/filesys.test @@ -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)))) -- 2.30.2