src/file/SDL_rwops.c
changeset 1453 2eb75f8a32ca
parent 1447 515df0086eb7
child 1455 f487bb150acc
equal deleted inserted replaced
1452:b7184889c1cb 1453:2eb75f8a32ca
    57 	/* "w+" = read, write, truncate. file may not exist    */
    57 	/* "w+" = read, write, truncate. file may not exist    */
    58 	
    58 	
    59 	must_exist = ( SDL_strchr(mode,'r') != NULL ) ? OPEN_EXISTING : 0;
    59 	must_exist = ( SDL_strchr(mode,'r') != NULL ) ? OPEN_EXISTING : 0;
    60 	truncate   = ( SDL_strchr(mode,'w') != NULL ) ? CREATE_ALWAYS : 0;
    60 	truncate   = ( SDL_strchr(mode,'w') != NULL ) ? CREATE_ALWAYS : 0;
    61 	r_right    = ( SDL_strchr(mode,'+') != NULL || must_exist ) ? GENERIC_READ : 0;
    61 	r_right    = ( SDL_strchr(mode,'+') != NULL || must_exist ) ? GENERIC_READ : 0;
    62 	a_mode     = ( SDL_strchr(mode,'a') != NULL );
    62 	a_mode     = ( SDL_strchr(mode,'a') != NULL ) ? OPEN_ALWAYS : 0;
    63 	w_right    = ( a_mode || SDL_strchr(mode,'w') || truncate ) ? GENERIC_WRITE : 0;
    63 	w_right    = ( a_mode || SDL_strchr(mode,'+') || truncate ) ? GENERIC_WRITE : 0;
    64 
    64 
    65 	if (!r_right && !w_right) /* inconsistent mode */
    65 	if (!r_right && !w_right) /* inconsistent mode */
    66 		return -1; /* failed (invalid call)*/
    66 		return -1; /* failed (invalid call)*/
    67 	
    67 	
    68 	/* Do not open a dialog box if failure */
    68 	/* Do not open a dialog box if failure */
    69 	old_error_mode = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS);	
    69 	old_error_mode = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS);	
    70 	
    70 	
    71 	h = CreateFile(filename, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ, 
    71 	h = CreateFile(filename, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ, 
    72 		           NULL, (must_exist|truncate), FILE_ATTRIBUTE_NORMAL,NULL);
    72 		           NULL, (must_exist|truncate|a_mode), FILE_ATTRIBUTE_NORMAL,NULL);
    73 	
    73 	
    74 	/* restore old behaviour */
    74 	/* restore old behaviour */
    75 	SetErrorMode(old_error_mode);
    75 	SetErrorMode(old_error_mode);
    76 
    76 
    77 	if (h==INVALID_HANDLE_VALUE) {
    77 	if (h==INVALID_HANDLE_VALUE) {
   336 {
   336 {
   337 	SDL_RWops *rwops = NULL;
   337 	SDL_RWops *rwops = NULL;
   338 
   338 
   339 #ifdef __WIN32__
   339 #ifdef __WIN32__
   340 	rwops = SDL_AllocRW();
   340 	rwops = SDL_AllocRW();
       
   341 	if (!rwops)
       
   342 		return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
   341 	rwops->hidden.win32io.h = INVALID_HANDLE_VALUE;
   343 	rwops->hidden.win32io.h = INVALID_HANDLE_VALUE;
   342 	if (win32_file_open(rwops,file,mode)) {
   344 	if (win32_file_open(rwops,file,mode)) {
   343 		SDL_FreeRW(rwops);
   345 		SDL_FreeRW(rwops);
   344 		return NULL;
   346 		return NULL;
   345 	}	
   347 	}