diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2012-09-13 11:17:38 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2012-09-13 11:22:09 -0700 |
commit | 9f5d9bd94f092739f0f8e846f8e19ec30a8c0c52 (patch) | |
tree | 30a873e5a5f49582e2f58ce4715e071058259305 | |
parent | 3d4be85f3521869f2703d9efb6b25c78ef90adea (diff) | |
download | subsurface-9f5d9bd94f092739f0f8e846f8e19ec30a8c0c52.tar.gz |
Use glib file and pathname functions
My silly reimplementation of these functions was broken on Windows,
anyway. This is much cleaner.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | gtk-gui.c | 41 |
1 files changed, 7 insertions, 34 deletions
@@ -174,36 +174,6 @@ static void file_open(GtkWidget *w, gpointer data) gtk_widget_destroy(dialog); } -/* return the path and the file component contained in the full path */ -static char *path_and_file(const char *pathin, char **fileout) { - const char *slash = pathin, *next; - char *result; - size_t len, n; - - if (! pathin) { - *fileout = strdup(""); - return strdup(""); - } - while ((next = strpbrk(slash + 1, "\\/"))) - slash = next; - if (pathin != slash) - slash++; - *fileout = strdup(slash); - - /* strndup(pathin, slash - pathin) */ - n = slash - pathin; - len = strlen(pathin); - if (n < len) - len = n; - - result = (char *)malloc(len + 1); - if (!result) - return 0; - - result[len] = '\0'; - return (char *)memcpy(result, pathin, len); -} - static void file_save_as(GtkWidget *w, gpointer data) { GtkWidget *dialog; @@ -219,7 +189,8 @@ static void file_save_as(GtkWidget *w, gpointer data) NULL); gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); - current_dir = path_and_file(existing_filename, ¤t_file); + current_dir = g_path_get_dirname(existing_filename); + current_file = g_path_get_basename(existing_filename); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), current_dir); gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), current_file); @@ -250,13 +221,14 @@ static void file_save(GtkWidget *w, gpointer data) if (strcmp(existing_filename, current_default) == 0) { /* if we are using the default filename the directory * that we are creating the file in may not exist */ - char *current_def_dir, *current_def_file; + char *current_def_dir; struct stat sb; - current_def_dir = path_and_file(existing_filename, ¤t_def_file); + current_def_dir = g_path_get_dirname(existing_filename); if (stat(current_def_dir, &sb) != 0) { g_mkdir(current_def_dir, S_IRWXU); } + free(current_def_dir); } save_dives(existing_filename); mark_divelist_changed(FALSE); @@ -509,7 +481,8 @@ static void pick_default_file(GtkWidget *w, GtkButton *button) gtk_window_set_accept_focus(GTK_WINDOW(preferences), FALSE); current_default = subsurface_default_filename(); - current_def_dir = path_and_file(current_default, ¤t_def_file); + current_def_dir = g_path_get_dirname(current_default); + current_def_file = g_path_get_basename(current_default); /* it's possible that the directory doesn't exist (especially for the default) * For gtk's file select box to make sense we create it */ |