Yidi Lin has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/78887?usp=email )
Change subject: libpayload/libc/getopt_long: Use common GCD ......................................................................
libpayload/libc/getopt_long: Use common GCD
TEST=emerge-geralt libpayload
Change-Id: Ib9dd1d2f658d4411c36d0198774819690686a393 Signed-off-by: Yidi Lin yidilin@chromium.org --- M payloads/libpayload/libc/Makefile.inc M payloads/libpayload/libc/getopt_long.c 2 files changed, 3 insertions(+), 20 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/87/78887/1
diff --git a/payloads/libpayload/libc/Makefile.inc b/payloads/libpayload/libc/Makefile.inc index bc706ae..2d277da 100644 --- a/payloads/libpayload/libc/Makefile.inc +++ b/payloads/libpayload/libc/Makefile.inc @@ -46,4 +46,5 @@
ifeq ($(CONFIG_LP_LIBC),y) libc-srcs += $(coreboottop)/src/commonlib/bsd/elog.c +libc-srcs += $(coreboottop)/src/commonlib/bsd/gcd.c endif diff --git a/payloads/libpayload/libc/getopt_long.c b/payloads/libpayload/libc/getopt_long.c index 365bc4a..822ce96 100644 --- a/payloads/libpayload/libc/getopt_long.c +++ b/payloads/libpayload/libc/getopt_long.c @@ -54,6 +54,7 @@ #include <err.h> #include <errno.h> */ +#include <commonlib/bsd/gcd.h> #include <libpayload.h> #include <getopt.h> #define warnx(x...) printf(x) @@ -88,7 +89,6 @@ const struct option *, int *, int); static int parse_long_options(char * const *, const char *, const struct option *, int *, int); -static int gcd(int, int); static void permute_args(int, int, int, char * const *);
static char *place = EMSG; /* option letter processing */ @@ -106,24 +106,6 @@ static const char illoptstring[] = "unknown option -- %s";
/* - * Compute the greatest common divisor of a and b. - */ -static int -gcd(int a, int b) -{ - int c; - - c = a % b; - while (c != 0) { - a = b; - b = c; - c = a % b; - } - - return (b); -} - -/* * Exchange the block from nonopt_start to nonopt_end with the block * from nonopt_end to opt_end (keeping the same order of arguments * in each block). @@ -140,7 +122,7 @@ */ nnonopts = panonopt_end - panonopt_start; nopts = opt_end - panonopt_end; - ncycle = gcd(nnonopts, nopts); + ncycle = gcd32(nnonopts, nopts); cyclelen = (opt_end - panonopt_start) / ncycle;
for (i = 0; i < ncycle; i++) {