From: Carlos Date: 2005-03-23T04:20:19+09:00 Subject: Re: Reading and writing a binary file [Chris G�nther , 2005-03-22 12.29 CET] > Thanks Robert, > > you are absolutely right with your remarks using a block. The code I > posted was just a small copied fraction of the real code, in which I > cannor use a block because the same fd will be stored in a hash for > later usage by another method. > Anyway, meanwhile I found the cause of this problem (again you are > right, it was not in the code I posted) , but now I have another related > problem that tricks my mind. I am trying to patch binary data in a file. > Unfortunately the data I am patching is not the data I get when reading > it back from the patched binary file. > Any ideas?? All your problems come from the fact that your are opening the file for appending ("ab+") instead of for reading ("r+b"). With "ab+", you can set fd.pos=0, if you want, but it will always write at the end of file.