+
+/* Return a copy of the full filename of a flist entry, using the indicated
+ * buffer. No size-checking is done because we checked the size when creating
+ * the file_struct entry.
+ */
+char *f_name_to(struct file_struct *f, char *fbuf)
+{
+ if (!f || !f->basename)
+ return NULL;
+
+ if (f->dirname) {
+ int len = strlen(f->dirname);
+ memcpy(fbuf, f->dirname, len);
+ fbuf[len] = '/';
+ strcpy(fbuf + len + 1, f->basename);
+ } else
+ strcpy(fbuf, f->basename);
+ return fbuf;
+}
+
+
+/* Like f_name_to(), but we rotate through 5 static buffers of our own. */
+char *f_name(struct file_struct *f)
+{
+ static char names[5][MAXPATHLEN];
+ static unsigned int n;
+
+ n = (n + 1) % (sizeof names / sizeof names[0]);
+
+ return f_name_to(f, names[n]);
+}
+
+
+/* Do a non-recursive scan of the named directory, possibly ignoring all
+ * exclude rules except for the daemon's. If "dlen" is >=0, it is the length
+ * of the dirname string, and also indicates that "dirname" is a MAXPATHLEN
+ * buffer (the functions we call will append names onto the end, but the old
+ * dir value will be restored on exit). */
+struct file_list *get_dirlist(char *dirname, int dlen,
+ int ignore_filter_rules)
+{
+ struct file_list *dirlist;
+ char dirbuf[MAXPATHLEN];
+ int save_recurse = recurse;
+
+ if (dlen < 0) {
+ dlen = strlcpy(dirbuf, dirname, MAXPATHLEN);
+ if (dlen >= MAXPATHLEN)
+ return NULL;
+ dirname = dirbuf;
+ }
+
+ dirlist = flist_new(WITHOUT_HLINK, "get_dirlist");
+
+ recurse = 0;
+ send_directory(ignore_filter_rules ? -2 : -1, dirlist, dirname, dlen);
+ recurse = save_recurse;
+ if (do_progress)
+ flist_count_offset += dirlist->count;
+
+ clean_flist(dirlist, 0, 0);
+
+ if (verbose > 3)
+ output_flist(dirlist);
+
+ return dirlist;
+}