From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (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 C421021507F for ; Sun, 4 Jan 2026 09:13:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767518008; cv=none; b=gh9Q1qbyutafbJd5Q0E3vhff+hFROP4zTZSypn7ww7cEbr3USaSzkqIVAtCViXI7dgIGW9tQt0ETC6f5h1L/z/G0tB+BitdwChpG9HvLdk4cSh3q3o9R4IT+LY5aSKwf1qPjakvrpfTO6Qm9ne0jOl6U4HV+/nZ7RzpfZTW2Rmo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767518008; c=relaxed/simple; bh=Cx+wcsilwlKQOuXno56fVqxahQy/rDnGHr0yi3k28RA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Iqyu5GSsPCEfy2IOWg6Zw/y5lo+hPBH+rk3uO/ZQIyYTc3c76FGMoDH/m1D6Y1IhAk66RlLJc5xrpkj9sC7pndPcIE8yosfKebYG5L8kQEYVds3yn1SxiT2otHyseV8/jTUw0HDEEjtHyBqO6IZJ/Ute7ZwODk3fMSiU2hz8eTg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=feNBWqpb; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="feNBWqpb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1767518004; bh=Cx+wcsilwlKQOuXno56fVqxahQy/rDnGHr0yi3k28RA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=feNBWqpbiFOXIOH+H9+yq7Ip7b35TVPfWj/6227wyg3cATktvux2of8x9n9OMUjd1 kXd/vhP8Z/n6xreH1haxsC5n2G1yvLQFzqYDQyjsFU140/o+s95HCCHGUD9OKyPtRq 6QOBONsqiUZWnGboRyc5cD4QUYEqsL5rUSj51y+k= Date: Sun, 4 Jan 2026 10:13:24 +0100 From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: Daniel Palmer Cc: w@1wt.eu, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] tools/nolibc: Add fread() to stdio.h Message-ID: References: <20260104083837.1390041-1-daniel@thingy.jp> <20260104083837.1390041-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: <20260104083837.1390041-2-daniel@thingy.jp> On 2026-01-04 17:38:36+0900, Daniel Palmer wrote: > Add a very basic version of fread() like we already have for fwrite(). > > Signed-off-by: Daniel Palmer > --- > tools/include/nolibc/stdio.h | 35 ++++++++++++++++++++++++++++++++++- > 1 file changed, 34 insertions(+), 1 deletion(-) > > diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h > index 1f16dab2ac88..21569ebae824 100644 > --- a/tools/include/nolibc/stdio.h > +++ b/tools/include/nolibc/stdio.h > @@ -170,7 +170,7 @@ int putchar(int c) > } > > > -/* fwrite(), puts(), fputs(). Note that puts() emits '\n' but not fputs(). */ > +/* fwrite(), fread(), puts(), fputs(). Note that puts() emits '\n' but not fputs(). */ > > /* internal fwrite()-like function which only takes a size and returns 0 on > * success or EOF on error. It automatically retries on short writes. > @@ -204,6 +204,39 @@ size_t fwrite(const void *s, size_t size, size_t nmemb, FILE *stream) > return written; > } > > +/* internal fread()-like function which only takes a size and returns 0 on > + * success or EOF on error. It automatically retries on short reads. > + */ > +static __attribute__((unused)) > +int _fread(void *buf, size_t size, FILE *stream) > +{ > + ssize_t ret; > + int fd = fileno(stream); Switch these two lines around. > + > + while (size) { > + ret = read(fd, buf, size); > + if (ret <= 0) > + return EOF; > + size -= ret; > + buf += ret; > + } > + return 0; > +} > + > + > +static __attribute__((unused)) > +size_t fread(void *s, size_t size, size_t nmemb, FILE *stream) > +{ > + size_t readed; I really don't like this name. Maybe 'nread'? > + > + for (readed = 0; readed < nmemb; readed++) { > + if (_fread(s, size, stream) != 0) > + break; > + s += size; > + } > + return readed; > +} > + > static __attribute__((unused)) > int fputs(const char *s, FILE *stream) > { > -- > 2.51.0 >