From a71f0ce8c5f80757096f6e4d0ebca27ccbe14da9 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Wed, 6 Feb 2008 18:59:15 +0200 Subject: ubi-tools: improve printing macros Signed-off-by: Artem Bityutskiy --- ubi-utils/src/ubidetach.c | 55 ++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 37 deletions(-) (limited to 'ubi-utils/src/ubidetach.c') diff --git a/ubi-utils/src/ubidetach.c b/ubi-utils/src/ubidetach.c index fe53997..cd48368 100644 --- a/ubi-utils/src/ubidetach.c +++ b/ubi-utils/src/ubidetach.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include "common.h" @@ -84,19 +83,15 @@ static int parse_opt(int argc, char * const argv[]) switch (key) { case 'd': args.devn = strtoul(optarg, &endp, 0); - if (*endp != '\0' || endp == optarg || args.devn < 0) { - errmsg("bad UBI device number: \"%s\"", optarg); - return -1; - } + if (*endp != '\0' || endp == optarg || args.devn < 0) + return errmsg("bad UBI device number: \"%s\"", optarg); break; case 'm': args.mtdn = strtoul(optarg, &endp, 0); - if (*endp != '\0' || endp == optarg || args.mtdn < 0) { - errmsg("bad MTD device number: \"%s\"", optarg); - return -1; - } + if (*endp != '\0' || endp == optarg || args.mtdn < 0) + return errmsg("bad MTD device number: \"%s\"", optarg); break; @@ -111,8 +106,7 @@ static int parse_opt(int argc, char * const argv[]) exit(EXIT_SUCCESS); case ':': - errmsg("parameter is missing"); - return -1; + return errmsg("parameter is missing"); default: fprintf(stderr, "Use -h for help\n"); @@ -120,23 +114,16 @@ static int parse_opt(int argc, char * const argv[]) } } - if (optind == argc) { - errmsg("UBI control device name was not specified (use -h for help)"); - return -1; - } else if (optind != argc - 1) { - errmsg("more then one UBI control device specified (use -h for help)"); - return -1; - } + if (optind == argc) + return errmsg("UBI control device name was not specified (use -h for help)"); + else if (optind != argc - 1) + return errmsg("more then one UBI control device specified (use -h for help)"); - if (args.mtdn == -1 && args.devn == -1) { - errmsg("neither MTD nor UBI devices were specified (use -h for help)"); - return -1; - } + if (args.mtdn == -1 && args.devn == -1) + return errmsg("neither MTD nor UBI devices were specified (use -h for help)"); - if (args.mtdn != -1 && args.devn != -1) { - errmsg("specify either MTD or UBI device (use -h for help)"); - return -1; - } + if (args.mtdn != -1 && args.devn != -1) + return errmsg("specify either MTD or UBI device (use -h for help)"); args.node = argv[optind]; return 0; @@ -153,19 +140,15 @@ int main(int argc, char * const argv[]) return -1; libubi = libubi_open(); - if (libubi == NULL) { - errmsg("cannot open libubi"); - perror("libubi_open"); - return -1; - } + if (libubi == NULL) + return sys_errmsg("cannot open libubi"); /* * Make sure the kernel is fresh enough and this feature is supported. */ err = ubi_get_info(libubi, &ubi_info); if (err) { - errmsg("cannot get UBI information"); - perror("ubi_get_info"); + sys_errmsg("cannot get UBI information"); goto out_libubi; } @@ -177,15 +160,13 @@ int main(int argc, char * const argv[]) if (args.devn != -1) { err = ubi_remove_dev(libubi, args.node, args.devn); if (err) { - errmsg("cannot remove ubi%d", args.devn); - perror("ubi_remove_dev"); + sys_errmsg("cannot remove ubi%d", args.devn); goto out_libubi; } } else { err = ubi_detach_mtd(libubi, args.node, args.mtdn); if (err) { - errmsg("cannot detach mtd%d", args.mtdn); - perror("ubi_detach_mtd"); + sys_errmsg("cannot detach mtd%d", args.mtdn); goto out_libubi; } } -- cgit v1.2.3