aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-04-26 23:22:40 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-04-26 23:22:40 +0000
commit28e67966f3fc0728fb2f923265a8b2275f410655 (patch)
tree0c522b97ed681180f68d028094bd02b89b292b49 /shell
parent572930027d5d86a18ebd68d5f4273150a2f302e1 (diff)
downloadbusybox-28e67966f3fc0728fb2f923265a8b2275f410655.tar.gz
hush: make getopt32 usable in builtins. use it in unset.
more uses are expected in the future. function old new delta getopt32 1356 1393 +37 builtin_export 256 266 +10 builtin_unset 418 380 -38
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c42
-rw-r--r--shell/hush_test/hush-vars/unset.right5
2 files changed, 18 insertions, 29 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 292b8b2e3..d0819f691 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -6451,7 +6451,11 @@ static int builtin_export(char **argv)
}
#if ENABLE_HUSH_EXPORT_N
- opt_unexport = getopt32(argv, "+n"); /* "+": stop at 1st non-option */
+ /* "!": do not abort on errors */
+ /* "+": stop at 1st non-option */
+ opt_unexport = getopt32(argv, "!+n");
+ if (opt_unexport == (unsigned)-1)
+ return EXIT_FAILURE;
argv += optind;
#else
opt_unexport = 0;
@@ -6918,36 +6922,22 @@ static int builtin_umask(char **argv)
static int builtin_unset(char **argv)
{
int ret;
- char var;
- char *arg;
-
- if (!*++argv)
- return EXIT_SUCCESS;
+ unsigned opts;
- var = 0;
- while ((arg = *argv) != NULL && arg[0] == '-') {
- arg++;
- do {
- switch (*arg) {
- case 'v':
- case 'f':
- if (var == 0 || var == *arg) {
- var = *arg;
- break;
- }
- /* else: unset -vf, which is illegal.
- * fall through */
- default:
- bb_error_msg("unset: %s: invalid option", *argv);
- return EXIT_FAILURE;
- }
- } while (*++arg);
- argv++;
+ /* "!": do not abort on errors */
+ /* "+": stop at 1st non-option */
+ opts = getopt32(argv, "!+vf");
+ if (opts == (unsigned)-1)
+ return EXIT_FAILURE;
+ if (opts == 3) {
+ bb_error_msg("unset: -v and -f are exclusive");
+ return EXIT_FAILURE;
}
+ argv += optind;
ret = EXIT_SUCCESS;
while (*argv) {
- if (var != 'f') {
+ if (!(opts & 2)) { /* not -f */
if (unset_local_var(*argv)) {
/* unset <nonexistent_var> doesn't fail.
* Error is when one tries to unset RO var.
diff --git a/shell/hush_test/hush-vars/unset.right b/shell/hush_test/hush-vars/unset.right
index 8dea7c40d..1fbe76a73 100644
--- a/shell/hush_test/hush-vars/unset.right
+++ b/shell/hush_test/hush-vars/unset.right
@@ -1,6 +1,5 @@
-hush: unset: -: invalid option
-1
-hush: unset: -m: invalid option
+0
+unset: invalid option -- m
1
0
___