summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-10-02 16:30:10 -0400
committerTavian Barnes <tavianator@tavianator.com>2016-10-02 16:30:10 -0400
commitb2175be362b0a32d06d98369302d55b226b58ab1 (patch)
treefed6309efab2967279265a990637c38bffa33cc1
parent34fa233c66d6595e168fe114655857f14accfa3a (diff)
downloadbfs-b2175be362b0a32d06d98369302d55b226b58ab1.tar.xz
bftw: Add support for some exotic file types, where available.
-rw-r--r--bftw.c60
-rw-r--r--bftw.h6
-rw-r--r--color.c6
-rw-r--r--eval.c23
-rw-r--r--parse.c3
5 files changed, 96 insertions, 2 deletions
diff --git a/bftw.c b/bftw.c
index ac99a42..45d2d27 100644
--- a/bftw.c
+++ b/bftw.c
@@ -464,29 +464,58 @@ static void dirqueue_free(struct dirqueue *queue) {
/** Fill in ftwbuf fields with information from a struct dirent. */
static void ftwbuf_use_dirent(struct BFTW *ftwbuf, const struct dirent *de) {
-#if defined(_DIRENT_HAVE_D_TYPE) || defined(DT_DIR)
+#if defined(_DIRENT_HAVE_D_TYPE) || defined(DT_UNKNOWN)
switch (de->d_type) {
+#ifdef DT_BLK
case DT_BLK:
ftwbuf->typeflag = BFTW_BLK;
break;
+#endif
+#ifdef DT_CHR
case DT_CHR:
ftwbuf->typeflag = BFTW_CHR;
break;
+#endif
+#ifdef DT_DIR
case DT_DIR:
ftwbuf->typeflag = BFTW_DIR;
break;
+#endif
+#ifdef DT_DOOR
+ case DT_DOOR:
+ ftwbuf->typeflag = BFTW_DOOR;
+ break;
+#endif
+#ifdef DT_FIFO
case DT_FIFO:
ftwbuf->typeflag = BFTW_FIFO;
break;
+#endif
+#ifdef DT_LNK
case DT_LNK:
ftwbuf->typeflag = BFTW_LNK;
break;
+#endif
+#ifdef DT_PORT
+ case DT_PORT:
+ ftwbuf->typeflag = BFTW_PORT;
+ break;
+#endif
+#ifdef DT_REG
case DT_REG:
ftwbuf->typeflag = BFTW_REG;
break;
+#endif
+#ifdef DT_SOCK
case DT_SOCK:
ftwbuf->typeflag = BFTW_SOCK;
break;
+#endif
+#ifdef DT_WHT
+ case DT_WHT:
+ ftwbuf->typeflag = BFTW_WHT;
+ break;
+#endif
}
#endif
}
@@ -501,27 +530,56 @@ static int ftwbuf_stat(struct BFTW *ftwbuf, struct stat *sb, int flags) {
ftwbuf->statbuf = sb;
switch (sb->st_mode & S_IFMT) {
+#ifdef S_IFBLK
case S_IFBLK:
ftwbuf->typeflag = BFTW_BLK;
break;
+#endif
+#ifdef S_IFCHR
case S_IFCHR:
ftwbuf->typeflag = BFTW_CHR;
break;
+#endif
+#ifdef S_IFDIR
case S_IFDIR:
ftwbuf->typeflag = BFTW_DIR;
break;
+#endif
+#ifdef S_IFDOOR
+ case S_IFDOOR:
+ ftwbuf->typeflag = BFTW_DOOR;
+ break;
+#endif
+#ifdef S_IFIFO
case S_IFIFO:
ftwbuf->typeflag = BFTW_FIFO;
break;
+#endif
+#ifdef S_IFLNK
case S_IFLNK:
ftwbuf->typeflag = BFTW_LNK;
break;
+#endif
+#ifdef S_IFPORT
+ case S_IFPORT:
+ ftwbuf->typeflag = BFTW_PORT;
+ break;
+#endif
+#ifdef S_IFREG
case S_IFREG:
ftwbuf->typeflag = BFTW_REG;
break;
+#endif
+#ifdef S_IFSOCK
case S_IFSOCK:
ftwbuf->typeflag = BFTW_SOCK;
break;
+#endif
+#ifdef S_IFWHT
+ case S_IFWHT:
+ ftwbuf->typeflag = BFTW_WHT;
+ break;
+#endif
}
return 0;
diff --git a/bftw.h b/bftw.h
index 0b692b0..31498f7 100644
--- a/bftw.h
+++ b/bftw.h
@@ -27,14 +27,20 @@ enum bftw_typeflag {
BFTW_CHR,
/** Directory. */
BFTW_DIR,
+ /** Solaris door. */
+ BFTW_DOOR,
/** Pipe. */
BFTW_FIFO,
/** Symbolic link. */
BFTW_LNK,
+ /** Solaris event port. */
+ BFTW_PORT,
/** Regular file. */
BFTW_REG,
/** Socket. */
BFTW_SOCK,
+ /** BSD whiteout. */
+ BFTW_WHT,
/** An error occurred for this file. */
BFTW_ERROR,
};
diff --git a/color.c b/color.c
index 47c2fb3..6e0902b 100644
--- a/color.c
+++ b/color.c
@@ -302,6 +302,12 @@ static const char *file_color(const struct colors *colors, const char *filename,
case S_IFSOCK:
color = colors->socket;
break;
+
+#ifdef S_IFDOOR
+ case S_IFDOOR:
+ color = colors->door;
+ break;
+#endif
}
if (!color) {
diff --git a/eval.c b/eval.c
index dfc04ce..65a9186 100644
--- a/eval.c
+++ b/eval.c
@@ -26,6 +26,18 @@
#include <time.h>
#include <unistd.h>
+#ifndef S_ISDOOR
+# define S_ISDOOR(mode) false
+#endif
+
+#ifndef S_ISPORT
+# define S_ISPORT(mode) false
+#endif
+
+#ifndef S_ISWHT
+# define S_ISWHT(mode) false
+#endif
+
struct eval_state {
/** Data about the current file. */
struct BFTW *ftwbuf;
@@ -722,21 +734,30 @@ bool eval_xtype(const struct expr *expr, struct eval_state *state) {
}
}
- switch (expr->idata) {
+ switch ((enum bftw_typeflag)expr->idata) {
+ case BFTW_UNKNOWN:
+ case BFTW_ERROR:
+ break;
case BFTW_BLK:
return S_ISBLK(sb.st_mode);
case BFTW_CHR:
return S_ISCHR(sb.st_mode);
case BFTW_DIR:
return S_ISDIR(sb.st_mode);
+ case BFTW_DOOR:
+ return S_ISDOOR(sb.st_mode);
case BFTW_FIFO:
return S_ISFIFO(sb.st_mode);
case BFTW_LNK:
return S_ISLNK(sb.st_mode);
+ case BFTW_PORT:
+ return S_ISPORT(sb.st_mode);
case BFTW_REG:
return S_ISREG(sb.st_mode);
case BFTW_SOCK:
return S_ISSOCK(sb.st_mode);
+ case BFTW_WHT:
+ return S_ISWHT(sb.st_mode);
}
return false;
diff --git a/parse.c b/parse.c
index 6a4dfc6..5761dc3 100644
--- a/parse.c
+++ b/parse.c
@@ -1327,6 +1327,9 @@ static struct expr *parse_type(struct parser_state *state, int x, int arg2) {
case 'd':
typeflag = BFTW_DIR;
break;
+ case 'D':
+ typeflag = BFTW_DOOR;
+ break;
case 'p':
typeflag = BFTW_FIFO;
break;