views:

69

answers:

1

I am using an embedded system running linux.I use a ramdisk filesystem on the embedded target. My application captures real-time data and does Standard C "fwrite" to a file in this ramdisk fs.As there is limited amount of memory , I would like to set a max size for the file and cause fwrite to wrap around like a circular buffer. Is there a way to do this in manner that is transparent to the application ? I would prefer the application to remain unchanged when I migrate to a filesystem on a storage device (eSATA) having much larger capacity.

+1  A: 

There's no built in method of achieving this.

The best option is probably to write a small wrapper function that takes care of the file write while maintaining a count of the number of bytes written.

Once it has reached the maximum size that you set it should call rewind() (or fseek() etc.) to go back to the start of the file.


It might be easier to use mmap() to memory map your file and then treat it like a circular buffer. But again you would need to implement the wrapping yourself.

Andrew Edgecombe