- struct avoided_name const *p;
- for (p = avoided_names; p; p = p->next)
- if (strcmp (p->name, name) == 0)
- return 1;
- return 0;
+ return hash_string_lookup (avoided_name_table, name);
+}
+
+\f
+static Hash_table *individual_file_table;
+
+static void
+register_individual_file (char const *name)
+{
+ struct stat st;
+
+ if (deref_stat (dereference_option, name, &st) != 0)
+ return; /* Will be complained about later */
+ if (S_ISDIR (st.st_mode))
+ return;
+
+ hash_string_insert (&individual_file_table, name);
+}
+
+bool
+is_individual_file (char const *name)
+{
+ return hash_string_lookup (individual_file_table, name);
+}
+
+\f
+
+/* Return the size of the prefix of FILE_NAME that is removed after
+ stripping NUM leading file name components. NUM must be
+ positive. */
+
+size_t
+stripped_prefix_len (char const *file_name, size_t num)
+{
+ char const *p = file_name + FILE_SYSTEM_PREFIX_LEN (file_name);
+ while (ISSLASH (*p))
+ p++;
+ while (*p)
+ {
+ bool slash = ISSLASH (*p);
+ p++;
+ if (slash)
+ {
+ if (--num == 0)
+ return p - file_name;
+ while (ISSLASH (*p))
+ p++;
+ }
+ }
+ return -1;
+}
+\f
+/* Return nonzero if NAME contains ".." as a file name component. */
+bool
+contains_dot_dot (char const *name)
+{
+ char const *p = name + FILE_SYSTEM_PREFIX_LEN (name);
+
+ for (;; p++)
+ {
+ if (p[0] == '.' && p[1] == '.' && (ISSLASH (p[2]) || !p[2]))
+ return 1;
+
+ while (! ISSLASH (*p))
+ {
+ if (! *p++)
+ return 0;
+ }
+ }