* src/stdio/__stdio_read.c
@ 2012-11-16 7:40 Yuri Kozlov
2012-11-16 9:29 ` src/stdio/__stdio_read.c Szabolcs Nagy
0 siblings, 1 reply; 3+ messages in thread
From: Yuri Kozlov @ 2012-11-16 7:40 UTC (permalink / raw)
To: musl
Hello.
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?
--
Best Regards,
Yuri Kozlov
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: src/stdio/__stdio_read.c
2012-11-16 7:40 src/stdio/__stdio_read.c Yuri Kozlov
@ 2012-11-16 9:29 ` Szabolcs Nagy
2012-11-16 19:01 ` src/stdio/__stdio_read.c Rich Felker
0 siblings, 1 reply; 3+ messages in thread
From: Szabolcs Nagy @ 2012-11-16 9:29 UTC (permalink / raw)
To: musl
* Yuri Kozlov <yuray@komyakino.ru> [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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: src/stdio/__stdio_read.c
2012-11-16 9:29 ` src/stdio/__stdio_read.c Szabolcs Nagy
@ 2012-11-16 19:01 ` Rich Felker
0 siblings, 0 replies; 3+ messages in thread
From: Rich Felker @ 2012-11-16 19:01 UTC (permalink / raw)
To: musl
On Fri, Nov 16, 2012 at 10:29:36AM +0100, Szabolcs Nagy wrote:
> * Yuri Kozlov <yuray@komyakino.ru> [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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-11-16 19:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-16 7:40 src/stdio/__stdio_read.c Yuri Kozlov
2012-11-16 9:29 ` src/stdio/__stdio_read.c Szabolcs Nagy
2012-11-16 19:01 ` src/stdio/__stdio_read.c Rich Felker
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).