static int FAST_FUNC chattr_dir_proc(const char *dir_name, struct dirent *de, void *gp) { char *path = concat_subpath_file(dir_name, de->d_name); /* path is NULL if de->d_name is "." or "..", else... */ if (path) { change_attributes(path, gp); free(path); } return 0; }
static int chattr_dir_proc (const char * dir_name, struct dirent * de, void * unused_private) { if (strcmp (de->d_name, ".") && strcmp (de->d_name, "..")) { char *path; path = malloc(strlen (dir_name) + 1 + strlen (de->d_name) + 1); if (!path) fatal_error(_("Couldn't allocate path variable " "in chattr_dir_proc"), 1); sprintf (path, "%s/%s", dir_name, de->d_name); change_attributes (path); free(path); } return 0; }
int chattr_main(int argc UNUSED_PARAM, char **argv) { struct globals g; char *arg; memset(&g, 0, sizeof(g)); /* parse the args */ while ((arg = *++argv)) { /* take care of -R and -v <version> */ if (arg[0] == '-' && (arg[1] == 'R' || arg[1] == 'v') && !arg[2] ) { if (arg[1] == 'R') { g.recursive = 1; continue; } /* arg[1] == 'v' */ if (!*++argv) bb_show_usage(); g.version = xatoul(*argv); g.flags |= OPT_SET_VER; continue; } if (!decode_arg(arg, &g)) break; } /* run sanity checks on all the arguments given us */ if (!*argv) bb_show_usage(); if ((g.flags & OPT_SET) && (g.flags & (OPT_ADD|OPT_REM))) bb_error_msg_and_die("= is incompatible with - and +"); if (g.rf & g.af) bb_error_msg_and_die("can't set and unset a flag"); if (!g.flags) bb_error_msg_and_die("must use '-v', =, - or +"); /* now run chattr on all the files passed to us */ do change_attributes(*argv, &g); while (*++argv); return EXIT_SUCCESS; }
int main (int argc, char ** argv) { int i, j; int end_arg = 0; #ifdef ENABLE_NLS setlocale(LC_MESSAGES, ""); bindtextdomain(NLS_CAT_NAME, LOCALEDIR); textdomain(NLS_CAT_NAME); #endif if (argc && *argv) program_name = *argv; i = 1; while (i < argc && !end_arg) { if (decode_arg (&i, argc, argv) == EOF) end_arg = 1; else i++; } if (i >= argc) usage (); if (set && (add || rem)) { fprintf (stderr, _("= is incompatible with - and +\n")); exit (1); } if ((rf & af) != 0) { fprintf (stderr, "Can't both set and unset same flag.\n"); exit (1); } if (!(add || rem || set || set_version)) { fprintf (stderr, _("Must use '-v', =, - or +\n")); exit (1); } if (verbose) fprintf (stderr, "chattr %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE); for (j = i; j < argc; j++) change_attributes (argv[j]); exit(0); }
int ad_set(int argc, char **argv, AFPObj *obj) { int c, firstarg; afpvol_t vol; struct stat st; int adflags = 0; struct adouble ad; while ((c = getopt(argc, argv, ":l:t:c:f:a:")) != -1) { switch(c) { case 'l': new_label = strdup(optarg); break; case 't': new_type = strdup(optarg); break; case 'c': new_creator = strdup(optarg); break; case 'f': new_flags = strdup(optarg); break; case 'a': new_attributes = strdup(optarg); break; case ':': case '?': usage_set(); return -1; break; } } if (argc <= optind) exit(1); cnid_init(); openvol(obj, argv[optind], &vol); if (vol.vol->v_path == NULL) exit(1); if (stat(argv[optind], &st) != 0) { perror("stat"); exit(1); } if (S_ISDIR(st.st_mode)) adflags = ADFLAGS_DIR; ad_init(&ad, vol.vol); if (ad_open(&ad, argv[optind], adflags | ADFLAGS_HF | ADFLAGS_CREATE | ADFLAGS_RDWR, 0666) < 0) goto exit; if (new_label) change_label(argv[optind], &vol, &st, &ad, new_label); if (new_type) change_type(argv[optind], &vol, &st, &ad, new_type); if (new_creator) change_creator(argv[optind], &vol, &st, &ad, new_creator); if (new_flags) change_flags(argv[optind], &vol, &st, &ad, new_flags); if (new_attributes) change_attributes(argv[optind], &vol, &st, &ad, new_attributes); ad_flush(&ad); ad_close(&ad, ADFLAGS_HF); exit: closevol(&vol); return 0; }