Просмотр исходного кода

[cmdline] Simplify "isset" command

There is no plausible scenario I can think of in which "isset" would
be used with more than one argument.  Simplify the code by specifying
that exactly one argument is required.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 лет назад
Родитель
Сommit
7aee315f61
1 измененных файлов: 3 добавлений и 10 удалений
  1. 3
    10
      src/core/exec.c

+ 3
- 10
src/core/exec.c Просмотреть файл

@@ -464,8 +464,7 @@ static struct option_descriptor isset_opts[] = {};
464 464
 
465 465
 /** "isset" command descriptor */
466 466
 static struct command_descriptor isset_cmd =
467
-	COMMAND_DESC ( struct isset_options, isset_opts, 0, MAX_ARGUMENTS,
468
-		       "[...]" );
467
+	COMMAND_DESC ( struct isset_options, isset_opts, 1, 1, "<value>" );
469 468
 
470 469
 /**
471 470
  * "isset" command
@@ -476,20 +475,14 @@ static struct command_descriptor isset_cmd =
476 475
  */
477 476
 static int isset_exec ( int argc, char **argv ) {
478 477
 	struct isset_options opts;
479
-	int i;
480 478
 	int rc;
481 479
 
482 480
 	/* Parse options */
483 481
 	if ( ( rc = parse_options ( argc, argv, &isset_cmd, &opts ) ) != 0 )
484 482
 		return rc;
485 483
 
486
-	/* Return success if any argument is non-empty */
487
-	for ( i = optind ; i < argc ; i++ ) {
488
-		if ( argv[i][0] != '\0' )
489
-			return 0;
490
-	}
491
-
492
-	return -ENOENT;
484
+	/* Return success iff argument is non-empty */
485
+	return ( argv[optind][0] ? 0 : -ENOENT );
493 486
 }
494 487
 
495 488
 /** "isset" command */

Загрузка…
Отмена
Сохранить