Blob Blame History Raw
diff -up blender-2.59/source/blender/blenkernel/intern/blender.c.cve blender-2.59/source/blender/blenkernel/intern/blender.c
--- blender-2.59/source/blender/blenkernel/intern/blender.c.cve	2012-09-07 12:20:28.318000011 +0200
+++ blender-2.59/source/blender/blenkernel/intern/blender.c	2012-09-07 12:30:57.111000017 +0200
@@ -45,6 +45,7 @@
 	#define write _write
 #endif
 
+#include <errno.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <stddef.h>
@@ -705,7 +706,8 @@ void BKE_undo_save_quit(void)
 {
 	UndoElem *uel;
 	MemFileChunk *chunk;
-	int file;
+	int flags = O_BINARY+O_WRONLY+O_CREAT+O_TRUNC+O_EXCL;
+	int file = -1;
 	char str[FILE_MAXDIR+FILE_MAXFILE];
 	
 	if( (U.uiflag & USER_GLOBALUNDO)==0) return;
@@ -721,10 +723,16 @@ void BKE_undo_save_quit(void)
 		
 	BLI_make_file_string("/", str, btempdir, "quit.blend");
 
-	file = open(str,O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
-	if(file == -1) {
+	while (file == -1) {
+	  file = open(str,flags, 0666);
+	  if(file == -1) {
+	    if(errno == EEXIST) 
+	      flags ^= O_CREAT;
+	    else {
 		//XXX error("Unable to save %s, check you have permissions", str);
 		return;
+	    }
+	  }
 	}
 
 	chunk= uel->memfile.chunks.first;