#include <errno.h>
#include <ctype.h>
#include <dirent.h>
+#include <getopt.h>
#include "c.h"
#include "nls.h"
int main(int argc, char *argv[])
{
char *newroot, *init, **initargs;
+ int c;
+ static const struct option longopts[] = {
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 'h'},
+ {NULL, 0, NULL, 0}
+ };
+
atexit(close_stdout);
- if (argv[1] && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")))
- usage(stdout);
- if (argv[1] && (!strcmp(argv[1], "--version") || !strcmp(argv[1], "-V"))) {
- printf(UTIL_LINUX_VERSION);
- return EXIT_SUCCESS;
- }
+ while ((c = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
+ switch (c) {
+ case 'V':
+ printf(UTIL_LINUX_VERSION);
+ return EXIT_SUCCESS;
+ case 'h':
+ usage(stdout);
+ default:
+ errtryhelp(EXIT_FAILURE);
+ }
if (argc < 3)
usage(stderr);