From e2fec4f27f4567fe4cad2b7ee7b7ac451f6c58a1 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 9 Oct 2023 22:38:04 +0200 Subject: [PATCH] Update getopt_port to 6ad8cc105. --- getopt/getopt.c | 13 ++++++++++++- getopt/getopt.h | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/getopt/getopt.c b/getopt/getopt.c index eae36a64..5705bc11 100644 --- a/getopt/getopt.c +++ b/getopt/getopt.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012-2017, Kim Grasman + * Copyright (c) 2012-2023, Kim Grasman * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -159,6 +159,7 @@ int getopt_long(int argc, char* const argv[], const char* optstring, const struct option* match = NULL; int num_matches = 0; size_t argument_name_length = 0; + size_t option_length = 0; const char* current_argument = NULL; int retval = -1; @@ -175,6 +176,16 @@ int getopt_long(int argc, char* const argv[], const char* optstring, current_argument = argv[optind] + 2; argument_name_length = strcspn(current_argument, "="); for (; o->name; ++o) { + /* Check for exact match first. */ + option_length = strlen(o->name); + if (option_length == argument_name_length && + strncmp(o->name, current_argument, option_length) == 0) { + match = o; + num_matches = 1; + break; + } + + /* If not exact, count the number of abbreviated matches. */ if (strncmp(o->name, current_argument, argument_name_length) == 0) { match = o; ++num_matches; diff --git a/getopt/getopt.h b/getopt/getopt.h index a1d6db03..166ab261 100644 --- a/getopt/getopt.h +++ b/getopt/getopt.h @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012-2017, Kim Grasman + * Copyright (c) 2012-2023, Kim Grasman * All rights reserved. * * Redistribution and use in source and binary forms, with or without