From b48327d357e0818d1a6ae2a064cfa7d1567e1242 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Sun, 5 Dec 2021 15:17:44 -0800 Subject: feat(huge): huge refactor (in progress). Commented out libc includes to uncover all explicit dependencies. A large fraction has now been ported over (no testing). I did not port over the command line tools, such as the rc shell. These will be done independently - as of now I just want the library to stand independent. Compilation currently fails due to the lack of math functions. --- src/cmd/filter/filter.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/cmd/filter/filter.c') diff --git a/src/cmd/filter/filter.c b/src/cmd/filter/filter.c index abc9a88..82fb364 100644 --- a/src/cmd/filter/filter.c +++ b/src/cmd/filter/filter.c @@ -2,42 +2,42 @@ #include #include +#include #include #include #define FLAG(x) (flag[(x)-'a']) -static void filter(const char *, const char *); +static void filter(char *, char *); static void usage(void); static int match = 0; static int flag[26]; static struct stat old, new; -static -void -filter(const char *path, const char *name) +static void +filter(char *path, char *name) { struct stat st, ln; if ((!stat(path, &st) && (FLAG('a') || name[0] != '.') /* hidden files */ - && (!FLAG('b') || S_ISBLK(st.st_mode)) /* block special */ - && (!FLAG('c') || S_ISCHR(st.st_mode)) /* character special */ - && (!FLAG('d') || S_ISDIR(st.st_mode)) /* directory */ - && (!FLAG('e') || access(path, F_OK) == 0) /* exists */ - && (!FLAG('f') || S_ISREG(st.st_mode)) /* regular file */ + && (!FLAG('b') || sys·InfoIsBlock(st.st_mode)) /* block special */ + && (!FLAG('c') || sys·InfoIsChar(st.st_mode)) /* character special */ + && (!FLAG('d') || sys·InfoIsDir(st.st_mode)) /* directory */ + && (!FLAG('e') || !sys·access(path,sys·FileExists)) /* exists */ + && (!FLAG('f') || sys·InfoIsFile(st.st_mode)) /* regular file */ && (!FLAG('g') || st.st_mode & S_ISGID) /* set-group-id flag */ && (!FLAG('h') || (!lstat(path, &ln) && S_ISLNK(ln.st_mode))) /* symbolic link */ && (!FLAG('n') || st.st_mtime > new.st_mtime) /* newer than file */ && (!FLAG('o') || st.st_mtime < old.st_mtime) /* older than file */ - && (!FLAG('p') || S_ISFIFO(st.st_mode)) /* named pipe */ - && (!FLAG('r') || access(path, R_OK) == 0) /* readable */ + && (!FLAG('p') || sys·InfoIsFifo(st.st_mode)) /* named pipe */ + && (!FLAG('r') || !sys·access(path, sys·FileCanRead)) /* readable */ && (!FLAG('s') || st.st_size > 0) /* not empty */ && (!FLAG('u') || st.st_mode & S_ISUID) /* set-user-id flag */ - && (!FLAG('w') || access(path, W_OK) == 0) /* writable */ - && (!FLAG('x') || access(path, X_OK) == 0)) != FLAG('v')) { /* executable */ + && (!FLAG('w') || !sys·access(path, sys·FileCanWrite)) /* writable */ + && (!FLAG('x') || !sys·access(path, sys·FileCanExec))) != FLAG('v')) { /* executable */ if (FLAG('q')) - exit(0); + rt·exit(0); match = 1; puts(name); } @@ -48,7 +48,7 @@ usage(void) { fprintf(stderr, "usage: %s [-abcdefghlpqrsuvwx] " "[-n file] [-o file] [file...]\n", argv0); - exit(2); /* like test(1) return > 1 on error */ + rt·exit(2); /* like test(1) return > 1 on error */ } int @@ -70,7 +70,7 @@ main(int argc, char *argv[]) break; default: /* miscellaneous operators */ - if (strchr("abcdefghlpqrsuvwx", ARGC())) + if(str·rfindc("abcdefghlpqrsuvwx", ARGC())) FLAG(ARGC()) = 1; else usage(); /* unknown flag */ -- cgit v1.2.1