summaryrefslogtreecommitdiff
path: root/not.c
diff options
context:
space:
mode:
Diffstat (limited to 'not.c')
-rw-r--r--not.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/not.c b/not.c
new file mode 100644
index 0000000..5d1170f
--- /dev/null
+++ b/not.c
@@ -0,0 +1,48 @@
+#define _POSIX_C_SOURCE 2
+#include <dirent.h>
+#include <fnmatch.h>
+#include <locale.h>
+#include <stdio.h>
+#include <unistd.h>
+
+static int matches(char *fn, int argc, char *argv[])
+{
+ for (int i = 0; i < argc; i++) {
+ if (fnmatch(argv[i], fn, 0) == 0) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ setlocale(LC_ALL, "");
+ int c;
+ while ((c = getopt(argc, argv, "")) != -1) {
+ switch (c) {
+ default:
+ return 1;
+ }
+ }
+
+ if (argc <= optind) {
+ fprintf(stderr, "not: missing operands\n");
+ return 1;
+ }
+
+ DIR *d = opendir(".");
+ if (d == NULL) {
+ perror("not");
+ return 1;
+ }
+
+ struct dirent *de;
+ while ((de = readdir(d)) != NULL) {
+ if (!matches(de->d_name, argc - optind, argv + optind)) {
+ printf("%s\n", de->d_name);
+ }
+ }
+
+ return 0;
+}