aboutsummaryrefslogtreecommitdiff
path: root/ubi-utils/src/ubidetach.c
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2008-02-06 18:59:15 +0200
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2008-02-06 18:59:15 +0200
commita71f0ce8c5f80757096f6e4d0ebca27ccbe14da9 (patch)
tree07645e323044fcfb331df157a80a84b624cdab51 /ubi-utils/src/ubidetach.c
parentf3d507be006c46870818c549b8f7dc0b4daccf03 (diff)
ubi-tools: improve printing macros
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'ubi-utils/src/ubidetach.c')
-rw-r--r--ubi-utils/src/ubidetach.c55
1 files changed, 18 insertions, 37 deletions
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 <getopt.h>
#include <stdlib.h>
#include <string.h>
-#include <errno.h>
#include <libubi.h>
#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;
}
}