Linux I2C development
 help / color / mirror / Atom feed
* [PATCH] i2ctransfer: Drop redundant variable arg_idx
@ 2022-05-24  9:44 Jean Delvare
  0 siblings, 0 replies; only message in thread
From: Jean Delvare @ 2022-05-24  9:44 UTC (permalink / raw)
  To: Linux I2C; +Cc: Wolfram Sang

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.

Sigend-off-by: Jean Delvare <jdelvare@suse.de>
---
I can't easily test this, Wolfram can you please do it?

 tools/i2ctransfer.c |   15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

--- i2c-tools.orig/tools/i2ctransfer.c	2022-05-24 11:34:48.901029181 +0200
+++ i2c-tools/tools/i2ctransfer.c	2022-05-24 11:38:35.637104513 +0200
@@ -131,7 +131,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;
 	struct i2c_msg msgs[I2C_RDRW_IOCTL_MAX_MSGS];
 	enum parse_state state = PARSE_GET_DESC;
@@ -160,13 +160,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);
 
@@ -174,8 +173,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;
@@ -310,7 +309,7 @@ int main(int argc, char *argv[])
 			goto err_out;
 		}
 
-		arg_idx++;
+		optind++;
 	}
 
 	if (state != PARSE_GET_DESC || nmsgs == 0) {
@@ -342,7 +341,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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-24  9:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-24  9:44 [PATCH] i2ctransfer: Drop redundant variable arg_idx Jean Delvare

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox