diff options
Diffstat (limited to 'libsylph')
-rw-r--r-- | libsylph/libsylph-0.def | 1 | ||||
-rw-r--r-- | libsylph/utils.c | 27 | ||||
-rw-r--r-- | libsylph/utils.h | 5 |
3 files changed, 33 insertions, 0 deletions
diff --git a/libsylph/libsylph-0.def b/libsylph/libsylph-0.def index ad74b796..20df1f10 100644 --- a/libsylph/libsylph-0.def +++ b/libsylph/libsylph-0.def @@ -670,3 +670,4 @@ EXPORTS xml_truncate_buf @ 668
xml_unescape_str @ 669
strcasestr_with_skip_quote @ 670
+ is_path_parent @ 671
diff --git a/libsylph/utils.c b/libsylph/utils.c index 88b2fafb..3a14e690 100644 --- a/libsylph/utils.c +++ b/libsylph/utils.c @@ -392,6 +392,33 @@ gint path_cmp(const gchar *s1, const gchar *s2) #endif } +/* return TRUE if parent is equal to or ancestor of child */ +gboolean is_path_parent(const gchar *parent, const gchar *child) +{ + gint plen; + const gchar *base; + + g_return_val_if_fail(parent != NULL, FALSE); + g_return_val_if_fail(child != NULL, FALSE); + + plen = strlen(parent); + while (plen > 0 && G_IS_DIR_SEPARATOR(parent[plen - 1])) + plen--; + +#ifdef G_OS_WIN32 + if (!g_ascii_strncasecmp(parent, child, plen)) { +#else + if (!strncmp(parent, child, plen)) { +#endif + base = child + plen; + if (!G_IS_DIR_SEPARATOR(*base) && *base != '\0') + return FALSE; + return TRUE; + } + + return FALSE; +} + /* remove trailing return code */ gchar *strretchomp(gchar *str) { diff --git a/libsylph/utils.h b/libsylph/utils.h index d062041a..c911fa5f 100644 --- a/libsylph/utils.h +++ b/libsylph/utils.h @@ -231,16 +231,21 @@ gint strcmp2 (const gchar *s1, const gchar *s2); gint path_cmp (const gchar *s1, const gchar *s2); +gboolean is_path_parent (const gchar *parent, + const gchar *child); + gchar *strretchomp (gchar *str); gchar *strtailchomp (gchar *str, gchar tail_char); gchar *strcrchomp (gchar *str); + gchar *strcasestr (const gchar *haystack, const gchar *needle); gpointer my_memmem (gconstpointer haystack, size_t haystacklen, gconstpointer needle, size_t needlelen); + gchar *strncpy2 (gchar *dest, const gchar *src, size_t n); |