better save_image that doesn't corrupt your factor image if you're out of disk space. should throw exception instead of printing error messages if saving fails..
parent
2df61fd78d
commit
99cd664961
12
vm/image.c
12
vm/image.c
|
@ -112,7 +112,9 @@ bool save_image(const F_CHAR *filename)
|
|||
FILE* file;
|
||||
F_HEADER h;
|
||||
|
||||
file = OPEN_WRITE(filename);
|
||||
F_CHAR temporary_filename[] = "##saving-factor-image##";
|
||||
|
||||
file = OPEN_WRITE(temporary_filename);
|
||||
if(file == NULL)
|
||||
{
|
||||
print_string("Cannot open image file: "); print_native_string(filename); nl();
|
||||
|
@ -163,6 +165,14 @@ bool save_image(const F_CHAR *filename)
|
|||
return false;
|
||||
}
|
||||
|
||||
if(MOVE_FILE_FAILS(temporary_filename, filename))
|
||||
{
|
||||
print_string("Failed to rename tempoarary image file: "); print_string(strerror(errno)); nl();
|
||||
if(DELETE_FILE_FAILS(temporary_filename))
|
||||
print_string("Failed to clean up temporary image file: "); print_string(strerror(errno)); nl();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ typedef char F_SYMBOL;
|
|||
#define STRCMP strcmp
|
||||
#define STRNCMP strncmp
|
||||
#define STRDUP strdup
|
||||
#define MOVE_FILE_FAILS(old,new) (rename((old),(new)) < 0)
|
||||
#define DELETE_FILE_FAILS(old) (unlink((old)) < 0)
|
||||
|
||||
#define FIXNUM_FORMAT "%ld"
|
||||
#define CELL_FORMAT "%lu"
|
||||
|
|
|
@ -19,6 +19,8 @@ typedef wchar_t F_CHAR;
|
|||
#define STRCMP wcscmp
|
||||
#define STRNCMP wcsncmp
|
||||
#define STRDUP _wcsdup
|
||||
#define MOVE_FILE_FAILS(old,new) (MoveFile((old),(new)) == 0)
|
||||
#define DELETE_FILE_FAILS(old) (DeleteFile((old)) == 0)
|
||||
|
||||
#ifdef WIN64
|
||||
#define CELL_FORMAT "%Iu"
|
||||
|
|
Loading…
Reference in New Issue