diff --git a/ChangeLog b/ChangeLog index 113b029c14..4032cb7da8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,13 @@ +2009-03-27 Enrico Tröger + + * src/keyfile.c, src/utils.c, src/utils.h: + Add utils_path_skip_root(), a relative path safe variant of + g_path_skip_root (forgotten patch by Colomban Wendling, #2518658). + + 2009-03-26 Enrico Tröger - * src\main.c, src\plugins.c, src\win32.c, src\win32.h: + * src/main.c, src/plugins.c, src/win32.c, src/win32.h: Use g_win32_get_package_installation_directory_of_module() on Windows with newer GLib versions instead of deprecated API. * src/keybindings.c: diff --git a/src/keyfile.c b/src/keyfile.c index f9e7d75475..3c0626274f 100644 --- a/src/keyfile.c +++ b/src/keyfile.c @@ -231,7 +231,6 @@ static gchar *get_session_file_string(GeanyDocument *doc) { gchar *fname; gchar *locale_filename; - gchar *rootless_filename; GeanyFiletype *ft = doc->file_type; if (ft == NULL) /* can happen when saving a new file when quitting */ @@ -243,10 +242,7 @@ static gchar *get_session_file_string(GeanyDocument *doc) * writing with usual colons which must never appear in a filename and replace them * back when we read the file again from the file. * (g_path_skip_root() to skip C:\... on Windows) */ - rootless_filename = (gchar *) g_path_skip_root(locale_filename); - if (locale_filename == NULL) - rootless_filename = locale_filename; - g_strdelimit(rootless_filename, ";", ':'); + g_strdelimit((gchar*) utils_path_skip_root(locale_filename), ";", ':'); fname = g_strdup_printf("%d;%s;%d;%d;%d;%d;%d;%s;%d", sci_get_current_position(doc->editor->sci), @@ -894,7 +890,6 @@ static gboolean open_session_file(gchar **tmp, guint len) guint pos; const gchar *ft_name; gchar *locale_filename; - gchar *rootless_filename; gint enc_idx, indent_type; gboolean ro, auto_indent, line_wrapping; /** TODO when we have a global pref for line breaking, use its value */ @@ -911,10 +906,7 @@ static gboolean open_session_file(gchar **tmp, guint len) /* try to get the locale equivalent for the filename */ locale_filename = utils_get_locale_from_utf8(tmp[7]); /* replace ':' back with ';' (see get_session_file_string for details) */ - rootless_filename = (gchar *) g_path_skip_root(locale_filename); - if (locale_filename == NULL) - rootless_filename = locale_filename; - g_strdelimit(rootless_filename, ":", ';'); + g_strdelimit((gchar*) utils_path_skip_root(locale_filename), ":", ';'); if (len > 8) line_breaking = atoi(tmp[8]); diff --git a/src/utils.c b/src/utils.c index 7df9cdf826..14e834a8fc 100644 --- a/src/utils.c +++ b/src/utils.c @@ -319,6 +319,19 @@ gboolean utils_is_absolute_path(const gchar *path) } +/* Skips root if path is absolute, do nothing otherwise. + * This is a relative-safe version of g_path_skip_root(). + */ +const gchar *utils_path_skip_root(const gchar *path) +{ + const gchar *path_relative; + + path_relative = g_path_skip_root(path); + + return (path_relative != NULL) ? path_relative : path; +} + + gdouble utils_scale_round(gdouble val, gdouble factor) { /*val = floor(val * factor + 0.5);*/ diff --git a/src/utils.h b/src/utils.h index e0edd3168a..e2752a1a3b 100644 --- a/src/utils.h +++ b/src/utils.h @@ -76,6 +76,8 @@ gboolean utils_atob(const gchar *str); gboolean utils_is_absolute_path(const gchar *path); +const gchar *utils_path_skip_root(const gchar *path); + gdouble utils_scale_round(gdouble val, gdouble factor); gboolean utils_str_equal(const gchar *a, const gchar *b);