diff options
author | Phillip Lougher <phillip@squashfs.org.uk> | 2014-09-08 02:11:45 +0100 |
---|---|---|
committer | Mohamad Ayyash <mkayyash@google.com> | 2015-02-23 12:36:46 -0800 |
commit | 1d5e58dfdef868f3f341d206001005ffa6bd0ddc (patch) | |
tree | 4c1b234fff734f0badbed881da7975d5d7ff4dcd | |
parent | fe8ec3abcdfebbfe922ca1e47c2e70c45cc981ae (diff) | |
download | squashfs-tools-1d5e58dfdef868f3f341d206001005ffa6bd0ddc.tar.gz |
actions: refactor parse_octal_mode_args(), to use it with the perm test function
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
-rw-r--r-- | squashfs-tools/action.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/squashfs-tools/action.c b/squashfs-tools/action.c index 4265d52..8d596ac 100644 --- a/squashfs-tools/action.c +++ b/squashfs-tools/action.c @@ -1184,29 +1184,36 @@ static void guid_action(struct action *action, struct dir_ent *dir_ent) /* * Mode specific action code */ -static int parse_octal_mode_args(unsigned int mode, int bytes, int args, - char **argv, void **data) +static int parse_octal_mode_args(int args, char **argv, void **data) { + int n, bytes; + unsigned int mode; struct mode_data *mode_data; + /* octal mode number? */ + n = sscanf(argv[0], "%o%n", &mode, &bytes); + if (n == 0) + return -1; /* not an octal number arg */ + + /* check there's no trailing junk */ if (argv[0][bytes] != '\0') { SYNTAX_ERROR("Unexpected trailing bytes after octal " "mode number\n"); - return 0; + return 0; /* bad octal number arg */ } /* check there's only one argument */ if (args > 1) { SYNTAX_ERROR("Octal mode number is first argument, " "expected one argument, got %d\n", args); - return 0; + return 0; /* bad octal number arg */ } /* check mode is within range */ if (mode > 07777) { SYNTAX_ERROR("Octal mode %o is out of range\n", mode); - return 0; + return 0; /* bad octal number arg */ } mode_data = malloc(sizeof(struct mode_data)); @@ -1377,20 +1384,18 @@ static int parse_sym_mode_args(struct action_entry *action, int args, static int parse_mode_args(struct action_entry *action, int args, char **argv, void **data) { - int n, bytes; - unsigned int mode; + int res; if (args == 0) { SYNTAX_ERROR("Mode action expects one or more arguments\n"); return 0; } - /* octal mode number? */ - n = sscanf(argv[0], "%o%n", &mode, &bytes); - - if(n >= 1) - return parse_octal_mode_args(mode, bytes, args, argv, data); - else + res = parse_octal_mode_args(args, argv, data); + if(res >= 0) + /* Got an octal mode argument */ + return res; + else /* not an octal mode argument */ return parse_sym_mode_args(action, args, argv, data); } |