* Copyright (C) 1995-1998 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
+ * Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
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);
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)
{
}
gchar*
-g_dirname (const gchar *file_name)
+g_path_get_dirname (const gchar *file_name)
{
register gchar *base;
register guint len;
}
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;
guint len = 17;
gchar buffer[17];
- if (GetUserName (buffer, &len))
+ if (GetUserName ((LPTSTR) buffer, (LPDWORD) &len))
{
g_user_name = g_strdup (buffer);
g_real_name = g_strdup (buffer);
char *result = nl_langinfo (CODESET);
return g_strdup (result);
#else
+#ifndef G_OS_WIN32
/* FIXME: Do something more intelligent based on setlocale (LC_CTYPE, NULL)
*/
return g_strdup ("ISO-8859-1");
+#else
+ /* On Win32 we always use UTF-8. At least in GDK. SO should we
+ * therefore return that?
+ */
+ return g_strdup ("UTF-8");
+#endif
#endif
}