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 7A5EB459D7; Thu, 19 Sep 2024 17:06:36 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7C65D4337D; Thu, 19 Sep 2024 17:06:23 +0200 (CEST) Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by mails.dpdk.org (Postfix) with ESMTP id C03B04336A for ; Thu, 19 Sep 2024 17:06:21 +0200 (CEST) Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-718e285544fso705077b3a.1 for ; Thu, 19 Sep 2024 08:06:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726758381; x=1727363181; 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=IaLvkAy7EZnUXhXV0cLtvwGD9fj1cd6nyd8cZK/jfkk=; b=coAc8zqITlESNPJV/X8RM3KqkLfsaLQ/qT/xHJ2P9z/HgOduCq8fICi6PGG2aioQzZ BulQ4NNF4wSLb71ZsvqdgnZ2gDbJ48HORfJB+hPI8iq4c8PlafHt+dRA+T7OMWxBOS2S oFaBgWPNca2+NNuCrWhK/lE0W9Bg+EZTKWTMx5ZjHNIin9FivVJhW3x8LmJ6uIBSli1z IiAb18g0rrv0Q27cHAR5fM3TkeJ5n/1rShOboAldBbapdKH9HYDlH6+SRkA/bFuuUkJM y8woLZOk9f91GUeLAgtj6xTGoC5BdYjC8jK7TlJl/hg0VmtmoY1BvnAWjmYk2k6ZIA1c 25vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726758381; x=1727363181; 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=IaLvkAy7EZnUXhXV0cLtvwGD9fj1cd6nyd8cZK/jfkk=; b=OLzPq8oYywaH1jPNQ5m85Y1imh8zfjXWZCL9M0YWHKUTrkYfxJo4Y3gLrBK/NZkef+ fI+oX/BYffERIrL8tOzq95pPZ6rasO51UG8M1JhXkEiaOkBQ2alCquTz+KWAEQPr7XB8 o2+CWFMuLpEIutrhqjh5Fk+P9VIoJub+cSFEHFZa4aB8fW6tYzQXucvgZzyw4tYDa9uk OGHXBjZuyuGkmx4Ywmdju0dpE4P0GM/b/Inb0Y/Hb60APNqRT05QUolDkMK9bp94VJIl CyNPxjKp2+dZewy6aXUL2eEqlxPTH1wxTXriTPSo85yNLBo8fce4K6Q0kdJX5cS4L1YJ aRqQ== X-Gm-Message-State: AOJu0Yw9zDtUKwyaZYTEmvTo4xGqACGbkr5qlw+NJFwT5+f6lJTiSJlo 6D2i52kCCbHNz8WZFcVDpKwMiE0bkSgjBEmZmEr1KGQB8i+bg57XtbOX4GqLbIa9IAtNzSPJ54M Z X-Google-Smtp-Source: AGHT+IFlP8Utfe2AysXj55KNf8nSCzyAHdnzRHgg5031q4EI/YTCfO5vhq3kWsbW09P6hxcahWXF/Q== X-Received: by 2002:a05:6a00:13a9:b0:714:173f:7e6b with SMTP id d2e1a72fcca58-71936a3abdemr33203832b3a.2.1726758380769; Thu, 19 Sep 2024 08:06:20 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944adfd3dsm8620841b3a.92.2024.09.19.08.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 08:06:20 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Dmitry Kozlyuk , =?UTF-8?q?Morten=20Br=C3=B8rup?= , Bruce Richardson , Chengwen Feng Subject: [PATCH v25 02/15] windows: make getopt functions have const properties Date: Thu, 19 Sep 2024 08:04:08 -0700 Message-ID: <20240919150609.5281-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240919150609.5281-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240919150609.5281-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 Acked-by: Morten Brørup Acked-by: Bruce Richardson Acked-by: Chengwen Feng --- 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 #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 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.45.2