summaryrefslogtreecommitdiffstats
path: root/disk-utils/mkfs.c
diff options
context:
space:
mode:
authorSami Kerola2011-06-29 00:24:27 +0200
committerSami Kerola2011-06-29 13:36:52 +0200
commit02b1c216168fa049cbecfb4fb65248f453cb5f14 (patch)
treec3e7339165eacee2aba9533092ea0b752bbd968b /disk-utils/mkfs.c
parentmkfs: include-what-you-use header check (diff)
downloadkernel-qcow2-util-linux-02b1c216168fa049cbecfb4fb65248f453cb5f14.tar.gz
kernel-qcow2-util-linux-02b1c216168fa049cbecfb4fb65248f453cb5f14.tar.xz
kernel-qcow2-util-linux-02b1c216168fa049cbecfb4fb65248f453cb5f14.zip
mkfs: coding style fixes
The patch includes two symbolic exit values and a main argv notation change, none of which should cause any side effects. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'disk-utils/mkfs.c')
-rw-r--r--disk-utils/mkfs.c154
1 files changed, 78 insertions, 76 deletions
diff --git a/disk-utils/mkfs.c b/disk-utils/mkfs.c
index 389a21c7b..ce845a571 100644
--- a/disk-utils/mkfs.c
+++ b/disk-utils/mkfs.c
@@ -25,7 +25,7 @@
#include "xalloc.h"
#ifndef DEFAULT_FSTYPE
-# define DEFAULT_FSTYPE "ext2"
+#define DEFAULT_FSTYPE "ext2"
#endif
#define SEARCH_PATH "PATH=" FS_SEARCH_PATH
@@ -61,80 +61,82 @@ static void __attribute__ ((__noreturn__)) print_version(void)
exit(EXIT_SUCCESS);
}
-int main(int argc, char *argv[])
+int main(int argc, char **argv)
{
- char *progname; /* name of executable to be called */
- char *fstype = NULL;
- int i, more = 0, verbose = 0;
- char *oldpath, *newpath;
-
- enum { VERSION_OPTION = CHAR_MAX + 1 };
-
- static const struct option longopts[] = {
- {"type", required_argument, NULL, 't'},
- {"version", no_argument, NULL, VERSION_OPTION},
- {"help", no_argument, NULL, 'h'},
- {NULL, 0, NULL, 0}
- };
-
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
-
- if (argc == 2 && !strcmp(argv[1], "-V"))
- print_version();
-
- /* Check commandline options. */
- opterr = 0;
- while ((more == 0) && ((i = getopt_long(argc, argv, "Vt:h", longopts, NULL)) != -1))
- switch (i) {
- case 'V':
- verbose++;
- break;
- case 't':
- fstype = optarg;
- break;
- case 'h':
- usage(stdout);
- case VERSION_OPTION:
- print_version();
- default:
- optind--;
- more = 1;
- break; /* start of specific arguments */
- }
- if (optind == argc)
- usage(stderr);
-
- /* If -t wasn't specified, use the default */
- if (fstype == NULL)
- fstype = DEFAULT_FSTYPE;
-
- /* Set PATH and program name */
- oldpath = getenv("PATH");
- if (!oldpath)
- oldpath = "/bin";
-
- newpath = xmalloc(strlen(oldpath) + sizeof(SEARCH_PATH) + 3);
- sprintf(newpath, "%s:%s\n", SEARCH_PATH, oldpath);
- putenv(newpath);
-
- progname = xmalloc(sizeof(PROGNAME) + strlen(fstype) + 1);
- sprintf(progname, PROGNAME, fstype);
- argv[--optind] = progname;
-
- if (verbose) {
- printf(_("mkfs (%s)\n"), PACKAGE_STRING);
- i = optind;
- while (argv[i])
- printf("%s ", argv[i++]);
- printf("\n");
- if (verbose > 1)
- return 0;
- }
-
- /* Execute the program */
- execvp(progname, argv+optind);
- perror(progname);
- return 1;
+ char *progname; /* name of executable to be called */
+ char *fstype = NULL;
+ int i, more = 0, verbose = 0;
+ char *oldpath, *newpath;
+
+ enum { VERSION_OPTION = CHAR_MAX + 1 };
+
+ static const struct option longopts[] = {
+ {"type", required_argument, NULL, 't'},
+ {"version", no_argument, NULL, VERSION_OPTION},
+ {"help", no_argument, NULL, 'h'},
+ {NULL, 0, NULL, 0}
+ };
+
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+
+ if (argc == 2 && !strcmp(argv[1], "-V"))
+ print_version();
+
+ /* Check commandline options. */
+ opterr = 0;
+ while ((more == 0)
+ && ((i = getopt_long(argc, argv, "Vt:h", longopts, NULL))
+ != -1))
+ switch (i) {
+ case 'V':
+ verbose++;
+ break;
+ case 't':
+ fstype = optarg;
+ break;
+ case 'h':
+ usage(stdout);
+ case VERSION_OPTION:
+ print_version();
+ default:
+ optind--;
+ more = 1;
+ break; /* start of specific arguments */
+ }
+ if (optind == argc)
+ usage(stderr);
+
+ /* If -t wasn't specified, use the default */
+ if (fstype == NULL)
+ fstype = DEFAULT_FSTYPE;
+
+ /* Set PATH and program name */
+ oldpath = getenv("PATH");
+ if (!oldpath)
+ oldpath = "/bin";
+
+ newpath = xmalloc(strlen(oldpath) + sizeof(SEARCH_PATH) + 3);
+ sprintf(newpath, "%s:%s\n", SEARCH_PATH, oldpath);
+ putenv(newpath);
+
+ progname = xmalloc(sizeof(PROGNAME) + strlen(fstype) + 1);
+ sprintf(progname, PROGNAME, fstype);
+ argv[--optind] = progname;
+
+ if (verbose) {
+ printf(_("mkfs (%s)\n"), PACKAGE_STRING);
+ i = optind;
+ while (argv[i])
+ printf("%s ", argv[i++]);
+ printf("\n");
+ if (verbose > 1)
+ return EXIT_SUCCESS;
+ }
+
+ /* Execute the program */
+ execvp(progname, argv + optind);
+ perror(progname);
+ return EXIT_FAILURE;
}