From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 9F40F43D49;
	Mon, 25 Mar 2024 21:54:24 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 7212C40A77;
	Mon, 25 Mar 2024 21:54:19 +0100 (CET)
Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com
 [209.85.214.176])
 by mails.dpdk.org (Postfix) with ESMTP id 431744067D
 for <dev@dpdk.org>; Mon, 25 Mar 2024 21:54:18 +0100 (CET)
Received: by mail-pl1-f176.google.com with SMTP id
 d9443c01a7336-1dee5daa236so35535895ad.0
 for <dev@dpdk.org>; Mon, 25 Mar 2024 13:54:18 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711400057;
 x=1712004857; 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=j2bWaQew6uFbTYM7AsbymK+bBIaNZpLFH5iS8177eDI=;
 b=MItS1Kg02JktqL+zuDh2N/71zvPrtt5zLFxzrip7H/2+ZuwTKyUz1eRhCGYxfQ/v8F
 REU2nnF6fN4P7IW3LKmZwGofZkmTGKnIM/9CMEXkmZ5DYFi+I9uL8kOXj2IvLn3kslH1
 Rk68xcazhh76vtuZgDkRU0dCLKmsoCrOGG8pNsG9aMqn4wlb5Ra9RgpDYom3ou5XUpoe
 2SKvWVaraMnl3l3CKpKUVVhk7C5kLuVY+R9yILWsN6t42oqO3gHHjLD3gGuWUwmhtyiD
 JRN14Ntwm1Xg/qbMOHehvlenYUlVflNKE2hPXHIHNVe907VgdrMK+tPdwP3W7Yh6ngzp
 o/lw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1711400057; x=1712004857;
 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=j2bWaQew6uFbTYM7AsbymK+bBIaNZpLFH5iS8177eDI=;
 b=Z6kdu20mhNbbtzkOmdTfql3CT2UN56iKWQ+RWHW9EZr7S76x02KIotRMCkYpIA5rJk
 GaoTJLAPgUpU1Wu3x6kbm9BKdGLTds3vNKrOztnVzGO2v3VMGVfpi7cvR9Srtg2C+YEg
 9tqPeyh4BVA90cdHu7kFKqCX1OS41zLR5P5422tpz/WZrk+xyB0SOZAGoiIN5PAAEb9E
 56k2kBXwFji0UGbBIWLrQFi5Tk+mMBwr/LsHl+sKHZfxHfOyW9+qkLcVCDOuc8cDbKVK
 aB0TBvdgRPhqb+dQTONy9OjO8RQZd2sjVyD5X4I8g1hEaQUec3Qe+70c0Ixc14DUW85A
 I13A==
X-Gm-Message-State: AOJu0YyU2gNn7dLSq9tfJk3jbNU2fCPGOY8sbAyH4xZck5gHVVHIKPo/
 7GrIkUz27Qmv0fLqISF8PSWxEBGBmVmXSDGqHS76Urpy/D+d86Y27K0Ic1KaS83cUTlM+qAz115
 o
X-Google-Smtp-Source: AGHT+IFYXLB3txJGWqT/r49jZ6r4xkiGopDhBCitkzMId1c07SKK7PiWgrKEC4InVg/FLKdUjbd5Iw==
X-Received: by 2002:a17:902:f70e:b0:1e0:e56e:eddd with SMTP id
 h14-20020a170902f70e00b001e0e56eedddmr602863plo.32.1711400057272; 
 Mon, 25 Mar 2024 13:54:17 -0700 (PDT)
Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203])
 by smtp.gmail.com with ESMTPSA id
 b18-20020a170903229200b001e0b5eee802sm3164487plh.123.2024.03.25.13.54.15
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 25 Mar 2024 13:54:16 -0700 (PDT)
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
 Tyler Retzlaff <roretzla@linux.microsoft.com>,
 Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>,
 Pallavi Kadam <pallavi.kadam@intel.com>
Subject: [PATCH v12 01/14] windows: make getopt functions have const properties
Date: Mon, 25 Mar 2024 13:46:58 -0700
Message-ID: <20240325205405.669897-2-stephen@networkplumber.org>
X-Mailer: git-send-email 2.43.0
In-Reply-To: <20240325205405.669897-1-stephen@networkplumber.org>
References: <20200814173441.23086-1-stephen@networkplumber.org>
 <20240325205405.669897-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 <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=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 <stephen@networkplumber.org>
Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 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 a1f51c6c23..50ff71b930 100644
--- a/lib/eal/windows/getopt.c
+++ b/lib/eal/windows/getopt.c
@@ -20,7 +20,7 @@
 #include <string.h>
 #include <stdlib.h>
 
-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 6f57af454b..e4cf6873cb 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