NEED HELP: fread, fwrite, fseek, ftell

Brian Chapman chapman at sco.COM
Thu May 4 06:03:25 AEST 1989


In article <7327 at mrspoc.UUCP> itkin at mrspoc.UUCP (Steven List) writes:
>I am trying to write a simple little program to swap bytes and/or words
>in a file.  The program works great except for one little problem.  When
>I try to do it in place, the file just keeps growing and growing and...

I think I can guess your problem.  [ Although your code fragment was
not sufficent to be sure ].

The old V7 and or BSD trick of opening a file for appending
(eg. fopen(....."a");)  and then rewinding it;  doesn't work
on System V compatibile systems.

Open for appending inforces an implied seek() to EOF on writes.
So you read from the front of the file and your writes get added
to the end, to be read again and added as yet more data at the
end of file to be read again....

Try just opening the file read|write.  (fopen(....."r+");)

[ I once chased this "feature" all the way to the exact line in	]
[ in the kernel, and was about to report it as a bug.  Until a	]
[ co-worked pointed it out in the SVID.	:-)			]
-- 
	Pay no attention to the man behind the curtain.
Brian Chapman		uunet!sco!chapman	SCO UNIX 3.2 Development



More information about the Comp.unix.xenix mailing list