if(name) {  if(cb) {  if(rw==0) {  FILE *fd; fd=fopen(name,"rb"); if(!fd) { GUI_Alert("Cannot open this file !"); return; } fclose(fd); cb(name); ADM_dealloc(name);  } else { FILE *fd; fd=fopen(name,"rb"); if(fd) { fclose(fd); if(!GUI_Question("Overwrite file ?")) return; }  fd=fopen(name,"wb"); if(!fd) { GUI_Alert("No write access to that file !"); return; } fclose(fd);   cb(name); ADM_dealloc(name); } } else {  *rname=name;   }   }
fileReadWrite(cb, rw, name);
void GUI_FileSel(const char *label, SELFILE_CB * cb, int rw,char **rname){				/* Create the selector */    	GtkWidget *dialog;	char *name=NULL;	char *tmpname;	gchar *selected_filename;	if(rname)		*rname=NULL;	dialog=create_fileselection1();	gtk_window_set_title (GTK_WINDOW (dialog),label);	gtk_transient(dialog);	if( prefs->get(LASTDIR,&tmpname))	{		DIR *dir;	//	printf("tmpname : %s\n",tmpname);		char *str=PathCanonize(tmpname);	//	printf("tmpname : %s\n",str);		PathStripName(str);	//	printf("tmpname : *%s*\n",str);		/* LASTDIR may have gone; then do nothing and use current dir instead (implied) */		if( (dir=opendir(str)) ){			closedir(dir);			gtk_file_selection_set_filename(GTK_FILE_SELECTION(dialog),(gchar *)str);		}		delete [] str;	}	if(gtk_dialog_run(GTK_DIALOG(dialog))==GTK_RESPONSE_OK)	{			selected_filename= (gchar *) 	gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog));#ifdef CYG_MANGLING			if (*(selected_filename + strlen(selected_filename) - 1) == '\\'){#else						 if (*(selected_filename + strlen(selected_filename) - 1) == '/'){#endif			       	  					GUI_Alert("Cannot open directory as file !");			}			else			{						name=ADM_strdup(selected_filename);						char *str=PathCanonize(name);						PathStripName(str);						prefs->set(LASTDIR,str);									delete [] str;			}	}	gtk_widget_destroy(dialog);	if(name)	{		if(cb)		{			if(rw==0) // read			{				// try to open it..				FILE *fd;				fd=fopen(name,"rb");				if(!fd)				{						GUI_Alert("Cannot open this file !");						return;				}				fclose(fd);				cb(name);				ADM_dealloc(name);			}			else // write			{				FILE *fd;				fd=fopen(name,"rb");				if(fd)					{							fclose(fd);							if(!GUI_Question("Overwrite file ?"))								return;					}				// check we have right access to it				fd=fopen(name,"wb");				if(!fd)					{						GUI_Alert("No write access to that file !");						return;					}				fclose(fd);				cb(name);				ADM_dealloc(name);			}		} // no callback -> return value		else		{			*rname=name;		}	}}