+#ifdef __WIN32__
+# define compare_utf16le_names compare_utf16le_names_case_insensitive
+#else
+# define compare_utf16le_names compare_utf16le_names_case_sensitive
+#endif
+
+
+#ifdef __WIN32__
+static int
+dentry_compare_names_case_insensitive(const struct wim_dentry *d1,
+ const struct wim_dentry *d2)
+{
+ return compare_utf16le_names_case_insensitive(d1->file_name,
+ d1->file_name_nbytes,
+ d2->file_name,
+ d2->file_name_nbytes);
+}
+#endif /* __WIN32__ */
+
+static int
+dentry_compare_names_case_sensitive(const struct wim_dentry *d1,
+ const struct wim_dentry *d2)
+{
+ return compare_utf16le_names_case_sensitive(d1->file_name,
+ d1->file_name_nbytes,
+ d2->file_name,
+ d2->file_name_nbytes);
+}
+
+#ifdef __WIN32__
+# define dentry_compare_names dentry_compare_names_case_insensitive
+#else
+# define dentry_compare_names dentry_compare_names_case_sensitive
+#endif
+
+/* Return %true iff the alternate data stream entry @entry has the UTF-16LE
+ * stream name @name that has length @name_nbytes bytes. */
+static inline bool
+ads_entry_has_name(const struct wim_ads_entry *entry,
+ const utf16lechar *name, size_t name_nbytes)
+{
+ return !compare_utf16le_names(name, name_nbytes,
+ entry->stream_name,
+ entry->stream_name_nbytes);
+}
+
+/* Given a UTF-16LE filename and a directory, look up the dentry for the file.
+ * Return it if found, otherwise NULL. This is case-sensitive on UNIX and
+ * case-insensitive on Windows. */
+struct wim_dentry *
+get_dentry_child_with_utf16le_name(const struct wim_dentry *dentry,
+ const utf16lechar *name,
+ size_t name_nbytes)
+{
+ struct rb_node *node;
+
+#ifdef __WIN32__
+ node = dentry->d_inode->i_children_case_insensitive.rb_node;
+#else
+ node = dentry->d_inode->i_children.rb_node;
+#endif
+
+ struct wim_dentry *child;
+ while (node) {
+ #ifdef __WIN32__
+ child = rb_entry(node, struct wim_dentry, rb_node_case_insensitive);
+ #else
+ child = rbnode_dentry(node);
+ #endif
+ int result = compare_utf16le_names(name, name_nbytes,
+ child->file_name,
+ child->file_name_nbytes);
+ if (result < 0)
+ node = node->rb_left;
+ else if (result > 0)
+ node = node->rb_right;
+ else {
+ #ifdef __WIN32__
+ if (!list_empty(&child->case_insensitive_conflict_list))
+ {
+ WARNING("Result of case-insensitive lookup is ambiguous "
+ "(returning \"%ls\" instead of \"%ls\")",
+ child->file_name,
+ container_of(child->case_insensitive_conflict_list.next,
+ struct wim_dentry,
+ case_insensitive_conflict_list)->file_name);
+ }
+ #endif
+ return child;
+ }