+ /* If they opened a file in write mode but didn't specifically get
+ permission to do so, complain if the file already exists */
+ if(fileref->orig_filemode == filemode_Read && fmode != filemode_Read) {
+ gdk_threads_enter();
+
+ GtkWidget *dialog = gtk_message_dialog_new(NULL, 0,
+ GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
+ "File %s already exists. Overwrite?", fileref->filename);
+ gint response = gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+
+ gdk_threads_leave();
+
+ if(response != GTK_RESPONSE_YES) {
+ fclose(fp);
+ return NULL;
+ }
+ }
+
+ strid_t str = g_new0(struct glk_stream_struct, 1);
+ str->rock = rock;
+ str->file_mode = fmode;
+ str->type = STREAM_TYPE_FILE;
+ str->file_pointer = fp;
+ str->binary = binary;
+ str->unicode = unicode;
+ str->filename = g_filename_to_utf8(fileref->filename, -1, NULL, NULL, NULL);
+ if(str->filename == NULL)
+ str->filename = g_strdup("Unknown file name"); /* fail silently */
+ /* Add it to the global stream list */
+ glk_data->stream_list = g_list_prepend(glk_data->stream_list, str);
+ str->stream_list = glk_data->stream_list;
+
+ return str;