diff options
Diffstat (limited to 'not.c')
-rw-r--r-- | not.c | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -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; +} |