[En-Nut-Discussion] Strange behavior with files using file attributes '+' or 'a'

Michael Bieri mibieri at ee.ethz.ch
Wed Feb 27 12:34:50 CET 2008


Hi
> Andreas Helmcke wrote:
>   
>> Michael Bieri wrote:
>>     
>>> - Sometimes, the 'a' attribute doesn't append my data, it only appends 
>>> some trash with the same length at the end.
>>> - Sometimes, the 'a' attribute doesn't start "inserting"/appending data 
>>> at the end of my file, but inserts it at the beginning. fseek(..., 
>>> SEEK_END) does fix this problem.
>>> - If I try to insert some data with 'rb+', it behaves like an ordinary 
>>> 'w' (existing data is lost, but new data is there).
>>>       
>> I had similar problems when trying to append to an already existing file but 
>> didn't find by now the time to file a bug.
>> For me it works properly when opening the file with the correct attributes and 
>> doing fseek(...,0,SEEK_END) immediately afterwards.
>>     
>
> Thanks for reporting this. Someone can add this to the bugtracker, please?
>   
Andreas' proposal does fix the problem with the 'a'-attribute.

For the problem with the '+' attribute: It seems, that there's something 
wrong with the file attributes, in _fmode(...), a '+' does set the 
attribute _O_TRUNC, this attribute then clears the file in PhatFileOpen(...)

if (mode & _O_TRUNC) {
            /*
             * Relase all clusters allocated by this entry.
             */
  ......
}

As it seems, you can work-around this problem using low-level IO as 
_open, _write, _read.



More information about the En-Nut-Discussion mailing list