extern GPrivate *glk_data_key;
-/* Internal function: create a fileref using the given parameters. */
+/* Internal function: create a fileref using the given parameters. If @basename
+is NULL, compute a basename from @filename. */
frefid_t
-fileref_new(gchar *filename, glui32 rock, glui32 usage, glui32 orig_filemode)
+fileref_new(char *filename, char *basename, glui32 rock, glui32 usage, glui32 orig_filemode)
{
g_return_val_if_fail(filename != NULL, NULL);
f->disprock = (*glk_data->register_obj)(f, gidisp_Class_Fileref);
f->filename = g_strdup(filename);
+ if(basename)
+ f->basename = g_strdup(basename);
+ else
+ f->basename = g_path_get_basename(filename);
f->usage = usage;
f->orig_filemode = orig_filemode;
fref->disprock.ptr = NULL;
}
- if(fref->filename)
- g_free(fref->filename);
+ g_free(fref->filename);
+ g_free(fref->basename);
fref->magic = MAGIC_FREE;
g_free(fref);
return NULL;
}
- frefid_t f = fileref_new(filename, rock, usage, filemode_Write);
+ /* Pass a basename of "" to ensure that this file can't be repurposed */
+ frefid_t f = fileref_new(filename, "", rock, usage, filemode_Write);
g_free(filename);
return f;
}
return NULL;
}
gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(chooser) );
- frefid_t f = fileref_new(filename, rock, usage, fmode);
+ frefid_t f = fileref_new(filename, NULL, rock, usage, fmode);
g_free(filename);
gtk_widget_destroy(chooser);
return NULL;
}
filename = g_strconcat(buf, extension, NULL);
- g_free(buf);
/* Find out what encoding filenames are in */
const gchar **charsets; /* Do not free */
path = g_strdup(osname);
g_free(osname);
- frefid_t f = fileref_new(path, rock, usage, filemode_ReadWrite);
+ frefid_t f = fileref_new(path, buf, rock, usage, filemode_ReadWrite);
g_free(path);
+ g_free(buf);
return f;
}
glk_fileref_create_from_fileref(glui32 usage, frefid_t fref, glui32 rock)
{
VALID_FILEREF(fref, return NULL);
- return fileref_new(fref->filename, rock, usage, fref->orig_filemode);
+ return fileref_new(fref->filename, fref->basename, rock, usage, fref->orig_filemode);
}
/**
/* Fileref parameters */
gchar *filename; /* Always stored in the default filename encoding, not
UTF8 or Latin-1 */
+ char *basename; /* Name from which real filename was derived */
glui32 orig_filemode; /* Used to check if the user gets a fileref in read
mode and then tries to open it in write mode */
glui32 usage;
};
-G_GNUC_INTERNAL frefid_t fileref_new(gchar *filename, glui32 rock, glui32 usage, glui32 orig_filemode);
+G_GNUC_INTERNAL frefid_t fileref_new(char *filename, char *basename, glui32 rock, glui32 usage, glui32 orig_filemode);
#endif
g_return_val_if_fail(pathname, NULL);
g_return_val_if_fail(strlen(pathname) > 0, NULL);
- frefid_t fileref = fileref_new(pathname, rock,
+ frefid_t fileref = fileref_new(pathname, NULL, rock,
textmode? fileusage_TextMode : fileusage_BinaryMode,
writemode? filemode_Write : filemode_Read);
return file_stream_new(fileref, writemode? filemode_Write : filemode_Read, rock, FALSE);
g_return_val_if_fail(pathname, NULL);
g_return_val_if_fail(strlen(pathname) > 0, NULL);
- frefid_t fileref = fileref_new(pathname, rock, textmode? fileusage_TextMode : fileusage_BinaryMode, filemode_Read);
+ frefid_t fileref = fileref_new(pathname, NULL, rock, textmode? fileusage_TextMode : fileusage_BinaryMode, filemode_Read);
return file_stream_new(fileref, filemode_Read, rock, FALSE);
}
g_slist_free(arglist);
return TRUE;
-}
\ No newline at end of file
+}