summaryrefslogtreecommitdiff
path: root/gutils.c
diff options
context:
space:
mode:
authorSebastian Wilhelmi <wilhelmi@ira.uka.de>2000-07-20 16:58:54 +0000
committerSebastian Wilhelmi <wilhelmi@src.gnome.org>2000-07-20 16:58:54 +0000
commitfec9828ac62918374fb8aa94e15a9bdf554e269e (patch)
tree7f327de3ead1d7355b5fa6144d6e264afb34e4e9 /gutils.c
parent84114c5321e4d7e4701f77f7f0e2b9b739d4035c (diff)
downloadglib-fec9828ac62918374fb8aa94e15a9bdf554e269e.tar.gz
Mark the functions g_basename and g_dirname deprecated. They will issue an
2000-07-20 Sebastian Wilhelmi <wilhelmi@ira.uka.de> * gutils.c, glib.h: Mark the functions g_basename and g_dirname deprecated. They will issue an warning once, when compiled with G_ENABLE_DEBUG, but continue to work as before. Instead the functions g_path_get_basename and g_path_get_dirname should be used, which BOTH return newly allocated memory, that has to freed by g_free. The new g_path_get_basename now strips trailing slashes from the path. This fixes #5097. For discussion see http://mail.gnome.org/pipermail/gtk-devel-list/2000-April/003139.html * gwin32.c, testglib.c, tests/dirname-test.c: Use the new functions instead of the old ones. * gmodule/libgplugin_a.c, gmodule/testgmodule.c: Use g_path_get_basename instead of the deprecated g_basename.
Diffstat (limited to 'gutils.c')
-rw-r--r--gutils.c75
1 files changed, 74 insertions, 1 deletions
diff --git a/gutils.c b/gutils.c
index c9f2c2805..794f4ea69 100644
--- a/gutils.c
+++ b/gutils.c
@@ -278,6 +278,17 @@ gchar*
g_basename (const gchar *file_name)
{
register gchar *base;
+#ifdef G_ENABLE_DEBUG
+ static gboolean first_call = TRUE;
+
+ if (first_call)
+ {
+ g_warning("g_basename is deprecated. Use g_path_get_basename instead.");
+ g_warning("Watch out! You have to g_free the string returned by "
+ "g_path_get_basename.");
+ first_call = FALSE;
+ }
+#endif /* G_ENABLE_DEBUG */
g_return_val_if_fail (file_name != NULL, NULL);
@@ -293,6 +304,52 @@ g_basename (const gchar *file_name)
return (gchar*) file_name;
}
+gchar*
+g_path_get_basename (const gchar *file_name)
+{
+ register gint base;
+ register gint last_nonslash;
+ guint len;
+ gchar *retval;
+
+ g_return_val_if_fail (file_name != NULL, NULL);
+
+ if (file_name[0] == '\0')
+ /* empty string */
+ return g_strdup (".");
+
+ last_nonslash = strlen (file_name) - 1;
+
+ while (last_nonslash >= 0 && file_name [last_nonslash] == G_DIR_SEPARATOR)
+ last_nonslash--;
+
+ if (last_nonslash == -1)
+ /* string only containing slashes */
+ return g_strdup (G_DIR_SEPARATOR_S);
+
+#ifdef G_OS_WIN32
+ if (last_nonslash == 1 && isalpha (file_name[0]) && file_name[1] == ':')
+ /* string only containing slashes and a drive */
+ return g_strdup (G_DIR_SEPARATOR_S);
+#endif /* G_OS_WIN32 */
+
+ base = last_nonslash;
+
+ while (base >=0 && file_name [base] != G_DIR_SEPARATOR)
+ base--;
+
+#ifdef G_OS_WIN32
+ if (base == -1 && isalpha (file_name[0]) && file_name[1] == ':')
+ base = 1;
+#endif /* G_OS_WIN32 */
+
+ len = last_nonslash - base;
+ retval = g_malloc (len + 1);
+ memcpy (retval, file_name + base + 1, len);
+ retval [len] = '\0';
+ return retval;
+}
+
gboolean
g_path_is_absolute (const gchar *file_name)
{
@@ -326,7 +383,7 @@ g_path_skip_root (gchar *file_name)
}
gchar*
-g_dirname (const gchar *file_name)
+g_path_get_dirname (const gchar *file_name)
{
register gchar *base;
register guint len;
@@ -348,6 +405,22 @@ g_dirname (const gchar *file_name)
}
gchar*
+g_dirname (const gchar *file_name)
+{
+#ifdef G_ENABLE_DEBUG
+ static gboolean first_call = TRUE;
+
+ if (first_call)
+ {
+ g_warning("g_dirname is deprecated. Use g_path_get_dirname instead.");
+ first_call = FALSE;
+ }
+#endif /* G_ENABLE_DEBUG */
+
+ return g_path_get_dirname (file_name);
+}
+
+gchar*
g_get_current_dir (void)
{
gchar *buffer = NULL;