From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B56D743CDB; Sun, 17 Mar 2024 16:34:26 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 411004026F; Sun, 17 Mar 2024 16:34:26 +0100 (CET) Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by mails.dpdk.org (Postfix) with ESMTP id 763E540262 for ; Sun, 17 Mar 2024 16:34:24 +0100 (CET) Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-5d3907ff128so2766101a12.3 for ; Sun, 17 Mar 2024 08:34:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1710689663; x=1711294463; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MxTYZpMXUfqtuNgTJbwrIqu/ZFVDcUewbND1CRpyEKY=; b=xYojKgUK7AC7XeW5o6iBa24tdRC64Yx+YuOPk80x6RnAcepmtU1ZYHerA4sjHQgvZ4 FvTJCl0J6MztI/oRTH4wDTQAoy9DtCg33ZBYY8yLWYD5bP64WlOAXKLpOvnHKFW586Ir JnYBYTNG1xvk7GJQSYKoREZvCj439WgY4nuHNQ6oJO0dTCAowA1w3t0QYyMR2I+lhQMC gsRiBBrY+CBwTjk/OVUC/bZoese2s8Uc0oZsSCEmvPPfcKJbXa2kaXMOYqLtwewQRcIv ZlGnlvxmuNRdn9Pjqo9dNQWe7M2S1Dkyvff5gii2xhWpq2lz/FNGPVoKr537J3P/6q9f jcFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710689663; x=1711294463; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MxTYZpMXUfqtuNgTJbwrIqu/ZFVDcUewbND1CRpyEKY=; b=iCOgzPzTJL1HEo0lpsZTAlZtwzKYkBXlsqFWSFIPe8QFiyVGYXhZfoBm5tZmNfl05W gSWuHtw1yd+qWsHeQ2VPw4F4tkhWoIlCBWyhAKxIGpw8WP8hPJsHmSAAXz32zWWbqDs4 0CUtrPHOLHBtPeI02LZQL1RzCPngut8+g1VI0zAjijqchwB+Lt04lslJrE02O7fDMKdW 3zHs1468GD3f41ZZu5g/cO0I5IO8PT0KRn5R1VMXkPXJOku2v9lEZc87qWUdIr7+vHtd RAkv212P+oQPi2pg5gyc74Bc3CJCexEQlcnZbvpdEqMXSgsEBjIJpZK4TN98zSWMthi0 Sqbw== X-Gm-Message-State: AOJu0Yyd/M5CBZkTjFNzOGC/gveOkQ2+LAZKGD9L5d4peVwM/jtD25G2 OR54tR90wKlQ+QA3Sq5mkyE+ZkFR9LrDx2ZKLsS9AvRHKE6w3bOgm/7o7S6EJocFkubO6QyZtKT 5xtU= X-Google-Smtp-Source: AGHT+IGV44zpieBqHJccz/5QLBwIvEDT6MS5ZJRMHclsZarmFz5yRiHiuF/bpZ1qyY+Nle5UX6dvmg== X-Received: by 2002:a17:902:ce0f:b0:1e0:115c:e05d with SMTP id k15-20020a170902ce0f00b001e0115ce05dmr2693562plg.9.1710689663375; Sun, 17 Mar 2024 08:34:23 -0700 (PDT) Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id h5-20020a170902f54500b001e009717560sm364089plf.232.2024.03.17.08.34.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 08:34:22 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Dmitry Kozlyuk , Pallavi Kadam Subject: [PATCH v2] windows: make getopt functions have const properties Date: Sun, 17 Mar 2024 08:33:59 -0700 Message-ID: <20240317153413.5780-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240315151407.7517-1-stephen@networkplumber.org> References: <20240315151407.7517-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Having different prototypes on different platforms can lead to lots of unnecessary workarounds. Looks like the version of getopt used from windows was based on an older out of date version from FreeBSD. This patch changes getopt, getopt_long, etc to have the same const attributes as Linux and FreeBSD. The changes are derived from the current FreeBSD version of getopt_long. Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff Acked-by: Dmitry Kozlyuk --- v2 - remove orig file lib/eal/windows/getopt.c | 23 ++++++++++++----------- lib/eal/windows/include/getopt.h | 8 ++++---- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/eal/windows/getopt.c b/lib/eal/windows/getopt.c index a1f51c6c2318..50ff71b9300d 100644 --- a/lib/eal/windows/getopt.c +++ b/lib/eal/windows/getopt.c @@ -20,7 +20,7 @@ #include #include -const char *optarg; /* argument associated with option */ +char *optarg; /* argument associated with option */ int opterr = 1; /* if error message should be printed */ int optind = 1; /* index into parent argv vector */ int optopt = '?'; /* character checked for validity */ @@ -39,9 +39,9 @@ static void pass(const char *a) {(void) a; } #define BADARG ((*options == ':') ? (int)':' : (int)'?') #define INORDER 1 -#define EMSG "" +static char EMSG[] = ""; -static const char *place = EMSG; /* option letter processing */ +static char *place = EMSG; /* option letter processing */ /* XXX: set optreset to 1 rather than these two */ static int nonopt_start = -1; /* first non option argument (for permute) */ @@ -80,7 +80,7 @@ gcd(int a, int b) */ static void permute_args(int panonopt_start, int panonopt_end, int opt_end, - char **nargv) + char * const *nargv) { int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos; char *swap; @@ -101,11 +101,12 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end, pos -= nnonopts; else pos += nopts; + swap = nargv[pos]; /* LINTED const cast */ - ((char **) nargv)[pos] = nargv[cstart]; + ((char **)(uintptr_t)nargv)[pos] = nargv[cstart]; /* LINTED const cast */ - ((char **)nargv)[cstart] = swap; + ((char **)(uintptr_t)nargv)[cstart] = swap; } } } @@ -116,7 +117,7 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end, * Returns -1 if short_too is set and the option does not match long_options. */ static int -parse_long_options(char **nargv, const char *options, +parse_long_options(char * const *nargv, const char *options, const struct option *long_options, int *idx, int short_too) { const char *current_argv; @@ -236,7 +237,7 @@ parse_long_options(char **nargv, const char *options, * Parse argc/argv argument vector. Called by user level routines. */ static int -getopt_internal(int nargc, char **nargv, const char *options, +getopt_internal(int nargc, char *const nargv[], const char *options, const struct option *long_options, int *idx, int flags) { char *oli; /* option letter list index */ @@ -434,7 +435,7 @@ getopt_internal(int nargc, char **nargv, const char *options, * Parse argc/argv argument vector. */ int -getopt(int nargc, char *nargv[], const char *options) +getopt(int nargc, char *const nargv[], const char *options) { return getopt_internal(nargc, nargv, options, NULL, NULL, FLAG_PERMUTE); @@ -445,7 +446,7 @@ getopt(int nargc, char *nargv[], const char *options) * Parse argc/argv argument vector. */ int -getopt_long(int nargc, char *nargv[], const char *options, +getopt_long(int nargc, char *const nargv[], const char *options, const struct option *long_options, int *idx) { @@ -458,7 +459,7 @@ getopt_long(int nargc, char *nargv[], const char *options, * Parse argc/argv argument vector. */ int -getopt_long_only(int nargc, char *nargv[], const char *options, +getopt_long_only(int nargc, char *const nargv[], const char *options, const struct option *long_options, int *idx) { diff --git a/lib/eal/windows/include/getopt.h b/lib/eal/windows/include/getopt.h index 6f57af454b17..e4cf6873cb0c 100644 --- a/lib/eal/windows/include/getopt.h +++ b/lib/eal/windows/include/getopt.h @@ -44,7 +44,7 @@ /** argument to current option, or NULL if it has none */ -extern const char *optarg; +extern char *optarg; /** Current position in arg string. Starts from 1. * Setting to 0 resets state. */ @@ -80,14 +80,14 @@ struct option { }; /** Compat: getopt */ -int getopt(int argc, char *argv[], const char *options); +int getopt(int argc, char *const argv[], const char *options); /** Compat: getopt_long */ -int getopt_long(int argc, char *argv[], const char *options, +int getopt_long(int argc, char *const argv[], const char *options, const struct option *longopts, int *longindex); /** Compat: getopt_long_only */ -int getopt_long_only(int nargc, char *argv[], const char *options, +int getopt_long_only(int nargc, char *const argv[], const char *options, const struct option *long_options, int *idx); -- 2.43.0