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>
This commit is contained in:
Yidi Lin 2023-11-02 12:29:04 +08:00 committed by Martin L Roth
parent 85d7809e0c
commit 0285d67ae3
2 changed files with 3 additions and 20 deletions

View File

@ -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

View File

@ -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 */
@ -105,24 +105,6 @@ static const char noarg[] = "option doesn't take an argument -- %.*s";
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
@ -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++) {