From: Jean Delvare <jdelvare@suse.de>
To: Linux I2C <linux-i2c@vger.kernel.org>
Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>
Subject: [PATCH v2] i2ctransfer: Drop redundant variable arg_idx
Date: Thu, 12 Sep 2024 14:45:04 +0200 [thread overview]
Message-ID: <20240912144504.278d302b@endymion.delvare> (raw)
arg_idx has the same meaning as getopt's optind global variable, so
drop the former and use the latter. Once getopt() is done parsing the
options, there should be no problem using it for ourselves.
Signed-off-by: Jean Delvare <jdelvare@suse.de>
---
Changes since v1:
* Rebased to make it apply again.
* Fixed typo in my SOB.
tools/i2ctransfer.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
--- i2c-tools.orig/tools/i2ctransfer.c
+++ i2c-tools/tools/i2ctransfer.c
@@ -143,7 +143,7 @@ static int confirm(const char *filename,
int main(int argc, char *argv[])
{
char filename[20];
- int i2cbus, address = -1, file, opt, arg_idx, nmsgs = 0, nmsgs_sent, i;
+ int i2cbus, address = -1, file, opt, nmsgs = 0, nmsgs_sent, i;
int force = 0, yes = 0, version = 0, verbose = 0, all_addrs = 0, binary = 0;
struct i2c_msg msgs[I2C_RDRW_IOCTL_MAX_MSGS];
enum parse_state state = PARSE_GET_DESC;
@@ -173,13 +173,12 @@ int main(int argc, char *argv[])
exit(0);
}
- arg_idx = optind;
- if (arg_idx == argc) {
+ if (optind == argc) {
help();
exit(1);
}
- i2cbus = lookup_i2c_bus(argv[arg_idx++]);
+ i2cbus = lookup_i2c_bus(argv[optind++]);
if (i2cbus < 0)
exit(1);
@@ -187,8 +186,8 @@ int main(int argc, char *argv[])
if (file < 0 || check_funcs(file))
exit(1);
- while (arg_idx < argc) {
- char *arg_ptr = argv[arg_idx];
+ while (optind < argc) {
+ char *arg_ptr = argv[optind];
unsigned long len, raw_data;
__u16 flags;
__u8 data, *buf;
@@ -323,7 +322,7 @@ int main(int argc, char *argv[])
goto err_out;
}
- arg_idx++;
+ optind++;
}
if (state != PARSE_GET_DESC || nmsgs == 0) {
@@ -361,7 +360,7 @@ int main(int argc, char *argv[])
exit(0);
err_out_with_arg:
- fprintf(stderr, "Error: faulty argument is '%s'\n", argv[arg_idx]);
+ fprintf(stderr, "Error: faulty argument is '%s'\n", argv[optind]);
err_out:
close(file);
--
Jean Delvare
SUSE L3 Support
next reply other threads:[~2024-09-12 12:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-12 12:45 Jean Delvare [this message]
2024-09-12 18:51 ` [PATCH v2] i2ctransfer: Drop redundant variable arg_idx Wolfram Sang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240912144504.278d302b@endymion.delvare \
--to=jdelvare@suse.de \
--cc=linux-i2c@vger.kernel.org \
--cc=wsa+renesas@sang-engineering.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox