- Made f_name() and f_name_cmp() take const pointers.
authorWayne Davison <wayned@samba.org>
Sat, 14 Jul 2007 21:21:15 +0000 (21:21 +0000)
committerWayne Davison <wayned@samba.org>
Sat, 14 Jul 2007 21:21:15 +0000 (21:21 +0000)
- Added f_name_has_prefix().

flist.c

diff --git a/flist.c b/flist.c
index e33cd58..87a15b1 100644 (file)
--- a/flist.c
+++ b/flist.c
@@ -2449,6 +2449,8 @@ static void output_flist(struct file_list *flist)
 enum fnc_state { s_DIR, s_SLASH, s_BASE, s_TRAILING };
 enum fnc_type { t_PATH, t_ITEM };
 
 enum fnc_state { s_DIR, s_SLASH, s_BASE, s_TRAILING };
 enum fnc_type { t_PATH, t_ITEM };
 
+static int found_prefix;
+
 /* Compare the names of two file_struct entities, similar to how strcmp()
  * would do if it were operating on the joined strings.
  *
 /* Compare the names of two file_struct entities, similar to how strcmp()
  * would do if it were operating on the joined strings.
  *
@@ -2464,7 +2466,7 @@ enum fnc_type { t_PATH, t_ITEM };
  * cannot (and never is in the current codebase).  The basename component
  * may be NULL (for a removed item), in which case it is considered to be
  * after any existing item. */
  * cannot (and never is in the current codebase).  The basename component
  * may be NULL (for a removed item), in which case it is considered to be
  * after any existing item. */
-int f_name_cmp(struct file_struct *f1, struct file_struct *f2)
+int f_name_cmp(const struct file_struct *f1, const struct file_struct *f2)
 {
        int dif;
        const uchar *c1, *c2;
 {
        int dif;
        const uchar *c1, *c2;
@@ -2569,6 +2571,7 @@ int f_name_cmp(struct file_struct *f1, struct file_struct *f2)
                                }
                                /* FALL THROUGH */
                        case s_TRAILING:
                                }
                                /* FALL THROUGH */
                        case s_TRAILING:
+                               found_prefix = 1;
                                if (!*c1)
                                        return 0;
                                type2 = t_ITEM;
                                if (!*c1)
                                        return 0;
                                type2 = t_ITEM;
@@ -2582,6 +2585,16 @@ int f_name_cmp(struct file_struct *f1, struct file_struct *f2)
        return dif;
 }
 
        return dif;
 }
 
+/* Returns 1 if f1's filename has all of f2's filename as a prefix.  This does
+ * not match if f2's basename is not an exact match of a path element in f1.
+ * E.g. /path/foo is not a prefix of /path/foobar/baz, but /path/foobar is. */
+int f_name_has_prefix(const struct file_struct *f1, const struct file_struct *f2)
+{
+       found_prefix = 0;
+       f_name_cmp(f1, f2);
+       return found_prefix;
+}
+
 char *f_name_buf(void)
 {
        static char names[5][MAXPATHLEN];
 char *f_name_buf(void)
 {
        static char names[5][MAXPATHLEN];
@@ -2596,7 +2609,7 @@ char *f_name_buf(void)
  * buffer or one of 5 static buffers if fbuf is NULL.  No size-checking is
  * done because we checked the size when creating the file_struct entry.
  */
  * buffer or one of 5 static buffers if fbuf is NULL.  No size-checking is
  * done because we checked the size when creating the file_struct entry.
  */
-char *f_name(struct file_struct *f, char *fbuf)
+char *f_name(const struct file_struct *f, char *fbuf)
 {
        if (!f || !F_IS_ACTIVE(f))
                return NULL;
 {
        if (!f || !F_IS_ACTIVE(f))
                return NULL;