int main(int argc, char **argv) { int c, opt; extern char *optarg; struct stat statbuf; char passwd_path[PATH_MAX]; char group_path[PATH_MAX]; FILE *passwd_file = NULL; FILE *group_file = NULL; FILE *devtable = NULL; DIR *dir = NULL; umask (0); if (argc==1) { fputs( helptext , stderr ); exit(1); } while ((opt = getopt_long(argc, argv, "D:d:r:htv", long_options, &c)) >= 0) { switch (opt) { case 'D': devtable = xfopen(optarg, "r"); if (fstat(fileno(devtable), &statbuf) < 0) perror_msg_and_die(optarg); if (statbuf.st_size < 10) error_msg_and_die("%s: not a proper device table file", optarg); break; case 'h': puts(helptext); exit(0); case 'r': case 'd': /* for compatibility with mkfs.jffs, genext2fs, etc... */ if (rootdir != default_rootdir) { error_msg_and_die("root directory specified more than once"); } if ((dir = opendir(optarg)) == NULL) { perror_msg_and_die(optarg); } else { closedir(dir); } /* If "/" is specified, use "" because rootdir is always prepended to a * string that starts with "/" */ if (0 == strcmp(optarg, "/")) rootdir = xstrdup(""); else rootdir = xstrdup(optarg); break; case 't': trace = 1; break; case 'v': printf("%s: %s\n", app_name, VERSION); exit(0); default: fputs(helptext,stderr); exit(1); } } if (argv[optind] != NULL) { fputs(helptext,stderr); exit(1); } // Get name-id mapping sprintf(passwd_path, "%s/etc/passwd", rootdir); sprintf(group_path, "%s/etc/group", rootdir); if ((passwd_file = fopen(passwd_path, "r")) != NULL) { get_list_from_file(passwd_file, &usr_list); fclose(passwd_file); } if ((group_file = fopen(group_path, "r")) != NULL) { get_list_from_file(group_file, &grp_list); fclose(group_file); } // Parse devtable if(devtable) { parse_devtable(devtable); fclose(devtable); } // Free list free_list(usr_list); free_list(grp_list); return 0; }
int main(int argc, char **argv) { int c, opt; extern char *optarg; struct stat statbuf; char passwd_path[PATH_MAX]; char group_path[PATH_MAX]; FILE *passwd_file = NULL; FILE *group_file = NULL; FILE *devtable = NULL; umask (0); while ((opt = getopt_long(argc, argv, "D:d:r:qhv", long_options, &c)) >= 0) { switch (opt) { case 'D': devtable = xfopen(optarg, "r"); if (fstat(fileno(devtable), &statbuf) < 0) perror_msg_and_die(optarg); if (statbuf.st_size < 10) error_msg_and_die("%s: not a proper device table file", optarg); break; case 'h': fprintf(stderr, helptext); exit(1); case 'r': case 'd': /* for compatibility with mkfs.jffs, genext2fs, etc... */ if (rootdir != default_rootdir) { error_msg_and_die("root directory specified more than once"); } rootdir = xstrdup(optarg); break; case 'v': fprintf(stderr, "makedevs revision %.*s\n", (int) strlen(revtext) - 13, revtext + 11); exit(1); } } // Get name-id mapping sprintf(passwd_path, "%s/etc/passwd", rootdir); sprintf(group_path, "%s/etc/group", rootdir); if ((passwd_file = fopen(passwd_path, "r")) != NULL) { get_list_from_file(passwd_file, &usr_list); fclose(passwd_file); } if ((group_file = fopen(group_path, "r")) != NULL) { get_list_from_file(group_file, &grp_list); fclose(group_file); } // Parse devtable if(devtable) { parse_devtable(devtable); fclose(devtable); } // Free list free_list(usr_list); free_list(grp_list); return 0; }