#define _POSIX_C_SOURCE 2 #include #include #include #include #include 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; }