On Fri, Feb 11, 2000 at 11:39:53AM -0500, James C. Bevier wrote:
| I am having some confusion about how pipes work in Linux
| when being read/written with fread/fwrite.

Remember that pipes aren't very special. Tapes and ttys will also exhibit
this behaviour under the right circumstances.

| I am getting some
| random data error and suspect it may be how pipes work.
| 
| Several programs are piping data between job steps.  It seems
| to me if I use either:
| 
| fwrite(bufptr, size=1, count=100, fp) or
| fwrite(bufptr, size=100, count=1, fp that 100 bytes will be
| written to the pipe before the system returns from the fwrite
| call.  There is never a partial write to the pipe.
| Right?

This has been my experience. fwrite will normally only return a short write
if something goes wrong.

| If I use fread(bufptr, size=1, count=100, fp), the system MAY
| return a count of less that 100 bytes and not give an error
| indication via ferror(fp).  Right?

Correct, which is why you must check its count return.

| But if I use fread(bufptr, size=100, count=1, fp) that the system
| will ONLY return when 100 bytes have been read and never give
| a partial read because the count returned can only be 0 or 1.

That is how I read the specification.

| The programs involved do not test for short reads and have a mixture
| of both forms of fread calls.  I think I can solve my problem if I
| make sure all reads use a count of 1 and a size of the buffer I want
| to read.  Right?

Yes, but check for short reads anyway - since you can get one 0 or 1
you can treat 0 as "unexpected EOF" and abort tidily in some fashion.
-- 
Cameron Simpson, DoD#743        [EMAIL PROTECTED]    http://www.zip.com.au/~cs/

Microsoft Network is prohibited from redistributing this work in any form,
in whole or in part. Copyright (c), <your name>, 1995 
License to distribute this post is available to Microsoft for $1000.
Posting without permission constitutes an agreement to these terms.
        - Kevin Dinn <[EMAIL PROTECTED]>


-- 
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.

Reply via email to