summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-03-11 16:41:37 -0500
committerTavian Barnes <tavianator@tavianator.com>2017-03-11 16:41:37 -0500
commiteb18f806da9d39e21362080ab4f4ab816eeeb0d5 (patch)
treec75df495cc6a32cb55847f3cbc3dac89d3ad7758 /util.c
parent74bd445d659bd619d76e109f7b02bb7714eed95f (diff)
downloadbfs-eb18f806da9d39e21362080ab4f4ab816eeeb0d5.tar.xz
Implement -ls and -fls
Diffstat (limited to 'util.c')
-rw-r--r--util.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/util.c b/util.c
index f3f2c5f..98db1d7 100644
--- a/util.c
+++ b/util.c
@@ -10,11 +10,13 @@
*********************************************************************/
#include "util.h"
+#include "bftw.h"
#include <errno.h>
#include <fcntl.h>
#include <regex.h>
#include <stdarg.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
@@ -117,3 +119,86 @@ char *xregerror(int err, const regex_t *regex) {
}
return str;
}
+
+int xlocaltime(const time_t *timep, struct tm *result) {
+ // Should be called before localtime_r() according to POSIX.1-2004
+ tzset();
+
+ if (localtime_r(timep, result)) {
+ return 0;
+ } else {
+ return -1;
+ }
+}
+
+void format_mode(mode_t mode, char str[11]) {
+ strcpy(str, "----------");
+
+ switch (bftw_mode_to_typeflag(mode)) {
+ 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_FIFO:
+ str[0] = 'p';
+ break;
+ case BFTW_LNK:
+ str[0] = 'l';
+ break;
+ case BFTW_SOCK:
+ str[0] = 's';
+ break;
+ default:
+ break;
+ }
+
+ if (mode & 00400) {
+ str[1] = 'r';
+ }
+ if (mode & 00200) {
+ str[2] = 'w';
+ }
+ if ((mode & 04100) == 04000) {
+ str[3] = 'S';
+ } else if (mode & 04000) {
+ str[3] = 's';
+ } else if (mode & 00100) {
+ str[3] = 'x';
+ }
+
+ if (mode & 00040) {
+ str[4] = 'r';
+ }
+ if (mode & 00020) {
+ str[5] = 'w';
+ }
+ if ((mode & 02010) == 02000) {
+ str[6] = 'S';
+ } else if (mode & 02000) {
+ str[6] = 's';
+ } else if (mode & 00010) {
+ str[6] = 'x';
+ }
+
+ if (mode & 00004) {
+ str[7] = 'r';
+ }
+ if (mode & 00002) {
+ str[8] = 'w';
+ }
+ if ((mode & 01001) == 01000) {
+ str[9] = 'T';
+ } else if (mode & 01000) {
+ str[9] = 't';
+ } else if (mode & 00001) {
+ str[9] = 'x';
+ }
+}