int main(int argc, char **argv) { DIR *rep; struct dirent *ent; struct file sFile; char filename[4096]; FILE *fout; if (argc != 2) { fprintf(stderr, "Usage : %s <4DSD_directory>\n", argv[0]); exit(EXIT_FAILURE); } rep = opendir(argv[1]); if (rep == NULL) { perror("opendir()"); exit(EXIT_FAILURE); } fout = fopen("stats.md", "w"); if (!fout) { perror("fopen()"); exit(EXIT_FAILURE); } while ((ent = readdir(rep)) != NULL) { if (ent->d_type == 8) { if (strlen(argv[1]) + strlen(ent->d_name) + 1 + 1 < 4096) { strcpy(filename, argv[1]); if (filename[strlen(filename) - 1] != '/') strcat(filename, "/"); strcat(filename, ent->d_name); if (open_and_map(filename, &sFile) == 0) { clean_file(&sFile); fprintf(stderr, "[-] open_and_map failed : %s\n", filename); } else { print_info_file(fout, &sFile); clean_file(&sFile); } } } } closedir(rep); fclose(fout); return 0; }
int main (int argc, char *argv[]) { char c; int ret; char *file_name; FILE *in; recutl_init ("recinf"); while ((ret = getopt_long (argc, argv, "Sdnt:", GNU_longOptions, NULL)) != -1) { c = ret; switch (c) { COMMON_ARGS_CASES case PRINT_SEXPS_ARG: case 'S': { recinf_write_mode = REC_WRITER_SEXP; break; } case DESCRIPTOR_ARG: case 'd': { recinf_descriptor = true; break; } case NAMES_ARG: case 'n': { recinf_names_only = true; break; } case TYPE_ARG: case 't': { recinf_type = xstrdup (optarg); break; } default: { exit (EXIT_FAILURE); } } } /* Process the input files, if any. Otherwise use the standard input to read the rec data. */ if (optind < argc) { while (optind < argc) { file_name = argv[optind++]; if (!(in = fopen (file_name, "r"))) { printf(_("error: cannot read file %s\n"), file_name); exit (EXIT_FAILURE); } else { if (!print_info_file (in, file_name)) { /* Parse error */ exit (EXIT_FAILURE); } fclose (in); } } } else { if (!print_info_file (stdin, "stdin")) { /* Parse error */ exit (EXIT_FAILURE); } } return EXIT_SUCCESS; }