From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2303 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: src/stdio/__stdio_read.c Date: Fri, 16 Nov 2012 14:01:21 -0500 Message-ID: <20121116190121.GQ20323@brightrain.aerifal.cx> References: <20121116114057.34884015@keeper.home.local> <20121116092936.GI12537@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1353092495 3270 80.91.229.3 (16 Nov 2012 19:01:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 16 Nov 2012 19:01:35 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-2304-gllmg-musl=m.gmane.org@lists.openwall.com Fri Nov 16 20:01:47 2012 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1TZRAd-0001DE-EJ for gllmg-musl@plane.gmane.org; Fri, 16 Nov 2012 20:01:43 +0100 Original-Received: (qmail 32393 invoked by uid 550); 16 Nov 2012 19:01:33 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 32385 invoked from network); 16 Nov 2012 19:01:33 -0000 Content-Disposition: inline In-Reply-To: <20121116092936.GI12537@port70.net> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:2303 Archived-At: On Fri, Nov 16, 2012 at 10:29:36AM +0100, Szabolcs Nagy wrote: > * Yuri Kozlov [2012-11-16 11:40:57 +0400]: > > size_t __stdio_read(FILE *f, unsigned char *buf, size_t len) > > { > > ssize_t cnt; > > ... > > cnt = syscall(SYS_readv, ...) > > > > if (cnt <= 0) { > > f->flags |= F_EOF ^ ((F_ERR^F_EOF) & cnt); > > f->rpos = f->rend = 0; > > return cnt; > > } > > ... > > } > > > > It not raise a problem when a signed value return as unsigned? > > > > no, cnt is either 0 or -1 there (assuming readv works) > > this is how __stdio_read is used (f->read): > > for (; l; l-=k, dest+=k) { > k = __toread(f) ? 0 : f->read(f, dest, l); > if (k+1<=1) { > FUNLOCK(f); > return (len-l)/size; > } > } > > it handles the k == -1 and k == 0 case As far as I can tell, it would work just fine to have the f->read function simply return 0 on both EOF and error; there do not seem to be any callers that care to distinguish these cases. When I get around to documenting stdio internals I might clean up some things like this. Rich