@@ -1241,28 +1241,18 @@ bool MCS_get_temporary_folder(MCStringRef &r_temp_folder)
12411241
12421242bool MCS_create_temporary_file (MCStringRef p_path_string, MCStringRef p_prefix_string, IO_handle &r_file, MCStringRef &r_name_string)
12431243{
1244- const char *t_path = MCStringGetCString (p_path_string);
1245- const char *t_prefix = MCStringGetCString (p_prefix_string);
1246- char *t_name = (char *)MCStringGetCString (r_name_string);
1247-
12481244 bool t_success = true ;
1249- bool t_have_file = false ;
12501245
1251- char *t_temp_file = NULL ;
12521246 GUID t_guid;
12531247 WCHAR *t_guid_utf16 = NULL ;
12541248
1255- HANDLE t_temp_handle = NULL ;
1249+ IO_handle t_temp_handle = NULL ;
12561250
1257- while (t_success && !t_have_file)
1251+ MCAutoStringRef t_temp_file;
1252+ while (t_success && t_temp_handle == NULL )
12581253 {
12591254 CoCreateGuid (&t_guid);
12601255
1261- if (t_temp_file != NULL )
1262- {
1263- MCCStringFree (t_temp_file);
1264- t_temp_file = NULL ;
1265- }
12661256 if (t_guid_utf16 != NULL )
12671257 {
12681258 CoTaskMemFree (t_guid_utf16);
@@ -1277,28 +1267,22 @@ bool MCS_create_temporary_file(MCStringRef p_path_string, MCStringRef p_prefix_s
12771267 for (i = 0 ; t_guid_utf16[i] != ' \0 ' ; i++)
12781268 t_guid_string[i] = t_guid_utf16[i] & 0xFF ;
12791269 t_guid_string[i] = ' \0 ' ;
1280- t_success = MCCStringFormat ( t_temp_file, " %s/%s %s" , t_path, t_prefix , t_guid_string);
1270+ t_success = MCStringFormat (& t_temp_file, " %@/%@ %s" , p_path_string, p_prefix_string , t_guid_string);
12811271 }
12821272
12831273 if (t_success)
12841274 {
1285- t_temp_handle = CreateFileA (t_temp_file, GENERIC_READ | GENERIC_WRITE, 0 , NULL , CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL );
1286- if (t_temp_handle != INVALID_HANDLE_VALUE)
1287- t_have_file = true ;
1288- else
1275+ t_temp_handle = MCsystem->OpenFile (*t_temp_file, (intenum_t )kMCOpenFileModeCreate , false );
1276+ if (t_temp_handle == NULL )
12891277 t_success = GetLastError () == ERROR_FILE_EXISTS;
12901278 }
12911279 }
12921280
12931281 if (t_success)
12941282 {
1295- r_file = MCsystem -> OpenFd (_open_osfhandle ((intptr_t )t_temp_handle, _O_RDWR), kMCOpenFileModeCreate );
1296- t_name = t_temp_file;
1297- /* UNCHECKED */ MCStringCreateWithCString (t_name, r_name_string);
1298-
1283+ r_file = t_temp_handle;
1284+ r_name_string = t_temp_file.Take ();
12991285 }
1300- else
1301- MCCStringFree (t_temp_file);
13021286
13031287 CoTaskMemFree (t_guid_utf16);
13041288 return t_success;
0 commit comments