diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2016-10-02 16:30:10 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2016-10-02 16:30:10 -0400 |
commit | b2175be362b0a32d06d98369302d55b226b58ab1 (patch) | |
tree | fed6309efab2967279265a990637c38bffa33cc1 | |
parent | 34fa233c66d6595e168fe114655857f14accfa3a (diff) | |
download | bfs-b2175be362b0a32d06d98369302d55b226b58ab1.tar.xz |
bftw: Add support for some exotic file types, where available.
-rw-r--r-- | bftw.c | 60 | ||||
-rw-r--r-- | bftw.h | 6 | ||||
-rw-r--r-- | color.c | 6 | ||||
-rw-r--r-- | eval.c | 23 | ||||
-rw-r--r-- | parse.c | 3 |
5 files changed, 96 insertions, 2 deletions
@@ -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; @@ -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, }; @@ -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) { @@ -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; @@ -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; |