utils: use strtol instead of atoi

HEX format is friendly to iSCSI utils, for example:
./iscsi-inq -e 0x1 -c 0xb1 iscsi://...

atoi supports decimal only, this example does not work.
Use strtol(nptr, NULL, 0) to auto-detect format, then this works fine.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
This commit is contained in:
zhenwei pi
2023-07-07 09:51:37 +08:00
committed by Bart Van Assche
parent 9ca47316f4
commit 6e2c677553
4 changed files with 9 additions and 9 deletions

View File

@@ -260,16 +260,16 @@ int main(int argc, char *argv[])
show_usage = 1; show_usage = 1;
break; break;
case 'd': case 'd':
debug = atoi(optarg); debug = strtol(optarg, NULL, 0);
break; break;
case 'i': case 'i':
initiator = optarg; initiator = optarg;
break; break;
case 'e': case 'e':
evpd = atoi(optarg); evpd = strtol(optarg, NULL, 0);
break; break;
case 'c': case 'c':
pagecode = atoi(optarg); pagecode = strtol(optarg, NULL, 0);
break; break;
default: default:
fprintf(stderr, "Unrecognized option '%c'\n\n", c); fprintf(stderr, "Unrecognized option '%c'\n\n", c);

View File

@@ -287,13 +287,13 @@ int main(int argc, char *argv[])
initiator = optarg; initiator = optarg;
break; break;
case 'm': case 'm':
max_in_flight = atoi(optarg); max_in_flight = strtol(optarg, NULL, 0);
break; break;
case 't': case 't':
runtime = atoi(optarg); runtime = strtol(optarg, NULL, 0);
break; break;
case 'b': case 'b':
blocks_per_io = atoi(optarg); blocks_per_io = strtol(optarg, NULL, 0);
break; break;
case 'n': case 'n':
client.ignore_errors = 1; client.ignore_errors = 1;
@@ -308,7 +308,7 @@ int main(int argc, char *argv[])
logging = 1; logging = 1;
break; break;
case 'x': case 'x':
client.max_reconnects = atoi(optarg); client.max_reconnects = strtol(optarg, NULL, 0);
break; break;
case 'h': case 'h':
usage(); usage();

View File

@@ -338,7 +338,7 @@ int main(int argc, char *argv[])
break; break;
case 'T': case 'T':
type = atoi(optarg); type = strtol(optarg, NULL, 0);
break; break;
case 'G': case 'G':

View File

@@ -93,7 +93,7 @@ int main(int argc, char *argv[])
show_usage = 1; show_usage = 1;
break; break;
case 'd': case 'd':
debug = atoi(optarg); debug = strtol(optarg, NULL, 0);
break; break;
case 'i': case 'i':
initiator = optarg; initiator = optarg;