mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
replaced stdndup() with the inlined equivalent
don't kill the OS incompatibility messenger. 1) http://stackoverflow.com/questions/6062822/whats-wrong-with-strndup stdndup() is POSIX 2008, but apparently not available on OSX and Windows it could be made potentially application global (e.g. a local "stdndup.h") 2) free() memory at pointer "current_dir", once we are done. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
642c83f532
commit
9d10574694
1 changed files with 18 additions and 1 deletions
19
gtk-gui.c
19
gtk-gui.c
|
@ -175,6 +175,8 @@ static void file_open(GtkWidget *w, gpointer data)
|
||||||
/* return the path and the file component contained in the full path */
|
/* return the path and the file component contained in the full path */
|
||||||
static char *path_and_file(char *pathin, char **fileout) {
|
static char *path_and_file(char *pathin, char **fileout) {
|
||||||
char *slash = pathin, *next;
|
char *slash = pathin, *next;
|
||||||
|
char *result;
|
||||||
|
size_t len, n;
|
||||||
|
|
||||||
if (! pathin) {
|
if (! pathin) {
|
||||||
*fileout = strdup("");
|
*fileout = strdup("");
|
||||||
|
@ -185,7 +187,19 @@ static char *path_and_file(char *pathin, char **fileout) {
|
||||||
if (pathin != slash)
|
if (pathin != slash)
|
||||||
slash++;
|
slash++;
|
||||||
*fileout = strdup(slash);
|
*fileout = strdup(slash);
|
||||||
return strndup(pathin, slash - pathin);
|
|
||||||
|
/* 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)
|
static void file_save_as(GtkWidget *w, gpointer data)
|
||||||
|
@ -206,6 +220,9 @@ static void file_save_as(GtkWidget *w, gpointer data)
|
||||||
current_dir = path_and_file(existing_filename, ¤t_file);
|
current_dir = path_and_file(existing_filename, ¤t_file);
|
||||||
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), current_dir);
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), current_dir);
|
||||||
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), current_file);
|
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), current_file);
|
||||||
|
|
||||||
|
free(current_dir);
|
||||||
|
|
||||||
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
||||||
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue