aboutsummaryrefslogtreecommitdiff
path: root/util-linux/fdisk.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-02-10 19:44:20 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-02-10 19:44:20 +0000
commit04e11c9209f88b878d6bef0b56a4d8345c89c217 (patch)
treedc67a11b65d3d7e4a03b955dd2f5d1b3c7721b2f /util-linux/fdisk.c
parent9304d6ea92f7fc1529669800b75456d549cf1bfc (diff)
downloadbusybox-04e11c9209f88b878d6bef0b56a4d8345c89c217.tar.gz
getpot: add support for "a+" specifier for nonnegative int parameters.
By Vladimir Dronnikov <dronnikov at gmail.com>. fdisk and top are converted as an example. function old new delta getopt32 1340 1370 +30 top_main 1137 1120 -17 fdisk_main 3033 2949 -84 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 30/-101) Total: -71 bytes
Diffstat (limited to 'util-linux/fdisk.c')
-rw-r--r--util-linux/fdisk.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index cd053b876..c98a74fc0 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -2754,7 +2754,6 @@ unknown_command(int c)
int fdisk_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int fdisk_main(int argc, char **argv)
{
- char *str_b, *str_C, *str_H, *str_S;
unsigned opt;
/*
* fdisk -v
@@ -2776,8 +2775,9 @@ int fdisk_main(int argc, char **argv)
INIT_G();
+ opt_complementary = "b+:C+:H+:S+"; /* numeric params */
opt = getopt32(argv, "b:C:H:lS:u" USE_FEATURE_FDISK_BLKSIZE("s"),
- &str_b, &str_C, &str_H, &str_S);
+ &sector_size, &user_cylinders, &user_heads, &user_sectors);
argc -= optind;
argv += optind;
if (opt & OPT_b) { // -b
@@ -2785,27 +2785,18 @@ int fdisk_main(int argc, char **argv)
so cannot be combined with multiple disks,
and the same goes for the C/H/S options.
*/
- sector_size = xatoi_u(str_b);
- if (sector_size != 512 && sector_size != 1024 &&
- sector_size != 2048)
+ if (sector_size != 512 && sector_size != 1024
+ && sector_size != 2048)
bb_show_usage();
sector_offset = 2;
user_set_sector_size = 1;
}
- if (opt & OPT_C) user_cylinders = xatoi_u(str_C); // -C
- if (opt & OPT_H) { // -H
- user_heads = xatoi_u(str_H);
- if (user_heads <= 0 || user_heads >= 256)
- user_heads = 0;
- }
- //if (opt & OPT_l) // -l
- if (opt & OPT_S) { // -S
- user_sectors = xatoi_u(str_S);
- if (user_sectors <= 0 || user_sectors >= 64)
- user_sectors = 0;
- }
- if (opt & OPT_u) display_in_cyl_units = 0; // -u
- //if (opt & OPT_s) // -s
+ if (user_heads <= 0 || user_heads >= 256)
+ user_heads = 0;
+ if (user_sectors <= 0 || user_sectors >= 64)
+ user_sectors = 0;
+ if (opt & OPT_u)
+ display_in_cyl_units = 0; // -u
if (user_set_sector_size && argc != 1)
printf("Warning: the -b (set sector size) option should"