diff options
author | Yidi Lin <yidilin@chromium.org> | 2023-11-02 12:29:04 +0800 |
---|---|---|
committer | Martin L Roth <gaumless@gmail.com> | 2023-11-04 17:09:36 +0000 |
commit | 0285d67ae37bed601c127490b3d03625b0791c4a (patch) | |
tree | 50a44bbb720d0b47e6a34f5518e8658f5f756de0 /payloads | |
parent | 85d7809e0ca80b94fd23a753e0894b8843d38367 (diff) |
libpayload/libc/getopt_long: Use common GCD
TEST=emerge-geralt libpayload
Change-Id: Ib9dd1d2f658d4411c36d0198774819690686a393
Signed-off-by: Yidi Lin <yidilin@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/78887
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'payloads')
-rw-r--r-- | payloads/libpayload/libc/Makefile.inc | 1 | ||||
-rw-r--r-- | payloads/libpayload/libc/getopt_long.c | 22 |
2 files changed, 3 insertions, 20 deletions
diff --git a/payloads/libpayload/libc/Makefile.inc b/payloads/libpayload/libc/Makefile.inc index bc706ae5a7..2d277da3b5 100644 --- a/payloads/libpayload/libc/Makefile.inc +++ b/payloads/libpayload/libc/Makefile.inc @@ -46,4 +46,5 @@ endif 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 365bc4a85a..822ce96904 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 @@ static int getopt_internal(int, char * const *, const char *, 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 illoptchar[] = "unknown option -- %c"; 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 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end, */ 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++) { |