From: Jonathan Chambers Date: Wed, 2 May 2012 17:25:20 +0000 (-0400) Subject: Add tests and correctly handle using '/' in windows paths. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=cfa274f02d8d1dc0168ac650be52e98cdfd68dd0;p=mono.git Add tests and correctly handle using '/' in windows paths. --- diff --git a/eglib/src/gpath.c b/eglib/src/gpath.c index 4ae2f8f5e9e..14343494d80 100644 --- a/eglib/src/gpath.c +++ b/eglib/src/gpath.c @@ -88,6 +88,24 @@ g_build_path (const gchar *separator, const gchar *first_element, ...) return g_string_free (path, FALSE); } +static gchar* +strrchr_seperator (const gchar* filename) +{ +#ifdef G_OS_WIN32 + char *p2; +#endif + char *p; + + p = strrchr (filename, G_DIR_SEPARATOR); +#ifdef G_OS_WIN32 + p2 = strrchr (filename, '/'); + if (p2 > p) + p = p2; +#endif + + return p; +} + gchar * g_path_get_dirname (const gchar *filename) { @@ -95,7 +113,7 @@ g_path_get_dirname (const gchar *filename) size_t count; g_return_val_if_fail (filename != NULL, NULL); - p = strrchr (filename, G_DIR_SEPARATOR); + p = strrchr_seperator (filename); if (p == NULL) return g_strdup ("."); if (p == filename) @@ -119,7 +137,7 @@ g_path_get_basename (const char *filename) return g_strdup ("."); /* No separator -> filename */ - r = strrchr (filename, G_DIR_SEPARATOR); + r = strrchr_seperator (filename); if (r == NULL) return g_strdup (filename); @@ -127,7 +145,7 @@ g_path_get_basename (const char *filename) if (r [1] == 0){ char *copy = g_strdup (filename); copy [r-filename] = 0; - r = strrchr (copy, G_DIR_SEPARATOR); + r = strrchr_seperator (copy); if (r == NULL){ g_free (copy); diff --git a/eglib/test/path.c b/eglib/test/path.c index cd27b421f0b..e3832a04be4 100644 --- a/eglib/test/path.c +++ b/eglib/test/path.c @@ -158,6 +158,11 @@ test_dirname () return FAILED ("Expected c:\\home, got %s", s); g_free (s); + s = g_path_get_dirname ("c:/home/miguel"); + if (strcmp (s, "c:/home") != 0) + return FAILED ("Expected c:/home, got %s", s); + g_free (s); + s = g_path_get_dirname ("c:\\home\\dingus\\"); if (strcmp (s, "c:\\home\\dingus") != 0) return FAILED ("Expected c:\\home\\dingus, got %s", s); @@ -210,10 +215,20 @@ test_basename () return FAILED ("1 Expected dingus, got %s", s); g_free (s); + s = g_path_get_basename ("c:/home/dingus/"); + if (strcmp (s, "dingus") != 0) + return FAILED ("1 Expected dingus, got %s", s); + g_free (s); + s = g_path_get_basename ("c:\\home\\dingus"); if (strcmp (s, "dingus") != 0) return FAILED ("2 Expected dingus, got %s", s); g_free (s); + + s = g_path_get_basename ("c:/home/dingus"); + if (strcmp (s, "dingus") != 0) + return FAILED ("2 Expected dingus, got %s", s); + g_free (s); #else s = g_path_get_basename (""); if (strcmp (s, ".") != 0)