#include <atalk/ftw.h>
+#ifndef HAVE_MEMPCPY
#define mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N)))
+#endif
#define NDEBUG 1
#include <assert.h>
static int ftw_dir (struct ftw_data *data, struct STAT *st,
struct dir_data *old_dir) internal_function;
+typedef void (*__free_fn_t) (void *__nodep);
+typedef struct node_t {
+ const void *key;
+ struct node_t *left;
+ struct node_t *right;
+ unsigned int red:1;
+} *node;
+
+static void tdestroy_recurse (node root, __free_fn_t freefct)
+{
+ if (root->left != NULL)
+ tdestroy_recurse (root->left, freefct);
+ if (root->right != NULL)
+ tdestroy_recurse (root->right, freefct);
+ (*freefct) ((void *) root->key);
+ /* Free the node itself. */
+ free (root);
+}
+
+static void mytdestroy (void *vroot, __free_fn_t freefct)
+{
+ node root = (node) vroot;
+
+ if (root != NULL)
+ tdestroy_recurse (root, freefct);
+}
+
static char *mystpcpy(char *a, const char *b)
{
strcpy(a, b);
if (dfdp != NULL && *dfdp != -1)
{
- int fd = openat(*dfdp, data->dirbuf + data->ftw.base,
- O_RDONLY | O_DIRECTORY | O_NDELAY);
+ int fd = openat(*dfdp, data->dirbuf + data->ftw.base, O_RDONLY);
dirp->stream = NULL;
if (fd != -1 && (dirp->stream = fdopendir (fd)) == NULL)
close(fd);
static int
-process_entry (struct ftw_data *data, struct dir_data *dir, const char *name,
- size_t namlen, int d_type)
+process_entry (struct ftw_data *data, struct dir_data *dir, const char *name, size_t namlen)
{
struct STAT st;
int result = 0;
result = -1;
else if (data->flags & FTW_PHYS)
flag = FTW_NS;
- else if (d_type == DT_LNK)
- flag = FTW_SLN;
else
{
if (dir->streamfd != -1)
while (dir.stream != NULL && (d = __readdir64 (dir.stream)) != NULL)
{
- result = process_entry (data, &dir, d->d_name, NAMLEN (d), d->d_type);
+ result = process_entry (data, &dir, d->d_name, NAMLEN (d));
if (result != 0)
break;
}
char *endp = strchr (runp, '\0');
// XXX Should store the d_type values as well?!
- result = process_entry (data, &dir, runp, endp - runp, DT_UNKNOWN);
+ result = process_entry (data, &dir, runp, endp - runp);
runp = endp + 1;
}
/* We have to be able to go back to the current working
directory. The best way to do this is to use a file
descriptor. */
- cwdfd = open (".", O_RDONLY | O_DIRECTORY);
+ cwdfd = open (".", O_RDONLY);
if (cwdfd == -1)
{
/* Try getting the directory name. This can be needed if
/* Free all memory. */
out_fail:
save_err = errno;
- __tdestroy (data.known_objects, free);
+ mytdestroy (data.known_objects, free);
free (data.dirbuf);
__set_errno (save_err);