/* * Check for directory offsets that are not monotonically increasing. */ #include #include #include #include #include #include int main(int argc, char **argv) { DIR *dirp; struct dirent *dent; off_t oldoff; int c; bool verbose; verbose = false; while ((c = getopt(argc, argv, "v")) != -1) switch (c) { case 'v': verbose = true; break; default: errx(1, "Usage: rdir [-v] "); } argc -= optind; argv += optind; if (argc != 1) errx(1, "Usage: rdir [-v] "); dirp = opendir(argv[0]); if (dirp == NULL) errx(1, "Cannot open %s", argv[1]); oldoff = 0; while ((dent = readdir(dirp)) != NULL) { if (verbose) printf("%jd\n", (intmax_t)dent->d_off); if (dent->d_off <= oldoff) { printf("Not monotonically increasing\n"); exit(0); } oldoff = dent->d_off; } }