- if (argc > 1 && argv[0][0] == '-') {
- if (!strcmp("-X", argv[0])) {
- enable_x11 = 1;
- } else {
- if (strcmp("-h", argv[0])) {
- fprintf(stderr, "%s: unknown option '%s'!\n\n", argv0, argv[0]);
- }
- usage(argv0);
+ mesg_yes = 0;
+
+ argv0 = argv[0];
+
+ /*
+ * Glibc violates POSIX by default and skips over non-option arguments and
+ * parses later arguments which look like options as well. But we want to
+ * pass everything except the options unmodified to execvp(). Prefixing
+ * the optstring with "+" fixes this behaver. This is not POSIX
+ * compatible, but the option should be ignored on other systems.
+ */
+ while ((option = getopt(argc, argv, "+Xmhv")) != -1) {
+ switch (option) {
+ case 'X':
+ enable_x11 = 1;
+ break;
+ case 'm':
+ mesg_yes = 1;
+ break;
+ case 'h':
+ usage(argv0);
+ break;
+ case 'v':
+ printf("%s%s\n",
+ PACKAGE_STRING,
+ strlen(GIT_VERSION) ? " (Git " GIT_VERSION ")" : "");
+ exit(EXIT_SUCCESS);
+ break;
+ default:
+ fprintf(stderr, "%s: unknown option '%s'!\n\n",
+ argv0, argv[optind - 1]);
+ usage(argv0);
+ break;