+struct ads_entry *dentry_get_ads_entry(struct dentry *dentry,
+ const char *stream_name)
+{
+ size_t stream_name_len = strlen(stream_name);
+ if (!stream_name)
+ return NULL;
+ for (u16 i = 0; i < dentry->num_ads; i++)
+ if (ads_entry_has_name(&dentry->ads_entries[i],
+ stream_name, stream_name_len))
+ return &dentry->ads_entries[i];
+ return NULL;
+}
+
+/* Add an alternate stream entry to a dentry and return a pointer to it, or NULL
+ * on failure. */
+struct ads_entry *dentry_add_ads(struct dentry *dentry, const char *stream_name)
+{
+ u16 num_ads = dentry->num_ads + 1;
+ struct ads_entry *ads_entries;
+ struct ads_entry *new_entry;
+ if (num_ads == 0xffff)
+ return NULL;
+ ads_entries = MALLOC(num_ads * sizeof(struct ads_entry));
+ if (!ads_entries)
+ return NULL;
+
+ new_entry = &ads_entries[num_ads - 1];
+ if (change_ads_name(new_entry, stream_name) != 0) {
+ FREE(ads_entries);
+ return NULL;
+ }
+
+ memcpy(ads_entries, dentry->ads_entries,
+ (num_ads - 1) * sizeof(struct ads_entry));
+ FREE(dentry->ads_entries);
+ dentry->ads_entries = ads_entries;
+ dentry->num_ads = num_ads;
+ return memset(new_entry, 0, sizeof(struct ads_entry));
+}
+
+void dentry_remove_ads(struct dentry *dentry, struct ads_entry *sentry)
+{
+ destroy_ads_entry(sentry);
+ memcpy(sentry, sentry + 1,
+ (dentry->num_ads - (sentry - dentry->ads_entries))
+ * sizeof(struct ads_entry));
+ dentry->num_ads--;
+}
+