fwrite() and BUFSIZ

Douglas Harvey drharvey at chinet.chi.il.us
Wed Apr 17 11:00:00 AEST 1991


I am having a problem setting up my own buffers for fwrite using
setvbuf().  Incidently, I'm running on a Sun sparcstation running SunOS
4.1.

We work alot with tape files, both from clients (usually created on IBM
mainframe systems) and tapes we create internally by writing directly to
the device, eg. fopen("/dev/rst8","w").

However, I've come up against a couple of problems.  One, for some reason
I had to add eight (8) to the blocksize before the tape would get blocked
at the desired blocksize.  For example, if I wanted a blocksize of 10,000,
I would need to call setvbuf() with a size of 10,008 bytes.  Does fwrite()
reserve 8 bytes for a couple of 4-byte pointers or something?  I could not
find any mention of this.

The second problem I have yet to solve.  All of this works fine when the
size of the structure I'm fwrite()'ing is less than 1024 bytes in length.
Once I get above this size, the blocksize will be the same as the record
size.  This seems a little suspicious since the default buffer size for
fread/fwrite is 1,024 bytes.  Is this a bug with Sun OS, or is this just
the way it works?

Any comments, etc. welcomed.

Douglas Harvey                      Email: drharvey at chinet.UUCP
Ronald J. Krumm & Associates, Inc.  Compuserve: 72341,104
1 Riveside Road                     Phone: (708) 447-1771
Riverside, IL  60546



More information about the Comp.sys.sun mailing list