summaryrefslogtreecommitdiffstats
path: root/disk-utils/mkfs.c
diff options
context:
space:
mode:
authorDavidlohr Bueso2010-12-06 15:10:59 +0100
committerKarel Zak2011-01-17 16:54:24 +0100
commiteb811909ccebb1acc63ded5c1c87f7c892c0660c (patch)
tree55a81829bb93a83ee7f313768be76931134a777b /disk-utils/mkfs.c
parentuuidd: mention -q in uuidd.8 (diff)
downloadkernel-qcow2-util-linux-eb811909ccebb1acc63ded5c1c87f7c892c0660c.tar.gz
kernel-qcow2-util-linux-eb811909ccebb1acc63ded5c1c87f7c892c0660c.tar.xz
kernel-qcow2-util-linux-eb811909ccebb1acc63ded5c1c87f7c892c0660c.zip
mkfs: general cleanups
Use xalloc, remove unused headers, use EXIT_* constants. Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Diffstat (limited to 'disk-utils/mkfs.c')
-rw-r--r--disk-utils/mkfs.c25
1 files changed, 7 insertions, 18 deletions
diff --git a/disk-utils/mkfs.c b/disk-utils/mkfs.c
index a0ccd16f6..e22c5125e 100644
--- a/disk-utils/mkfs.c
+++ b/disk-utils/mkfs.c
@@ -17,12 +17,12 @@
#include <stdio.h>
-#include <stdlib.h>
#include <unistd.h>
#include <string.h>
-#include <getopt.h>
#include <nls.h>
+#include "xalloc.h"
+
#ifndef DEFAULT_FSTYPE
# define DEFAULT_FSTYPE "ext2"
#endif
@@ -50,7 +50,7 @@ int main(int argc, char *argv[])
if (argc == 2 &&
(!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version"))) {
printf(_("%s (%s)\n"), program_name, PACKAGE_STRING);
- exit(0);
+ exit(EXIT_SUCCESS);
}
/* Check commandline options. */
@@ -68,11 +68,8 @@ int main(int argc, char *argv[])
more = 1;
break; /* start of specific arguments */
}
- if (optind == argc) {
- fprintf(stderr,
- _("Usage: mkfs [-V] [-t fstype] [fs-options] device [size]\n"));
- return -1;
- }
+ if (optind == argc)
+ errx(EXIT_FAILURE, _("Usage: mkfs [-V] [-t fstype] [fs-options] device [size]"));
/* If -t wasn't specified, use the default */
if (fstype == NULL)
@@ -83,19 +80,11 @@ int main(int argc, char *argv[])
if (!oldpath)
oldpath = "/bin";
- newpath = (char *) malloc(strlen(oldpath) + sizeof(SEARCH_PATH) + 3);
- if (!newpath) {
- fprintf(stderr, _("%s: Out of memory!\n"), "mkfs");
- exit(1);
- }
+ newpath = xmalloc(strlen(oldpath) + sizeof(SEARCH_PATH) + 3);
sprintf(newpath, "%s:%s\n", SEARCH_PATH, oldpath);
putenv(newpath);
- progname = (char *) malloc(sizeof(PROGNAME) + strlen(fstype) + 1);
- if (!progname) {
- fprintf(stderr, _("%s: Out of memory!\n"), "mkfs");
- exit(1);
- }
+ progname = xmalloc(sizeof(PROGNAME) + strlen(fstype) + 1);
sprintf(progname, PROGNAME, fstype);
argv[--optind] = progname;