From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id ADA8824AC1 for ; Thu, 23 May 2024 15:12:30 +0200 (CEST) Received: (qmail 25739 invoked by uid 550); 23 May 2024 13:12:25 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 25689 invoked from network); 23 May 2024 13:12:24 -0000 Date: Thu, 23 May 2024 09:12:38 -0400 From: Rich Felker To: T A Cc: musl@lists.openwall.com Message-ID: <20240523131236.GY10433@brightrain.aerifal.cx> References: <20240423234355.2414567-1-Tony.Ambardar@gmail.com> <20240507032832.2432241-1-Tony.Ambardar@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] Re: [PATCH v3] add renameat2 linux syscall wrapper On Mon, May 20, 2024 at 06:42:55PM -0700, T A wrote: > Hi Rich, > > I think this v3 patch addressed all your suggestions. Are any other > improvements needed? Looks good. I'll go ahead and merge. > > Thanks, > Tony > > On Mon, May 6, 2024, 20:28 Tony Ambardar wrote: > > > This syscall is available since Linux 3.15 and also implemented in glibc > > from version 2.28. It is commonly used in filesystem or security contexts. > > > > Constants RENAME_NOREPLACE, RENAME_EXCHANGE, RENAME_WHITEOUT are guarded by > > _GNU_SOURCE as with glibc. > > > > Signed-off-by: Tony Ambardar > > --- > > v2 -> v3: > > * call SYS_renameat first if applicable > > * drop unneeded error code handling > > > > v1 -> v2: > > * align related constants > > * drop 'int' from 'unsigned int' > > * add fallback to SYS_renameat where applicable > > --- > > include/stdio.h | 7 +++++++ > > src/linux/renameat2.c | 11 +++++++++++ > > 2 files changed, 18 insertions(+) > > create mode 100644 src/linux/renameat2.c > > > > diff --git a/include/stdio.h b/include/stdio.h > > index cb858618..4ea4c170 100644 > > --- a/include/stdio.h > > +++ b/include/stdio.h > > @@ -158,6 +158,13 @@ char *ctermid(char *); > > #define L_ctermid 20 > > #endif > > > > +#if defined(_GNU_SOURCE) > > +#define RENAME_NOREPLACE (1 << 0) > > +#define RENAME_EXCHANGE (1 << 1) > > +#define RENAME_WHITEOUT (1 << 2) > > + > > +int renameat2(int, const char *, int, const char *, unsigned); > > +#endif > > > > #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ > > || defined(_BSD_SOURCE) > > diff --git a/src/linux/renameat2.c b/src/linux/renameat2.c > > new file mode 100644 > > index 00000000..b8060388 > > --- /dev/null > > +++ b/src/linux/renameat2.c > > @@ -0,0 +1,11 @@ > > +#define _GNU_SOURCE > > +#include > > +#include "syscall.h" > > + > > +int renameat2(int oldfd, const char *old, int newfd, const char *new, > > unsigned flags) > > +{ > > +#ifdef SYS_renameat > > + if (!flags) return syscall(SYS_renameat, oldfd, old, newfd, new); > > +#endif > > + return syscall(SYS_renameat2, oldfd, old, newfd, new, flags); > > +} > > -- > > 2.34.1