diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-09-22 14:53:41 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-09-22 14:53:41 +0000 |
commit | eaf1194e42116fb2ae22ad4dd6dbb848537bc17e (patch) | |
tree | 786bc190746590e1d6f0c8319bb774152eeb7d07 | |
parent | 6f407629690970ca5e3fb2593cc63aa9ffbf1264 (diff) | |
download | busybox-w32-eaf1194e42116fb2ae22ad4dd6dbb848537bc17e.tar.gz busybox-w32-eaf1194e42116fb2ae22ad4dd6dbb848537bc17e.tar.bz2 busybox-w32-eaf1194e42116fb2ae22ad4dd6dbb848537bc17e.zip |
losetup: getopt_ulflags'ification + small fix for perror_nomsg
git-svn-id: svn://busybox.net/trunk/busybox@16186 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | libbb/verror_msg.c | 4 | ||||
-rw-r--r-- | util-linux/losetup.c | 68 |
2 files changed, 38 insertions, 34 deletions
diff --git a/libbb/verror_msg.c b/libbb/verror_msg.c index 557b3290a..e670d40ba 100644 --- a/libbb/verror_msg.c +++ b/libbb/verror_msg.c | |||
@@ -27,7 +27,9 @@ void bb_verror_msg(const char *s, va_list p, const char* strerr) | |||
27 | if (!strerr) | 27 | if (!strerr) |
28 | fputs(msg_eol, stderr); | 28 | fputs(msg_eol, stderr); |
29 | else | 29 | else |
30 | fprintf(stderr, ": %s%s", strerr, msg_eol); | 30 | fprintf(stderr, "%s%s%s", |
31 | s ? ": " : "", | ||
32 | strerr, msg_eol); | ||
31 | } | 33 | } |
32 | if (ENABLE_FEATURE_SYSLOG && (logmode & LOGMODE_SYSLOG)) { | 34 | if (ENABLE_FEATURE_SYSLOG && (logmode & LOGMODE_SYSLOG)) { |
33 | if (!strerr) | 35 | if (!strerr) |
diff --git a/util-linux/losetup.c b/util-linux/losetup.c index 3c979840f..af0b03a53 100644 --- a/util-linux/losetup.c +++ b/util-linux/losetup.c | |||
@@ -12,39 +12,41 @@ | |||
12 | 12 | ||
13 | #include "busybox.h" | 13 | #include "busybox.h" |
14 | 14 | ||
15 | int losetup_main (int argc, char **argv) | 15 | int losetup_main(int argc, char **argv) |
16 | { | 16 | { |
17 | int offset = 0; | 17 | unsigned long opt; |
18 | 18 | char *opt_o; | |
19 | /* This will need a "while(getopt()!=-1)" loop when we can have more than | 19 | int offset = 0; |
20 | one option, but for now we can't. */ | 20 | |
21 | switch(getopt(argc,argv, "do:")) { | 21 | opt = bb_getopt_ulflags(argc, argv, "do:", &opt_o); |
22 | case 'd': | 22 | argc -= optind; |
23 | /* detach takes exactly one argument */ | 23 | argv += optind; |
24 | if(optind+1!=argc) bb_show_usage(); | 24 | |
25 | if(!del_loop(argv[optind])) return EXIT_SUCCESS; | 25 | if (opt == 0x3) bb_show_usage(); // -d and -o (illegal) |
26 | die_failed: | 26 | |
27 | bb_perror_msg_and_die("%s",argv[optind]); | 27 | if (opt == 0x1) { // -d |
28 | 28 | /* detach takes exactly one argument */ | |
29 | case 'o': | 29 | if (argc != 1) |
30 | offset = bb_xparse_number (optarg, NULL); | 30 | bb_show_usage(); |
31 | /* Fall through to do the losetup */ | 31 | if (!del_loop(argv[0])) |
32 | case -1: | 32 | return EXIT_SUCCESS; |
33 | /* losetup takes two argument:, loop_device and file */ | 33 | bb_perror_nomsg_and_die(); |
34 | if(optind+2==argc) { | 34 | } |
35 | if(set_loop(&argv[optind], argv[optind + 1], offset)>=0) | 35 | |
36 | return EXIT_SUCCESS; | 36 | if (opt == 0x2) // -o |
37 | else goto die_failed; | 37 | offset = bb_xparse_number(opt_o, NULL); |
38 | } | 38 | |
39 | if(optind+1==argc) { | 39 | /* -o or no option */ |
40 | char *s=query_loop(argv[optind]); | 40 | |
41 | if (!s) goto die_failed; | 41 | if (argc == 2) { |
42 | printf("%s: %s\n",argv[optind],s); | 42 | if (set_loop(&argv[0], argv[1], offset) < 0) |
43 | if(ENABLE_FEATURE_CLEAN_UP) free(s); | 43 | bb_perror_nomsg_and_die(); |
44 | } else if (argc == 1) { | ||
45 | char *s = query_loop(argv[0]); | ||
46 | if (!s) bb_perror_nomsg_and_die(); | ||
47 | printf("%s: %s\n", argv[0], s); | ||
48 | if (ENABLE_FEATURE_CLEAN_UP) free(s); | ||
49 | } else | ||
50 | bb_show_usage(); | ||
44 | return EXIT_SUCCESS; | 51 | return EXIT_SUCCESS; |
45 | } | ||
46 | break; | ||
47 | } | ||
48 | bb_show_usage(); | ||
49 | return EXIT_FAILURE; | ||
50 | } | 52 | } |