diff options
Diffstat (limited to 'src/fish.cpp')
-rw-r--r-- | src/fish.cpp | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/src/fish.cpp b/src/fish.cpp index 91610232..048c9cbe 100644 --- a/src/fish.cpp +++ b/src/fish.cpp @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include "config.h" #include <assert.h> +#include <getopt.h> #include <limits.h> #include <stddef.h> #include <stdint.h> @@ -39,15 +40,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include <sys/socket.h> // IWYU pragma: keep - suggests internal header #include <sys/un.h> #include <pwd.h> - -#ifdef HAVE_GETOPT_H -#include <getopt.h> -#endif - #include <locale.h> #include "fallback.h" // IWYU pragma: keep - #include "common.h" #include "reader.h" #include "builtin.h" @@ -72,11 +67,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #define PATH_MAX 1024 #endif -/** - The string describing the single-character options accepted by the main fish binary -*/ -#define GETOPT_STRING "+hilnvc:p:d:" - /* If we are doing profiling, the filename to output to */ static const char *s_profiling_output_filename = NULL; @@ -370,7 +360,8 @@ static int read_init(const struct config_paths_t &paths) */ static int fish_parse_opt(int argc, char **argv, std::vector<std::string> *cmds) { - const struct option long_options[] = + const char *short_opts = "+hilnvc:p:d:"; + const struct option long_opts[] = { { "command", required_argument, NULL, 'c' }, { "debug-level", required_argument, NULL, 'd' }, @@ -383,17 +374,15 @@ static int fish_parse_opt(int argc, char **argv, std::vector<std::string> *cmds) { NULL, 0, NULL, 0 } }; - while (1) + int opt; + while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) { - int opt = getopt_long(argc, argv, GETOPT_STRING, long_options, NULL); - if (opt == -1) - break; - switch (opt) { case 0: { - break; + fwprintf(stderr, _(L"getopt_long() unexpectedly returned zero\n")); + exit_without_destructors(127); } case 'c': @@ -462,6 +451,7 @@ static int fish_parse_opt(int argc, char **argv, std::vector<std::string> *cmds) default: { + // We assume getopt_long() has already emitted a diagnostic msg. exit_without_destructors(1); } |