From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 870BD241103 for ; Mon, 5 Jan 2026 11:01:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767610908; cv=none; b=fRxsxSzU4i/1XEF6mPb0QNjfNC1M0ulhw8FY4kytQeef+dFJWHSpCVB31y+3YYht+J3cTTTx4wY4MYQeIHxGRuWHqoWVUTnom7PdI71GS7fEjU3GIcdXkV064vtqO/ga5ivuLVW5N5OYbkR+Ta8BKdbYNiYjgX+sIi1YuvgFido= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767610908; c=relaxed/simple; bh=zBU5AhAxsjkIEXDSUmpnoWS7kYIWxfLXBzttlkSqTOI=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SuJ2CVXj2yhgsaJgSbt7LSrPQBQAkt+hLVGz4MkeQ0Ytt9U67C8llgbvz9ps3ZkK9MeA/BSSqwkFELQb65ojIw924+0DaFCwL4n5izVEOq4Z+FmiMS33bs5eMe5mRD6rRI190Jcl9USaaPOxOI/bMZX0+uoOo+ypVjDBZM0+ep0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GdDZLZqy; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GdDZLZqy" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-47d493a9b96so34049965e9.1 for ; Mon, 05 Jan 2026 03:01:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767610905; x=1768215705; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=rlBw1YpcJALGjXm5LUbqOhR2GWZVww3yDDltjynTrNQ=; b=GdDZLZqy5NOraw4WbOczKigx7HigQOY6PDp2WTVqHaqnG01DxqIilMF5pPP57hZqzr iBN/dDXasiyVTHPlteQz7dQ8WMDNG1bT3+qbu0UmE/zos3jI8PwgJXuO08sHgRWYxhAr aGjmBMSO0V8tpYf0bDBN/GTcHk00hPpIiZ9lW80Mi9d3twyNp4MN/5/Rqk9XpH+tSP2J HsjrdF+q6qhei6LARqqa5GPnzPuMWSG/yK9nnUrDzcMiZnl1nQoUpcPmMCeJOY3NBv0a yamz6cmTyuV487Tosu/A9+5ezsj6JFF6qJHv5BDo/p6+rfVBdurpHzf06siT5Bfr1key dgMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767610905; x=1768215705; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=rlBw1YpcJALGjXm5LUbqOhR2GWZVww3yDDltjynTrNQ=; b=TU2cnI71lWX4vmzoT16SAOZ0n6BfNcXnswmJRibVsHp6E6fmeLilaYhENlxeiGK4dc yAeRtQcnAE4I5YhDXtoPBVMYOGvKeZ/+gPb0YNJMg4LqSCJo2JNiDLDaqa3amF1u+NHa ZjM4rhAtPntbtx1izQpnuTK2uM6Ac8bbVGRurpw8efLpmgqe8o/GUnoFezsgsknHPDUq q6pKx5RcZAv//VluHZ55kGrB2LYcxUG1RpCZZaU8J7RqOaGjB2+q9qD0CvVNZxhYDtBt CANSFTU2esFfPel5sMMS4tSRJRwKMhDQ1Sf/8UBu9gJJ9DD5/IaoX5X9Fi4iEeHkKhk0 vN6g== X-Forwarded-Encrypted: i=1; AJvYcCVjYIeIuOmSbtTzY6bVdQjsZ9RiOhGDU7S+LZqJqrnT5v+Sk9Mo7GVhN+DRRtAgmjMl/tZxYdpVb+yC65U=@vger.kernel.org X-Gm-Message-State: AOJu0YyfAWm3mPWrUiHs/1ZUslvTEPS+n+kk05yZWVu4sVMPeEUYqqBO OOnQkcilQU9NPfkYtzEauq7h+AnFSRhSMuBbje6EHczYf4GK8zigC1jL X-Gm-Gg: AY/fxX6+z+tqCflvKAS5HHOjFQfaaWjxkX90EdlvP1yDgXiezw4gffGQmwj4zhWT+7B O14vLdkZqTlKRUbSCaOr+p5c1vYqzbUlVlfEG9CO5nXWBboHc0/QCFDzja1iuJc2+8aTAWFrY2A dZcRlcFMUHoXL6z9PWPYqw/FU6sDihHdK8DErYWOFPr4+5lt5V7cKaataGMYKdjZcXK7hJQ57dA hH4suoKZ6ozLmiA5LTyGJgJFIMMM5j5YqFC0//q6m5d0uSL0eAaBCjEU0a0YLKbc4G8w6zUREcn tfvUurK+QzzAzxwbgG0vrKcNNUqJKFJnI1JTCfcT2EP1zKpWTyItA5bta2L4sDlVSXoCaM77Ov4 wleBfTP0iIzl6ShAYxKzMt1XrBHRVY7uYfFzITyaY5PJmGMPmaCmXqeil8Q+JkmZkF8IBcekLYf xYBdF6wFhOEyaapblrxK5gafzJ0oLvoiJYDPcHvk4UN4C2boCVzmqS X-Google-Smtp-Source: AGHT+IFS1GAnpjQZr8nLPnlzn2n5eDl6tVE7oYVIsusRwVayTuqtNsTjGSpWFCd5iouvga13Oiv61w== X-Received: by 2002:a05:600c:8819:b0:471:1765:839c with SMTP id 5b1f17b1804b1-47d1957b7aamr526787205e9.20.1767610904466; Mon, 05 Jan 2026 03:01:44 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47d6be53a0csm57496995e9.3.2026.01.05.03.01.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jan 2026 03:01:43 -0800 (PST) Date: Mon, 5 Jan 2026 11:01:42 +0000 From: David Laight To: Daniel Palmer Cc: w@1wt.eu, linux@weissschuh.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] tools/nolibc: Add fread() to stdio.h Message-ID: <20260105110142.127eaba3@pumpkin> In-Reply-To: References: <20260104083837.1390041-1-daniel@thingy.jp> <20260104083837.1390041-2-daniel@thingy.jp> <20260104183452.57213367@pumpkin> <20260105092729.386bac33@pumpkin> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) 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-Transfer-Encoding: 7bit On Mon, 5 Jan 2026 18:43:03 +0900 Daniel Palmer wrote: > Hi David, > > On Mon, 5 Jan 2026 at 18:27, David Laight wrote: > > But you've deleted the partial bytes from the input. > > I'm sure that isn't right. > > Normally a FILE is buffered and the bytes are saved for the next read. > > Remember you can be reading from a pipe that is being written using > > 'block buffering' - so it is valid for only a partial 'item' be read. > > (I'm sure non-blocking IO is also valid...) > > I see now. If a partial read happens, the next call to fread() will > read from after the end of the partial read that happened and it'll be > broken. > Since in nolibc the FILE pointer that gets used isn't really a pointer > but the file descriptor I'm not sure where we'd stash the partial part > so we need to avoid doing the partial read entirely. Except you can't really avoid the partial read. Doing multiple read() system calls doesn't help. The situation where it can happen probably doesn't happen for nolibc. Is there support for ferror() and/or feof() ? (a global 'u8 fstate[64]' indexed by fd number would probably suffice.) If so you could set the 'error' bit and then error any further fread()s. David > > Thanks, > > Daniel