aboutsummaryrefslogtreecommitdiff
path: root/libsylph
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2009-12-17 02:51:57 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2009-12-17 02:51:57 +0000
commitd5175b3fc5fda02558b7754ba160eee360ccb7ec (patch)
treeae491e12e7e2c1b3e88127db4e438d598698e36e /libsylph
parent5fb2905b9f6c975ef03240393363471c81c1e21d (diff)
src/setup.c: check whether the specified location includes settings folder.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@2398 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'libsylph')
-rw-r--r--libsylph/libsylph-0.def1
-rw-r--r--libsylph/utils.c27
-rw-r--r--libsylph/utils.h5
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);