Re: read() system call
- From: "bill pursell" <bill.pursell@xxxxxxxxx>
- Date: 8 Feb 2006 09:37:37 -0800
Kasper Dupont wrote:
bill pursell wrote:
I recently encountered comment/code similar to this:
while ( (a =fwrite(ptr, size, nmemb, stream) != nmemb)) {
nmemb-=a;
sleep(1); /* in case we are writing faster than the reader.*/
}
At the time, I thought this due to a port from a system
on which fwrite would return a short count when the read side
of the pipe was blocking. Does anyone know of an such OS?
I don't know if the standard permits fwrite to be implemented in
a way which could result in a short write unless there is an
error. But even if it does, the sleep statement is plain stupid.
If I understand the man page on my system correctly, a return of
zero would mean an error has happened. So fwrite has to write
something every time it is called. If it cannot write right away
it has to block.
Yeah, it really is stupid. I try so hard not to cringe and pull my
hair
out and make fun of people, but it gets harder everyday. I think I
edited
my original post multiple times, deleting things like "either a port
from
a system...., or else the author was a complete moron" and finally
discarded all the insults.
I really think of myself as being a very neophyte software designer,
but
I'm getting to the point of realizing that the code I work with just
plain
sucks. It's an unpleasant realization.
.
- References:
- read() system call
- From: Bilgehan . Balban
- Re: read() system call
- From: "Nils O. Selåsdal"
- Re: read() system call
- From: Grant Edwards
- Re: read() system call
- From: bill pursell
- read() system call
- Prev by Date: Re: unsafe functions from signal handler
- Next by Date: Re: detecting file types
- Previous by thread: Re: read() system call
- Next by thread: Re: FS Module Conversion From 2.4 to 2.6?
- Index(es):