From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.formilux.org (mta1.formilux.org [51.159.59.229]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E5503E63B8 for ; Mon, 27 Apr 2026 17:47:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.159.59.229 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777312081; cv=none; b=Th5lFD0L9tGPK/u3oj7XyrEVshDJAhzPNQWbizFewwcCB6E1uTPY48Y2whDtTdNLJh2K4u4/SZ2G5VQu8f14nJHvYUeUbnJqHhCVd8l+WokuDve8GkznFQKJ3NgFmrHe58bxLix2ba/RMWXGAv8gaDaJtfpR4GkX8byV4tUp710= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777312081; c=relaxed/simple; bh=9p2s9kIDUFEO+vzh8Uzsz1gmp4c2/L01BzqzNZ+JEYs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=X8aoZNbNge200sriGJL/29xMLWgr+Mxjj3aPbcqiVgiB2IlYV+fnVtQlEPvLD02R8v9eyZQDfA3j3RWCJNDM70lYKGan+mHDhE1nqlgsVvJOt/nIu2u+HwBxraZ6wrazlhMwVpJyh6f3YYfYiQ2fNblCWYREPJ3+wjWSDhGizXg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b=Jk81Ic7W; arc=none smtp.client-ip=51.159.59.229 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b="Jk81Ic7W" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1wt.eu; s=mail; t=1777312071; bh=GKFkpScDEwYbAMp7PHdockGuDOBZXhkSd7pWEhteCOQ=; h=From:Message-ID:From; b=Jk81Ic7WNNz6uC5EO00cyvnHByUDviVxkyY2LEyqcOyJ+mePuRhbD2jVgqO7vCFJF voY4D2FfXRGVKeNaaYyXbyFkGC5tNfLr0qQKT6f34CNnhobkgmHCdmbN0ONoApudOJ ZS3v0lQ6GdnwusX2gWe06a3K6TuBzVYGJlrzvHtc= Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by mta1.formilux.org (Postfix) with ESMTP id 5B83FC0B7D; Mon, 27 Apr 2026 19:47:51 +0200 (CEST) Date: Mon, 27 Apr 2026 19:47:51 +0200 From: Willy Tarreau To: Thomas =?iso-8859-1?Q?Wei=DFschuh?= Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/3] tools/nolibc: simplify mode handling in open() and openat() Message-ID: References: <20260419-nolibc-open-mode-v1-0-8dc5a960daa7@weissschuh.net> <20260419-nolibc-open-mode-v1-3-8dc5a960daa7@weissschuh.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Hi Thomas! On Mon, Apr 27, 2026 at 07:28:22PM +0200, Thomas Weißschuh wrote: > On 2026-04-19 22:16:01+0200, Thomas Weißschuh wrote: > > On 2026-04-19 18:08:07+0200, Willy Tarreau wrote: > > > On Sun, Apr 19, 2026 at 05:29:05PM +0200, Thomas Weißschuh wrote: > > > The macro passes the "mode" argument to _open() when it's present, and when > > > it's absent, it passes the next one in the _OPT_ARG() macro, which is zero. > > > > > > E.g.: > > > > > > #include > > > > > > #define _OPT_ARG(a0, a1, ...) a1 > > > #define open(path, flags, mode...) _open(path, flags, _OPT_ARG(0, ##mode, 0)) > > > > > > int _open(const char *path, int flags, int mode) > > > { > > > return printf("path=%s flags=%d mode=%d\n", path, flags, mode); > > > } > > > > This is exactly what I tried to do. But ,## only works for the > > non-first argument and I didn't think of adding a dummy argument, so I > > ended up with __VA_OPT__. > > > > As open() is defined to be a function, I used the same name for both the > > vararg macro and the underlying function. I slightly prefer that, but if > > you object, let's rename it to _open(). > > > > > int main(void) > > > { > > > open("file1", 12); > > > open("file2", 34, 56); > > > return 0; > > > } > > > > > > $ ./a.out > > > path=file1 flags=12 mode=0 > > > path=file2 flags=34 mode=56 > > > > > > And this one works even on very old compilers (gcc-3.4 successfully tested). > > > > Let's use that. > > Sashiko rightfully complains[0] that '#define open()' will also apply to > struct member functions called open(). So I'm holding off on this patch > for now. Ah indeed, that's a good point, I hadn't thought about these ones. And yes, this can easily happen. Willy