I recently asked a similar question - but the issue has become more relevant to me as I continue working on my program, so I want to ask the question again in greater detail.
After reading over the GNU docs regarding file manipulation, there seems to be no facility for removing data from a file. My program creates a file which stores various records in no particular order. If I want my program to delete an arbitrary record, it seems my only option would be to recreate the entire file with one less record, and then delete the old file.
But recreating the entire file seems like a very expensive operation, especially if the file is large. Surely database programs which store thousands of records do not recreate the data file every time a single record is removed. But the only other conceivable way to remove an arbitrary record from a data file would be to seek the record, and then move all subsequent records backwards by one record. This is still a rather expensive operation, but I guess it's the only option with a disk-based data structure.
But is it even possible to do this? I realize there is no such facility defined in ANSI C, but I'm not worried so much about portability. Still, I can't find anything mentioned in the GNU docs either. So, what are some ways to remove data from a file without recreating the entire file on a GNU Linux platform?