r+ on fopen.

alt at BRL.ARPA alt at BRL.ARPA
Wed Sep 21 14:50:16 AEST 1983


From:  Howard Alt <alt at BRL.ARPA>


It seems that one of our people was trying to read and write
to the same file, seeking back and forth, etc.  It wasn't writing
the file.  I solved the problem by opening 2 file descriptors to the
same file, one for read, the other for append, and rewinding the
append one.  Then, I used ftell on the read descriptor to seek into the
write desctiptor and write.  It is a kluge.  
A person that wishes to remain unknown, did some testing, and here is
what he had to say about it...

------------BEGIN FORWARDED MESSAGE
To: alt hakim
Subject: Seek and you shall die

	It appears that opening files for reading and writing 
simultaneously is not a working feature. I beat on the problem
for a while with a little test program and noted the following
behavior (see /usr/XXX/test.c):

	If one seeks forward an even number of bytes and then
	seeks backwards an even number of bytes and then writes
	on the file, things appear to work correctly. Things
	also seem to work correctly if both seeks are odd. If
	one seek is odd and the other even the write to the file 
	has no effect.

All of this is fairly useless; the program did fairly (random)
bizarre things after only minor modification. I think the bottom
line is: "read/write files are broken (QED)".

				We must consult the wizards,
				   the anonymous hacker...
------------END FORWARDED MESSAGE


Well, has anyone had the same experience?  I really have no desire
to dig through the fopen, fseek, etc code to find out what is wrong...
someone must have fixed it.
Please send me the fix (or even speculate on what it could be)
		Thanks,
				Howard.
	



More information about the Comp.unix.wizards mailing list