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 0F3E13C343B for ; Thu, 2 Jul 2026 11:38:43 +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=1782992327; cv=none; b=IHRCJroA9gfsKvPIkM46pHE0+YIs/gFE2syqjrtdA1bvw7kW4exrRRpravINakD9cvGX76q/7pPWcSKanfd5NkTNwIS3o3/sDHCmFZp9Qf5Dz8EJhQK95t2yZFijMhjbUT3ULt3BRcchSD9GzQZtHPnMTe8PcEDwEYkeWPflns0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782992327; c=relaxed/simple; bh=2h6YlLR2i/3k0IgMzKwxWsAfE1Qy5EeuMFzmnSWOOaY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hgLsVNiHLoKe3QwQBxwDosADeQnroN2uOj6D7RNm5363PTKOYIEaKgshLIzh8R85nEQ/BnKS4he8IGmQPcDD2LONJFkAud7lUvtbDbJYazS8AW0U3rPr3q2xT6rEMhKAt4Iz8Tn+vhjiYzu6I8TAq4u93t9ILmYTD1D0n0YRRfM= 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=hkKtQ6Jv; 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="hkKtQ6Jv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1wt.eu; s=mail; t=1782991983; bh=dDmWhwJbVRbo+iZr6VMiaC+Q71S789V9MKm+nkbbztM=; h=From:Message-ID:From; b=hkKtQ6Jv8x1lOcZjq1tLwi9WizzHHsWTQ3321zRQjnD5nGFDTb+i7ogUND/aG1LNT QHOQ+1AfZQ0UvQX/ja7XY8hkAXt67S7thrdkCslbLlY2dzgIR5AI80ljmXURgAvzeR W6N0z26J8sZSaiSe6+TT7Qii05datW+LIMPAvWsY= Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by mta1.formilux.org (Postfix) with ESMTP id B2AF0C0D6B; Thu, 02 Jul 2026 13:33:03 +0200 (CEST) Date: Thu, 2 Jul 2026 13:33:03 +0200 From: Willy Tarreau To: Daniel Palmer Cc: linux@weissschuh.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 1/3] tools/nolibc: unistd: Add getcwd() Message-ID: References: <20260702085101.3304547-1-daniel@thingy.jp> <20260702085101.3304547-2-daniel@thingy.jp> 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=us-ascii Content-Disposition: inline In-Reply-To: <20260702085101.3304547-2-daniel@thingy.jp> Hi Daniel, On Thu, Jul 02, 2026 at 05:50:59PM +0900, Daniel Palmer wrote: > Add getcwd() for getting the current working directory. > > The behaviour matches what musl is doing except for one > important difference: If the passed buf is NULL musl (and glibc) > uses a big buffer on the stack and that is then strdup()'d and > returned. > > According to the man page for getcwd() this is a glibc extension > and I don't think we need it in nolibc. I entirely agree. > Signed-off-by: Daniel Palmer > > --- > tools/include/nolibc/unistd.h | 42 +++++++++++++++++++++++++++++++++++ > 1 file changed, 42 insertions(+) > > diff --git a/tools/include/nolibc/unistd.h b/tools/include/nolibc/unistd.h > index 79599ceef45d..2e0edbc26315 100644 > --- a/tools/include/nolibc/unistd.h > +++ b/tools/include/nolibc/unistd.h > @@ -73,6 +73,48 @@ int ftruncate(int fd, off_t length) > return __sysret(_sys_ftruncate(fd, length)); > } > > +/* > + * char *getcwd(char *buf, size_t size); > + */ > + > +static __attribute__((unused)) > +int _sys_getcwd(char *buf, size_t size) > +{ > + return __nolibc_syscall2(__NR_getcwd, buf, size); > +} > + > +static __attribute__((unused)) > +char *getcwd(char *buf, size_t size) > +{ > + int ret; > + > + /* Unlike other libc's we don't handle passing NULL for buf */ > + if (!buf || !size) { > + SET_ERRNO(EINVAL); > + return NULL; > + } > + > + ret = __sysret(_sys_getcwd(buf, size)); > + > + /* On error return NULL, __sysret() above will have set errno */ > + if (ret < 0) > + return NULL; > + > + /* Handle no path being written or the kernel putting > + * "(unreachable)" into the buffer instead of a path. > + * This matches what musl is doing. > + */ > + if (ret == 0 || buf[0] != '/') { > + SET_ERRNO(ENOENT); > + return NULL; > + } > + > + /* ret must be the number of bytes written at this point, > + * so return the pointer to buf. > + */ > + return buf; > +} > + > static __attribute__((unused)) > int msleep(unsigned int msecs) > { LGTM. Acked-by: Willy Tarreau Willy