Skip to content

Commit

Permalink
mdirs: extract DT_* handling
Browse files Browse the repository at this point in the history
  • Loading branch information
leahneukirchen committed Mar 8, 2020
1 parent 5822566 commit 6dd0799
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions blaze822_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ struct message {
#define lc(c) ((c) | 0x20)
#define uc(c) ((c) & 0xdf)

// dirent type that can be a mail/dir (following symlinks)
#if defined(DT_REG) && defined(DT_LNK) && defined(DT_UNKNOWN)
#define MAIL_DT(t) (t == DT_REG || t == DT_LNK || t == DT_UNKNOWN)
#define DIR_DT(t) (t == DT_DIR || t == DT_UNKNOWN)
#else
#define MAIL_DT(t) (1)
#define DIR_DT(t) (1)
#endif

void *mymemmem(const void *h0, size_t k, const void *n0, size_t l);
6 changes: 3 additions & 3 deletions mdirs.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <unistd.h>

#include "blaze822.h"
#include "blaze822_priv.h"

static char sep = '\n';
int aflag;
Expand Down Expand Up @@ -47,10 +48,9 @@ mdirs(char *fpath)
}

while ((d = readdir(dir))) {
#if defined(DT_DIR) && defined(DT_UNKNOWN)
if (d->d_type != DT_DIR && d->d_type != DT_UNKNOWN)
if (!DIR_DT(d->d_type))
continue;
#endif

if (d->d_name[0] == '.' &&
d->d_name[1] == 0)
continue;
Expand Down

0 comments on commit 6dd0799

Please sign in to comment.