I'm posting this question here since Keil's support haven't answered my email so far: ---------------------------------------- I have the following piece of code:
fH = fopen(FILE_NAME_CLOCK, "a"); fseek(fH,20,SEEK_SET); fwrite(jbuf,1,sizeof(jbuf),fH); fclose(fH);
It is supposed to write to position 20 right, but if you look at the attached file it appends the data to the end of the file. What am I missing or doing wrong or is it a bug?
PS: Using Keil's RTK file system and µVision3 V3.80 on a ARM7 from NXP.
It is supposed to write to position 20 right,
No, it's not. Your understanding of fopen mode "a" is wrong. I have to suggest a return visit to your C textbook.
Just for the sake of people who might experience this problem in future: First I must admit that my understanding of opening it with the "a" option was that you could then do a fseek() and then write to the middle of a file.
I received an email from Keil USA, basically stating that their file system does not support writing to a position in the middle of a file.
This in my opinion is a SERIOUS shortcoming for any file system as you can now only append to the end of a file or rewrite the file from scratch. How many times is it required to modify data inside a file - my guess is the most of all! I certainly didn't expect Keil to sell such incomplete software to their clients.
Thanks for all the replies.
just as the manual states clearly: "Seeking within a file opened for "w" mode is currently unsupported." if you have a file system that runs in RAM, maybe you can maintain your files there until it is required to update the non-volatile memory. this has obvious shortcomings, of course.
=>How many times is it required to modify data inside a file - my guess is the most of all!<=
For RL-FlashFS/Flash-Memory:
http://www.keil.com/support/man/docs/rlarm/rlarm_fs_mem_org.htm
When you want to erase the flash data, you need to erase the whole flash sector at once.
When the content of the file is modified, the old file content is invalidated and the new memory block is allocated. The Flash Block is erased when all the data stored in the Flash Block is invalidated.
fseek is not supported for SPI chip memories, e.g. dataflash, but is supported for MMC/SD cards.
View all questions in Keil forum