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 11/14] =?UTF-8?q?Define=20a=20Scheme=20binding=20to=20?= =?UTF-8?q?=E2=80=98fchownat=E2=80=99=20when=20it=20exists.?= Date: Tue, 16 Nov 2021 11:06:34 +0000 Message-ID: <20211116110637.125579-12-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="22896"; 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:15:16 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 1mmwQl-0005aS-QM for guile-devel@m.gmane-mx.org; Tue, 16 Nov 2021 12:15:15 +0100 Original-Received: from localhost ([::1]:45784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmwQk-0005qQ-P2 for guile-devel@m.gmane-mx.org; Tue, 16 Nov 2021 06:15:14 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:33664) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmwOs-0003vG-5e for guile-devel@gnu.org; Tue, 16 Nov 2021 06:13:19 -0500 Original-Received: from newton.telenet-ops.be ([195.130.132.45]:60182) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmwOq-0005ze-5a for guile-devel@gnu.org; Tue, 16 Nov 2021 06:13:17 -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 4Htjty5ZHGzMvs6n for ; Tue, 16 Nov 2021 12:07:06 +0100 (CET) Original-Received: from localhost.localdomain ([IPv6:2a02:1811:8c09:9d00:3c5f:2eff:feb0:ba5a]) by baptiste.telenet-ops.be with bizsmtp id Jz6j2600Q4UW6Th01z6qJF; 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=1637060811; bh=o4oUjBKE9DVl1IHEL3xim/f5skWjz8nyS5X231Yl7WY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EtBQvHIvGaPk+HdXUsfE/hgS//zFYWG320vWuMjb+x67FfjVKyNZsBYEblXodK2HE jskKPUqcTeheekbTLi3IxnyKOEe7WQtqNO7lh635DKUubP33HENif3+Vo6azgX+qiN bs50qlhLpxy5+rFkvviafqYDlu1jSutGE+BYhxOky0wTg/MA4LVJEElJ89B6r0NcoE mfLhu89aRafzs7qwP0gGM3LWbVFsPo6wWXO8oGvr5DfuSq5f6o149lPMFwtwlxqB+3 R004Hx4vOcDls5ZNHNJ0emZZFlqJgmHR04oSdMtK2AbNhAvLCpM6FxB1gQg3HGcG0T 6UUrjn+sXAerg== Received-SPF: pass client-ip=195.130.132.45; envelope-from=maximedevos@telenet.be; helo=newton.telenet-ops.be X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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:20942 Archived-At: * 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 | 4 ++-- doc/ref/posix.texi | 11 +++++++++++ libguile/filesys.c | 35 +++++++++++++++++++++++++++++++++++ libguile/filesys.h | 1 + 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index e1c090321..dcb6bceb5 100644 --- a/configure.ac +++ b/configure.ac @@ -478,14 +478,14 @@ AC_CHECK_HEADERS([assert.h crt_externs.h]) # isblank - available as a GNU extension or in C99 # _NSGetEnviron - Darwin specific # strcoll_l, newlocale, uselocale, utimensat, futimens, fchmodat, -# unlinkat - POSIX.1-2008 +# unlinkat, fchownat - POSIX.1-2008 # strtol_l - non-POSIX, found in glibc # fork - unavailable on Windows # sched_getaffinity, sched_setaffinity - GNU extensions (glibc) # sendfile - non-POSIX, found in glibc # AC_CHECK_FUNCS([DINFINITY DQNAN cexp chsize clog clog10 ctermid \ - fesetround ftime ftruncate fchown fchmod fchdir readlinkat \ + fesetround ftime ftruncate fchown fchownat fchmod fchdir readlinkat \ fchmodat symlinkat mkdirat renameat unlinkat getcwd geteuid getsid \ gettimeofday getuid getgid gmtime_r ioctl lstat mkdir mkdtemp mknod \ nice readlink rename rmdir setegid seteuid \ diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi index ad10585d9..3d06f1c73 100644 --- a/doc/ref/posix.texi +++ b/doc/ref/posix.texi @@ -784,6 +784,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 7e6d89626..c257bb59c 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, "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); -- 2.30.2