summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eval.c2
-rw-r--r--printf.c2
-rw-r--r--util.c73
-rw-r--r--util.h2
4 files changed, 39 insertions, 40 deletions
diff --git a/eval.c b/eval.c
index ca8c78f..551f069 100644
--- a/eval.c
+++ b/eval.c
@@ -600,7 +600,7 @@ bool eval_fls(const struct expr *expr, struct eval_state *state) {
uintmax_t ino = statbuf->ino;
uintmax_t blocks = ((uintmax_t)statbuf->blocks*BFS_STAT_BLKSIZE + 1023)/1024;
char mode[11];
- format_mode(statbuf->mode, mode);
+ xstrmode(statbuf->mode, mode);
char acl = bfs_check_acl(ftwbuf) > 0 ? '+' : ' ';
uintmax_t nlink = statbuf->nlink;
if (fprintf(file, "%9ju %6ju %s%c %2ju ", ino, blocks, mode, acl, nlink) < 0) {
diff --git a/printf.c b/printf.c
index 124be22..c30868d 100644
--- a/printf.c
+++ b/printf.c
@@ -342,7 +342,7 @@ static int bfs_printf_M(FILE *file, const struct bfs_printf *directive, const st
}
char buf[11];
- format_mode(statbuf->mode, buf);
+ xstrmode(statbuf->mode, buf);
return fprintf(file, directive->str, buf);
}
diff --git a/util.c b/util.c
index 715396c..b66dd18 100644
--- a/util.c
+++ b/util.c
@@ -15,7 +15,6 @@
****************************************************************************/
#include "util.h"
-#include "bftw.h"
#include "dstring.h"
#include <errno.h>
#include <fcntl.h>
@@ -168,44 +167,44 @@ char *xregerror(int err, const regex_t *regex) {
return str;
}
-void format_mode(mode_t mode, char str[11]) {
+/** Get the single character describing the given file type. */
+static char type_char(mode_t mode) {
+ switch (mode & S_IFMT) {
+ case S_IFREG:
+ return '-';
+ case S_IFBLK:
+ return 'b';
+ case S_IFCHR:
+ return 'c';
+ case S_IFDIR:
+ return 'd';
+ case S_IFLNK:
+ return 'l';
+ case S_IFIFO:
+ return 'p';
+ case S_IFSOCK:
+ return 's';
+#ifdef S_IFDOOR
+ case S_IFDOOR:
+ return 'D';
+#endif
+#ifdef S_IFPORT
+ case S_IFPORT:
+ return 'P';
+#endif
+#ifdef S_IFWHT
+ case S_IFWHT:
+ return 'w';
+#endif
+ }
+
+ return '?';
+}
+
+void xstrmode(mode_t mode, char str[11]) {
strcpy(str, "----------");
- switch (bftw_mode_to_type(mode)) {
- case BFTW_REG:
- break;
- case BFTW_BLK:
- str[0] = 'b';
- break;
- case BFTW_CHR:
- str[0] = 'c';
- break;
- case BFTW_DIR:
- str[0] = 'd';
- break;
- case BFTW_DOOR:
- str[0] = 'D';
- break;
- case BFTW_LNK:
- str[0] = 'l';
- break;
- case BFTW_FIFO:
- str[0] = 'p';
- break;
- case BFTW_PORT:
- str[0] = 'P';
- break;
- case BFTW_SOCK:
- str[0] = 's';
- break;
- case BFTW_WHT:
- str[0] = 'w';
- break;
- case BFTW_UNKNOWN:
- case BFTW_ERROR:
- str[0] = '?';
- break;
- }
+ str[0] = type_char(mode);
if (mode & 00400) {
str[1] = 'r';
diff --git a/util.h b/util.h
index 6e7c1f2..b10e0e4 100644
--- a/util.h
+++ b/util.h
@@ -166,7 +166,7 @@ char *xregerror(int err, const regex_t *regex);
* @param str
* The string to hold the formatted mode.
*/
-void format_mode(mode_t mode, char str[11]);
+void xstrmode(mode_t mode, char str[11]);
/**
* basename() variant that doesn't modify the input.