diff options
author | Elliott Hughes <enh@google.com> | 2014-12-11 20:50:51 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-12-11 20:50:52 +0000 |
commit | 81784ae8ddae139646441eb1dcaa5e1d89ab29de (patch) | |
tree | 330dac7aaed90a0ea88eb60ea4983c7115a46900 | |
parent | 3570072c362fc379ac83bcae6d9ff43db06ffcfb (diff) | |
parent | 98c80a0f4004391bf18eaa2d193ebf9d3eb72a79 (diff) | |
download | system_core-81784ae8ddae139646441eb1dcaa5e1d89ab29de.zip system_core-81784ae8ddae139646441eb1dcaa5e1d89ab29de.tar.gz system_core-81784ae8ddae139646441eb1dcaa5e1d89ab29de.tar.bz2 |
Merge "Lose chmod to toybox."
-rw-r--r-- | toolbox/Android.mk | 1 | ||||
-rw-r--r-- | toolbox/chmod.c | 101 |
2 files changed, 0 insertions, 102 deletions
diff --git a/toolbox/Android.mk b/toolbox/Android.mk index 249f91e..5a05e40 100644 --- a/toolbox/Android.mk +++ b/toolbox/Android.mk @@ -112,7 +112,6 @@ BSD_TOOLS := \ OUR_TOOLS := \ chcon \ - chmod \ cmp \ date \ df \ diff --git a/toolbox/chmod.c b/toolbox/chmod.c deleted file mode 100644 index 2a524e9..0000000 --- a/toolbox/chmod.c +++ /dev/null @@ -1,101 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <dirent.h> -#include <errno.h> -#include <sys/limits.h> -#include <sys/stat.h> - -#include <unistd.h> -#include <time.h> - -void recurse_chmod(char* path, int mode) -{ - struct dirent *dp; - DIR *dir = opendir(path); - if (dir == NULL) { - // not a directory, carry on - return; - } - char *subpath = malloc(sizeof(char)*PATH_MAX); - int pathlen = strlen(path); - - while ((dp = readdir(dir)) != NULL) { - if (strcmp(dp->d_name, ".") == 0 || - strcmp(dp->d_name, "..") == 0) continue; - - if (strlen(dp->d_name) + pathlen + 2/*NUL and slash*/ > PATH_MAX) { - fprintf(stderr, "Invalid path specified: too long\n"); - exit(1); - } - - strcpy(subpath, path); - strcat(subpath, "/"); - strcat(subpath, dp->d_name); - - if (chmod(subpath, mode) < 0) { - fprintf(stderr, "Unable to chmod %s: %s\n", subpath, strerror(errno)); - exit(1); - } - - recurse_chmod(subpath, mode); - } - free(subpath); - closedir(dir); -} - -static int usage() -{ - fprintf(stderr, "Usage: chmod [OPTION] <MODE> <FILE>\n"); - fprintf(stderr, " -R, --recursive change files and directories recursively\n"); - fprintf(stderr, " --help display this help and exit\n"); - - return 10; -} - -int chmod_main(int argc, char **argv) -{ - int i; - - if (argc < 3 || strcmp(argv[1], "--help") == 0) { - return usage(); - } - - int recursive = (strcmp(argv[1], "-R") == 0 || - strcmp(argv[1], "--recursive") == 0) ? 1 : 0; - - if (recursive && argc < 4) { - return usage(); - } - - if (recursive) { - argc--; - argv++; - } - - int mode = 0; - const char* s = argv[1]; - while (*s) { - if (*s >= '0' && *s <= '7') { - mode = (mode<<3) | (*s-'0'); - } - else { - fprintf(stderr, "Bad mode\n"); - return 10; - } - s++; - } - - for (i = 2; i < argc; i++) { - if (chmod(argv[i], mode) < 0) { - fprintf(stderr, "Unable to chmod %s: %s\n", argv[i], strerror(errno)); - return 10; - } - if (recursive) { - recurse_chmod(argv[i], mode); - } - } - return 0; -} - |