X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fnames.c;h=46581e0738f5228ed542a8af4ee29e983766f44e;hb=f364d50661977d5db6df03470e85999a88ec5981;hp=ee68749bb921be22ce3b13bcfeb3a4e8be8be205;hpb=3590887776356e895863847e3b58d6a2962009c6;p=chaz%2Ftar diff --git a/src/names.c b/src/names.c index ee68749..46581e0 100644 --- a/src/names.c +++ b/src/names.c @@ -595,6 +595,17 @@ name_match (const char *path) } } +/* Returns true if all names from the namelist were processed */ +bool +names_done () +{ + struct name const *cursor; + for (cursor = namelist; cursor; cursor = cursor->next) + if (cursor->regexp || (!cursor->found && !cursor->fake)) + return false; + return true; +} + /* Print the names of things in the namelist that were not matched. */ void names_notfound (void) @@ -1043,21 +1054,29 @@ safer_name_suffix (char const *file_name, bool link_target) return (char *) p; } -char const * -cut_path_elements (char const *file_name, size_t num) +/* Return the size of the prefix of FILE_NAME that is removed after + stripping NUM leading path name components. NUM must be + positive. */ + +size_t +stripped_prefix_len (char const *file_name, size_t num) { - char const *p = file_name; - if (ISSLASH (*p)) + char const *p = file_name + FILESYSTEM_PREFIX_LEN (file_name); + while (ISSLASH (*p)) p++; - for (; *p; p++) + while (*p) { - if (ISSLASH (*p)) + bool slash = ISSLASH (*p); + p++; + if (slash) { if (--num == 0) - return p + 1; + return p - file_name; + while (ISSLASH (*p)) + p++; } } - return NULL; + return -1; } /* Return nonzero if NAME contains ".." as a path name component. */