From 569e6f432b6ba46d3a57a89ef4d9834825a18e49 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Sat, 14 Jul 2007 21:21:15 +0000 Subject: [PATCH] - Made f_name() and f_name_cmp() take const pointers. - Added f_name_has_prefix(). --- flist.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/flist.c b/flist.c index e33cd585..87a15b10 100644 --- 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 }; +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. * @@ -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. */ -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; @@ -2569,6 +2571,7 @@ int f_name_cmp(struct file_struct *f1, struct file_struct *f2) } /* FALL THROUGH */ case s_TRAILING: + found_prefix = 1; 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; } +/* 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]; @@ -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. */ -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; -- 2.34.1