diff options
author | Karel Zak <kzak@redhat.com> | 2010-08-04 11:52:41 +0200 |
---|---|---|
committer | maximilian attems <max@stro.at> | 2011-07-05 23:25:30 +0200 |
commit | 6cb28af95367ca97f5ddc1cdc1b22bd3a6f9ef5f (patch) | |
tree | 6cd489deacebfe7d14ca0f8d04fccefb689ba3b1 | |
parent | 8c56fb3065dc8ef0fdcf0443e191b53e96c80f2d (diff) | |
download | klibc-6cb28af95367ca97f5ddc1cdc1b22bd3a6f9ef5f.tar.gz |
[klibc] losetup: use stdout and return 0 for -h
ported to klibc losetup version from util-linux
108591d2b7860ca0b8d27d114bed1e504a31fa72,
also add -h option. -maks
Reported-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: maximilian attems <max@stro.at>
-rw-r--r-- | usr/utils/losetup.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/usr/utils/losetup.c b/usr/utils/losetup.c index 59030d7bc75ce..9deacd43120e8 100644 --- a/usr/utils/losetup.c +++ b/usr/utils/losetup.c @@ -353,14 +353,16 @@ int del_loop (const char *device) int verbose = 0; char *progname; -static void usage(void) { - fprintf(stderr, "usage:\n\ +static void usage(FILE *f) +{ + fprintf(f, "usage:\n\ %s loop_device # give info\n\ %s -d loop_device # delete\n\ %s -f # find unused\n\ + %s -h # this help\n\ %s [-e encryption] [-o offset] {-f|loop_device} file # setup\n", - progname, progname, progname, progname); - exit(1); + progname, progname, progname, progname, progname); + exit(f == stderr ? EXIT_FAILURE : EXIT_SUCCESS); } char * xstrdup (const char *s) { @@ -407,7 +409,7 @@ int main(int argc, char **argv) if ((p = strrchr(progname, '/')) != NULL) progname = p+1; - while ((c = getopt(argc, argv, "de:E:fo:p:v")) != -1) { + while ((c = getopt(argc, argv, "de:E:fho:p:v")) != -1) { switch (c) { case 'd': delete = 1; @@ -419,6 +421,9 @@ int main(int argc, char **argv) case 'f': find = 1; break; + case 'h': + usage(stdout); + break; case 'o': offset = optarg; break; @@ -429,21 +434,21 @@ int main(int argc, char **argv) verbose = 1; break; default: - usage(); + usage(stderr); } } if (argc == 1) { - usage(); + usage(stderr); } else if (delete) { if (argc != optind+1 || encryption || offset || find) - usage(); + usage(stderr); } else if (find) { if (argc < optind || argc > optind+1) - usage(); + usage(stderr); } else { if (argc < optind+1 || argc > optind+2) - usage(); + usage(stderr); } if (find) { @@ -471,9 +476,9 @@ int main(int argc, char **argv) res = show_loop(device); else { if (offset && sscanf(offset, "%llu", &off) != 1) - usage(); + usage(stderr); if (passfd && sscanf(passfd, "%d", &pfd) != 1) - usage(); + usage(stderr); res = set_loop(device, file, off, encryption, pfd, &ro); } return res; |