From nobody Sat Feb 7 17:19:45 2026 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0C6A239E76 for ; Sun, 4 Jan 2026 08:39:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767515942; cv=none; b=C3hpKokYAArpn1uoKZPw+BNQZG/9s1jI0ClWo6vtm2elLp4MiS0hiRN8urQ2iItHce0b9DWsszrl+nd8gtLW0H0wuzvqGIVAI4k/se0xEtmcknQINXXoWALOsbRKpePGZdwThz0Y/3WJdCMMBm9C6K+2Fo7bLDULziz2wme64NM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767515942; c=relaxed/simple; bh=CWA1Ka6vidYHhyoTmWtUKsLFvKdVAuDZSaOvqB0pLJc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S08hYtxhl/tZ/vTkn+HFAaTY3PfKxaqahHmaI7XedOJhemLdZ6Fhb8lJrHYPRfxWoq44yEAovToW2o2/mYxNJ2qioXpe4yInSz6r2o58YeQAVgsVb/6+K9UH6u6Wg7Xi9QWi2tjUik8JJBg15RRvNhgRaRpLhk28MfKP6aLPDs0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp; spf=pass smtp.mailfrom=0x0f.com; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b=HIdu2zlW; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0x0f.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b="HIdu2zlW" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-7bb710d1d1dso18586643b3a.1 for ; Sun, 04 Jan 2026 00:39:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1767515940; x=1768120740; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wM46KKxyon7nRf7rG3geEZWmJ0mAF86Y4iAnb9L5Q04=; b=HIdu2zlW2m/sKuOw8Fbcg8ZI0uok+fbWmb5MYq8GBspHRizVtAzqNo5393DO9yFzLu S5tdnDpMLomvr/U4ZS/vhHWo7AdZa9Q5RoQSlr1+PxL7HOj5ohLvyAcCrbQMuO2F+SU6 mrh1oaC4cVfz3IJd7bO9P4MQ6H/fuRJUvcM7s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767515940; x=1768120740; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=wM46KKxyon7nRf7rG3geEZWmJ0mAF86Y4iAnb9L5Q04=; b=a/EHcw7Nz6U0S//q2AvXdNHB+Wu8h7GeD2PUD2KSBB4gP5I3HVF4prUr1cUG0k3tMX 3F1OycXnQMPW8wLsS1u01gnjAHMfY/mWTUo+UADQTNZh7ILHMW3EO01hzeZQhQukNBbJ 5tPvk7S0QHFZ4jYu+EmGIq9jDVvxSFpXmEpUihJM/32v9Lvrh462iDq/F657Fs2Fvgx1 mqPs83PhYOMRq30pH1SVFpvNrJsvj0VEURG0ggrRleliV6LTA20oZrtlYrAW9xNeIJ9F 7+BIWgZYs86keBVrYFXMKRpOnSmbQX3loN7zVyayLylGWiM928Ijjh+3zb//6Qy3tivK oGRw== X-Gm-Message-State: AOJu0YwQbHxIAIi+udZarGaM5HZsjwXSl19SJUtUP3XrjM33uPLeBQ8e ogavRkAypsf7+AqgbnEX+alqO6TOOmDbJtJ3XjswgZjorm23Mpr6IGXBMjhftjT4L58= X-Gm-Gg: AY/fxX5pzIQqmwSnHKrgfVtMY7DfhPzsbL+FvsvhFoaFtu/ZFheoC32IlFYUs1qf505 mK7OtrVZfVmSrNTQwPLOrt01aFoTVs4gL556gb2HiwTYVddCfOL81nwqX4kzpChD5x2rfAGnFmt 3pAjDW4We3w68VreFjI/AxzPhSPLPBghP6En7LeEcs07PmtrNAC6dN68mZ1Axh8WoW6d5wr7MB8 /0km4NouWGVQaU/aXPT7+X5oe4wqcIQb4kz0QehZaikRa7DaQEPqPbt3Gx8/3p9ZuGOHWYY9mqQ T66+Yk/U9L3Vzi2Ay5hX+PawSubjIfHx5UAp6IyJ5klWjUuyPZYP4j9iC9AR7CRgTlK9xrYbpVo dZHCAO8101f6ZZnIUQq0BiNueLseQ9Lx7ttmLcFwPmRmWJoaPQeaU3I3X5w5OpawwqlzNfHHw5U cIZthNnC+1WjU+o41fMdaRMe21fKjwSRPYGVtycSOatuUSGMDTaHhQHdQ9OlUJnKEZSHwWrGzMg /s= X-Google-Smtp-Source: AGHT+IGAaFjzefjYH5Z8kpFZ+RFoABQwYxji3hvgb4MB6kNxag9OOkQPVnmQjCwvYRlQ1+MAW53P6A== X-Received: by 2002:a05:6a00:1d9f:b0:7b9:420:cc0f with SMTP id d2e1a72fcca58-7ff646f8ad5mr41801061b3a.14.1767515940021; Sun, 04 Jan 2026 00:39:00 -0800 (PST) Received: from kinako.work.home.arpa (p1536247-ipxg00c01sizuokaden.shizuoka.ocn.ne.jp. [122.26.212.247]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7ff7aa328aesm44975827b3a.5.2026.01.04.00.38.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jan 2026 00:38:59 -0800 (PST) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [PATCH 1/2] tools/nolibc: Add fread() to stdio.h Date: Sun, 4 Jan 2026 17:38:36 +0900 Message-ID: <20260104083837.1390041-2-daniel@thingy.jp> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260104083837.1390041-1-daniel@thingy.jp> References: <20260104083837.1390041-1-daniel@thingy.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) } =20 =20 -/* fwrite(), puts(), fputs(). Note that puts() emits '\n' but not fputs().= */ +/* fwrite(), fread(), puts(), fputs(). Note that puts() emits '\n' but not= fputs(). */ =20 /* 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; } =20 +/* 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 =3D fileno(stream); + + while (size) { + ret =3D read(fd, buf, size); + if (ret <=3D 0) + return EOF; + size -=3D ret; + buf +=3D ret; + } + return 0; +} + + +static __attribute__((unused)) +size_t fread(void *s, size_t size, size_t nmemb, FILE *stream) +{ + size_t readed; + + for (readed =3D 0; readed < nmemb; readed++) { + if (_fread(s, size, stream) !=3D 0) + break; + s +=3D size; + } + return readed; +} + static __attribute__((unused)) int fputs(const char *s, FILE *stream) { --=20 2.51.0 From nobody Sat Feb 7 17:19:45 2026 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C9B026CE3B for ; Sun, 4 Jan 2026 08:39:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767515944; cv=none; b=Z50In2019n2xT0q48TOw/dv7VjZmVM/kpqhHaLiglCkQbITh5ReCvA3RwUDDC4fbURhcFdGs1CMx3nWPYzsYxHuSPiIMHId02lP0mz37v5c2Z8fMckKoIwmqzmB8GvRTocmVf0dDzrMf++xuD0i07adGw7Lpt8IoxFHTZXDMWKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767515944; c=relaxed/simple; bh=dLpZauhiM2vkarkLTIrYEQBfySBqwBlHrlPP0oAoMqk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dBdijLi5c4V8NS8b6K0lTZbGYWxiVIqBXIrHiMpXSW834Kupir273kx8ng3z+crKkKTWgzFh4lnFcF8mYmvEQMBSGNpOz27/NlOhr0PUg4kxh79GR4NbpjBFp4HmCSgyI+BK0ao72VIhwBq6qK7yUjk1UBV7aMojxsvQYFZTWes= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp; spf=pass smtp.mailfrom=0x0f.com; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b=N02HLezf; arc=none smtp.client-ip=209.85.216.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0x0f.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b="N02HLezf" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-34c902f6845so18622609a91.2 for ; Sun, 04 Jan 2026 00:39:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1767515942; x=1768120742; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zsGMasa6M3A32JVYchtqPBtl3jftbv6Mr3SyZIEiN2I=; b=N02HLezfrPu/yNVv7amWj0ST9/FUkzdmlK5TgU7WR6QmEerGP+BU4xhEGfchzYsHwL WgDEWtUbjQ9DzJrCK/Nu0q0r6+6fG/LRnNhromPwWGgliDquITc+SO4WXTJprZMvKJGV 5wzEJACBYjCZB6zywRzJ0/uHIkq6499e2pKPg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767515942; x=1768120742; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=zsGMasa6M3A32JVYchtqPBtl3jftbv6Mr3SyZIEiN2I=; b=nVCycQj6ybnDXfwkykETkPmS6x1Pd0aEpFMpmq6ZR+fkTNsNq/v5Pf/voUHYOjNzIY 12HPn0RH9f+loPl1I+Oe7ivjYxymrl19AoWHlHfoyLuaQEJ1c7zzSHyoD792AVhbQAhh oRJYcc5zf9BYG0vxRNNUfECvqAKALMw7GQkwZL1Ivxah4jON08JwYiRZv/xCgdAddEls jXPKWjarS+GkEq15dOZspBO9zhT7MQZGaNtR0I/6nSf17bYv7E6OuD9tkEyDVp6cwkCF qOEAT7A5497w1hzn9V1s5GgycjklNVMy72VN6/0Yy/sXFV/EyM9ETOf2ZvbLTlzoZ0yE dZ/w== X-Gm-Message-State: AOJu0YyULy4axSyF4/QxBeiVOYEnyvzCPHh2gIy7YgmDLb9LULi0YJRl 2/MYPos9Hf64e3MuPJMTLQ/cJ6e6TKaWof2TudPiGCzN7fWaIpZudwMp+rahsZTA1Rh96B5lvCA USudkdfk= X-Gm-Gg: AY/fxX5CNSSt/imyOhDM5P5gHj0aL5qjwZIQJ1+qxuRrgY7Blkbj5s6+xreN43tK1Ot 0ob3WiJcUxukBSJVVqWP0RH5p8oSrORla8+35aikKRoI0nKwuYgb3NXPiF4fZCVyXi5GZ5Q4u9J AjntxIJjiazXUDfyGMow+mC7a62PlwUulgk1PzqaA6ePJ8dI/kh/krZSyWUBph32q3UUBqNHCpB f7My+usgDHnwOq0LOyyPtMELLMS3AbKaza3VPWflJXc0inpRike51pAh0FNmb5YRLkQzwlfAqfF mrAdt3JIZ4STCyzoWB27+mX5rA6BMGegq31+GTwdsYA8lJlYTv4zIOuzVWF2wUMLsCGiwb6kwSx n1edgY47luohWatwIFU61WsYv7fVGtqR36tikWklC+P2p9qOx+25jtpf3+0Qhpa2C6nZWTQ3x8W dX2L2dOp8hQYh64lGKVbc/xvx7qeTwcMi7GQB2ywpVbka3pp4V/LS0v/Z+JTpPKUMyZmVe1h8kF NA= X-Google-Smtp-Source: AGHT+IE/bAa4i5Tl8OkzWj2MXMOHv+mhHMqdkYNHDfflj7rgFTQH0OglEqa4/9H4bpU5fsIx6Qi2HQ== X-Received: by 2002:a17:90b:590b:b0:34e:5aa2:cf61 with SMTP id 98e67ed59e1d1-34e921cc3b8mr36673116a91.28.1767515942295; Sun, 04 Jan 2026 00:39:02 -0800 (PST) Received: from kinako.work.home.arpa (p1536247-ipxg00c01sizuokaden.shizuoka.ocn.ne.jp. [122.26.212.247]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7ff7aa328aesm44975827b3a.5.2026.01.04.00.39.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jan 2026 00:39:01 -0800 (PST) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [PATCH 2/2] tools/nolibc: Add fseek() to stdio.h Date: Sun, 4 Jan 2026 17:38:37 +0900 Message-ID: <20260104083837.1390041-3-daniel@thingy.jp> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260104083837.1390041-1-daniel@thingy.jp> References: <20260104083837.1390041-1-daniel@thingy.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A very basic wrapper around lseek() that implements fseek(). Signed-off-by: Daniel Palmer --- tools/include/nolibc/stdio.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index 21569ebae824..d352ffa655a7 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -273,6 +273,25 @@ char *fgets(char *s, int size, FILE *stream) } =20 =20 +/* fseek */ +static __attribute__((unused)) +int fseek(FILE *stream, long offset, int whence) +{ + int fd =3D fileno(stream); + off_t ret; + + ret =3D lseek(fd, offset, whence); + + /* lseek() and fseek() differ in that lseek returns the new + * position or -1, fseek() returns either 0 or -1. + */ + if (ret >=3D 0) + return 0; + + return -1; +} + + /* minimal printf(). It supports the following formats: * - %[l*]{d,u,c,x,p} * - %s --=20 2.51.0