I am currently implementing backup-file functionality in my level-editor, and am wondering on the best way to implment it.
The most obvious solution is to rename the file to the backup filename and then write out the saved level as normal, like so...
|1||#define CHIO_MAXPATHLENGTH 260|
|2||#define CHIO_FILENAMEEXTENSION_BACKUP "bak"|
|5||replace_extension(szBackupName, szPathToUse, CHIO_FILENAMEEXTENSION_BACKUP, CHIO_MAXPATHLENGTH);|
|11|| return AERVAL_IOFAL; // TODO: More accurate error-code|
|17|| return AERVAL_IOFAL; // TODO: More accurate error-code|
Unfortunately, this has the problem of losing any meta-data associated with the file (such as creation-date, file-owner, and I believe that on BeOS, meta-data can become quite involved).
The alternative solution I had would be to copy the file byte by byte. But this has the disadvantage of being slow and inefficient (like when saving on a floppy disk), as it involves one read and two writes instead of one write. Also, the backup-file will not contain the meta-data of the original file.
Are there any other recommended ways of creating backup files, or any libc functions I could use? Perhaps I could read in the meta-data of the backup file and apply it to the saved file (although this would probably vary from OS to OS, and I'm not sure if I can create a file belonging to a different owner).