20
21
#include <unistd.h>
24
25
#include "xalloc.h"
26
27
#ifndef DEFAULT_FSTYPE
27
# define DEFAULT_FSTYPE "ext2"
28
#define DEFAULT_FSTYPE "ext2"
30
31
#define SEARCH_PATH "PATH=" FS_SEARCH_PATH
31
32
#define PROGNAME "mkfs.%s"
34
int main(int argc, char *argv[])
36
char *progname; /* name of executable to be called */
38
int i, more = 0, verbose = 0;
39
char *oldpath, *newpath;
40
char *program_name, *p;
42
program_name = argv[0];
43
if ((p = strrchr(program_name, '/')) != NULL)
46
setlocale(LC_ALL, "");
47
bindtextdomain(PACKAGE, LOCALEDIR);
51
(!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version"))) {
52
printf(_("%s (%s)\n"), program_name, PACKAGE_STRING);
56
/* Check commandline options. */
58
while ((more == 0) && ((i = getopt(argc, argv, "Vt:")) != -1))
69
break; /* start of specific arguments */
72
errx(EXIT_FAILURE, _("Usage: mkfs [-V] [-t fstype] [fs-options] device [size]"));
74
/* If -t wasn't specified, use the default */
76
fstype = DEFAULT_FSTYPE;
78
/* Set PATH and program name */
79
oldpath = getenv("PATH");
83
newpath = xmalloc(strlen(oldpath) + sizeof(SEARCH_PATH) + 3);
84
sprintf(newpath, "%s:%s\n", SEARCH_PATH, oldpath);
87
progname = xmalloc(sizeof(PROGNAME) + strlen(fstype) + 1);
88
sprintf(progname, PROGNAME, fstype);
89
argv[--optind] = progname;
92
printf(_("mkfs (%s)\n"), PACKAGE_STRING);
95
printf("%s ", argv[i++]);
101
/* Execute the program */
102
execvp(progname, argv+optind);
35
static void __attribute__ ((__noreturn__)) usage(FILE * out)
38
_("Usage: %s [options] [-t type fs-options] device [size]\n"),
39
program_invocation_short_name);
41
fprintf(out, _("\nOptions:\n"
42
" -t, --type=TYPE file system type, when undefined ext2 is used\n"
43
" fs-options parameters to real file system builder\n"
44
" device path to a device\n"
45
" size number of blocks on the device\n"
46
" -V, --verbose explain what is done\n"
47
" defining -V more than once will cause a dry-run\n"
48
" -V, --version output version information and exit\n"
49
" -V as version must be only option\n"
50
" -h, --help display this help and exit\n"));
52
fprintf(out, _("\nFor more information see mkfs(8).\n"));
54
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
57
static void __attribute__ ((__noreturn__)) print_version(void)
59
printf(_("%s (%s)\n"),
60
program_invocation_short_name, PACKAGE_STRING);
64
int main(int argc, char **argv)
66
char *progname; /* name of executable to be called */
68
int i, more = 0, verbose = 0;
69
char *oldpath, *newpath;
71
enum { VERSION_OPTION = CHAR_MAX + 1 };
73
static const struct option longopts[] = {
74
{"type", required_argument, NULL, 't'},
75
{"version", no_argument, NULL, VERSION_OPTION},
76
{"help", no_argument, NULL, 'h'},
80
setlocale(LC_ALL, "");
81
bindtextdomain(PACKAGE, LOCALEDIR);
84
if (argc == 2 && !strcmp(argv[1], "-V"))
87
/* Check commandline options. */
90
&& ((i = getopt_long(argc, argv, "Vt:h", longopts, NULL))
106
break; /* start of specific arguments */
111
/* If -t wasn't specified, use the default */
113
fstype = DEFAULT_FSTYPE;
115
/* Set PATH and program name */
116
oldpath = getenv("PATH");
120
newpath = xmalloc(strlen(oldpath) + sizeof(SEARCH_PATH) + 3);
121
sprintf(newpath, "%s:%s\n", SEARCH_PATH, oldpath);
124
progname = xmalloc(sizeof(PROGNAME) + strlen(fstype) + 1);
125
sprintf(progname, PROGNAME, fstype);
126
argv[--optind] = progname;
129
printf(_("mkfs (%s)\n"), PACKAGE_STRING);
132
printf("%s ", argv[i++]);
138
/* Execute the program */
139
execvp(progname, argv + optind);