How to truncate a file?

Hi, 

I'm writing CVS formatted data to a log file. When the system loses power unexpectedly and the write operation is interrupted it can happen that the last line of the file is incomplete (fewer columns). To tidy up the file I want to remove the last line. Currently the only option to do this seems to copy the entire file, which is quiet inefficient (files can have 100MB to 1GB). On a unix system one could use the ftruncate function to remove the tail of the file. Is there a similar (efficient) option for the Keil filesystem? 

Best,

Valentin

Parents
  • I think you're looking at the wrong end of this problem.

    Rather than burdening your embedded system with this job, it's almost ceraintly more productive to leave it to post-processing steps on whatever system you eventually shunt that log file over to.  There you'll have no problem whatsoever setting up a little script that cleans up this kind of gllitch before processing the file for real.


    Just make sure you issue a line-end if you find the last line to be lacking one, on boot-up.

Reply
  • I think you're looking at the wrong end of this problem.

    Rather than burdening your embedded system with this job, it's almost ceraintly more productive to leave it to post-processing steps on whatever system you eventually shunt that log file over to.  There you'll have no problem whatsoever setting up a little script that cleans up this kind of gllitch before processing the file for real.


    Just make sure you issue a line-end if you find the last line to be lacking one, on boot-up.

Children