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

@ -371,10 +371,23 @@ sequence::load ( const char *name )
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 );
@ -416,6 +429,11 @@ sequence::save ( const char *name ) const
p->dump( &f );
}
}
rename(tmp,name);
free(tmp);
}