Sequencer: Save file to tmp file before overwriting original.

This commit is contained in:
Jonathan Moore Liles 2020-09-16 18:18:43 -07:00
parent b3ffef17b5
commit 1a07dda5d9
1 changed files with 55 additions and 37 deletions

View File

@ -370,11 +370,24 @@ sequence::load ( const char *name )
/** save entire sequence to file */
void
sequence::save ( const char *name ) const
{
char *tmp = NULL;
{
const char *filename = basename(name);
char *dir = (char*)malloc( (strlen(name) - strlen(filename)) + 1 );
strncpy( dir, name, strlen(name) - strlen(filename) );
asprintf( &tmp, "%s#%s", dir, filename );
free(dir);
}
{
smf f;
/* open for writing */
f.open( name, smf::WRITE );
f.open( tmp, smf::WRITE );
f.write_header( 2 );
@ -418,6 +431,11 @@ sequence::save ( const char *name ) const
}
}
rename(tmp,name);
free(tmp);
}
/*************/
/* Accessors */