mirror of
https://github.com/ipmitool/ipmitool.git
synced 2026-06-23 22:01:36 +00:00
Finalize refactoring of string comparisons
Unify the comparison idioms use. Always use `if(!strcmp())` for "if string equals" and `if(strcmp())` for "if string is not equal". Never use `== 0` and `!= 0` with `strcmp()`. Minor reformatting of the code immediately surrounding the refactored lines. Resolves ipmitool/ipmitool#104 Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
This commit is contained in:
committed by
Alexander Amelkin
parent
e3fc775d26
commit
956ae2b372
@@ -192,7 +192,7 @@ ipmi_event_intf_load(char * name)
|
||||
intf++)
|
||||
{
|
||||
i = *intf;
|
||||
if (strcmp(name, i->name) == 0) {
|
||||
if (!strcmp(name, i->name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -845,7 +845,7 @@ ipmievd_open_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
struct ipmi_event_intf * eintf;
|
||||
|
||||
/* only one interface works for this */
|
||||
if (strcmp(intf->name, "open") != 0) {
|
||||
if (strcmp(intf->name, "open")) {
|
||||
lprintf(LOG_ERR, "Invalid Interface for OpenIPMI Event Handler: %s", intf->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -125,14 +125,12 @@ int ipmi_shell_main(struct ipmi_intf *intf, int argc, char **argv)
|
||||
pbuf = NULL;
|
||||
continue;
|
||||
}
|
||||
if (strcmp(pbuf, "quit") == 0 ||
|
||||
strcmp(pbuf, "exit") == 0) {
|
||||
if (!strcmp(pbuf, "quit") || !strcmp(pbuf, "exit")) {
|
||||
free(pbuf);
|
||||
pbuf = NULL;
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(pbuf, "help") == 0 ||
|
||||
strcmp(pbuf, "?") == 0) {
|
||||
if (!strcmp(pbuf, "help") || !strcmp(pbuf, "?")) {
|
||||
ipmi_cmd_print(intf->cmdlist);
|
||||
free(pbuf);
|
||||
pbuf = NULL;
|
||||
@@ -258,13 +256,13 @@ ipmi_set_usage(void)
|
||||
|
||||
int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
{
|
||||
if (argc == 0 || strcmp(argv[0], "help") == 0) {
|
||||
if (!argc || !strcmp(argv[0], "help")) {
|
||||
ipmi_set_usage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* these options can have no arguments */
|
||||
if (strcmp(argv[0], "verbose") == 0) {
|
||||
if (!strcmp(argv[0], "verbose")) {
|
||||
if (argc > 1) {
|
||||
if (str2int(argv[1], &verbose) != 0) {
|
||||
lprintf(LOG_ERR,
|
||||
@@ -277,7 +275,7 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(argv[0], "csv") == 0) {
|
||||
if (!strcmp(argv[0], "csv")) {
|
||||
if (argc > 1) {
|
||||
if (str2int(argv[1], &csv_output) != 0) {
|
||||
lprintf(LOG_ERR,
|
||||
@@ -297,8 +295,8 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0], "host") == 0 ||
|
||||
strcmp(argv[0], "hostname") == 0) {
|
||||
if (!strcmp(argv[0], "host") ||
|
||||
!strcmp(argv[0], "hostname")) {
|
||||
ipmi_intf_session_set_hostname(intf, argv[1]);
|
||||
if (!intf->session) {
|
||||
lprintf(LOG_ERR, "Failed to set session hostname.");
|
||||
@@ -307,8 +305,8 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
printf("Set session hostname to %s\n",
|
||||
intf->ssn_params.hostname);
|
||||
}
|
||||
else if (strcmp(argv[0], "user") == 0 ||
|
||||
strcmp(argv[0], "username") == 0) {
|
||||
else if (!strcmp(argv[0], "user") ||
|
||||
!strcmp(argv[0], "username")) {
|
||||
ipmi_intf_session_set_username(intf, argv[1]);
|
||||
if (!intf->session) {
|
||||
lprintf(LOG_ERR, "Failed to set session username.");
|
||||
@@ -317,8 +315,8 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
printf("Set session username to %s\n",
|
||||
intf->ssn_params.username);
|
||||
}
|
||||
else if (strcmp(argv[0], "pass") == 0 ||
|
||||
strcmp(argv[0], "password") == 0) {
|
||||
else if (!strcmp(argv[0], "pass") ||
|
||||
!strcmp(argv[0], "password")) {
|
||||
ipmi_intf_session_set_password(intf, argv[1]);
|
||||
if (!intf->session) {
|
||||
lprintf(LOG_ERR, "Failed to set session password.");
|
||||
@@ -326,7 +324,7 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
}
|
||||
printf("Set session password\n");
|
||||
}
|
||||
else if (strcmp(argv[0], "authtype") == 0) {
|
||||
else if (!strcmp(argv[0], "authtype")) {
|
||||
int authtype;
|
||||
authtype = str2val(argv[1], ipmi_authtype_session_vals);
|
||||
if (authtype == 0xFF) {
|
||||
@@ -343,7 +341,7 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
val2str(intf->ssn_params.authtype_set,
|
||||
ipmi_authtype_session_vals));
|
||||
}
|
||||
else if (strcmp(argv[0], "privlvl") == 0) {
|
||||
else if (!strcmp(argv[0], "privlvl")) {
|
||||
int privlvl;
|
||||
privlvl = str2val(argv[1], ipmi_privlvl_vals);
|
||||
if (privlvl == 0xFF) {
|
||||
@@ -361,7 +359,7 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
val2str(intf->ssn_params.privlvl,
|
||||
ipmi_privlvl_vals));
|
||||
}
|
||||
else if (strcmp(argv[0], "port") == 0) {
|
||||
else if (!strcmp(argv[0], "port")) {
|
||||
int port = 0;
|
||||
if (str2int(argv[1], &port) != 0 || port > MAX_PORT) {
|
||||
lprintf(LOG_ERR, "Given port '%s' is invalid.",
|
||||
@@ -375,7 +373,7 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
}
|
||||
printf("Set session port to %d\n", intf->ssn_params.port);
|
||||
}
|
||||
else if (strcmp(argv[0], "localaddr") == 0) {
|
||||
else if (!strcmp(argv[0], "localaddr")) {
|
||||
uint8_t my_addr = 0;
|
||||
if (str2uchar(argv[1], &my_addr) != 0) {
|
||||
lprintf(LOG_ERR, "Given localaddr '%s' is invalid.",
|
||||
@@ -385,7 +383,7 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
intf->my_addr = my_addr;
|
||||
printf("Set local IPMB address to 0x%02x\n", intf->my_addr);
|
||||
}
|
||||
else if (strcmp(argv[0], "targetaddr") == 0) {
|
||||
else if (!strcmp(argv[0], "targetaddr")) {
|
||||
uint8_t target_addr = 0;
|
||||
if (str2uchar(argv[1], &target_addr) != 0) {
|
||||
lprintf(LOG_ERR, "Given targetaddr '%s' is invalid.",
|
||||
|
||||
@@ -167,9 +167,8 @@ void ipmi_intf_print(struct ipmi_intf_support * intflist)
|
||||
if (intflist) {
|
||||
found = 0;
|
||||
for (sup=intflist; sup->name; sup++) {
|
||||
if (strcmp(sup->name, (*intf)->name) == 0 &&
|
||||
strcmp(sup->name, (*intf)->name) == 0 &&
|
||||
sup->supported == 1)
|
||||
if (!strcmp(sup->name, (*intf)->name)
|
||||
&& sup->supported)
|
||||
found = 1;
|
||||
}
|
||||
if (found == 0)
|
||||
@@ -211,7 +210,7 @@ struct ipmi_intf * ipmi_intf_load(char * name)
|
||||
intf++)
|
||||
{
|
||||
i = *intf;
|
||||
if (strcmp(name, i->name) == 0) {
|
||||
if (!strcmp(name, i->name)) {
|
||||
if (i->setup && (i->setup(i) < 0)) {
|
||||
lprintf(LOG_ERR, "Unable to setup "
|
||||
"interface %s", name);
|
||||
|
||||
@@ -394,7 +394,7 @@ recv_response(struct ipmi_intf * intf, unsigned char *data, int len)
|
||||
*pp = 0;
|
||||
|
||||
/* was it an error? */
|
||||
if (strcmp(p, "ERR ") == 0) {
|
||||
if (!strcmp(p, "ERR ")) {
|
||||
serial_write_line(intf, "\r\r\r\r");
|
||||
sleep(1);
|
||||
serial_flush(intf);
|
||||
|
||||
@@ -133,7 +133,7 @@ scsiProbeNew(int *num_ami_devices, int *sg_nos)
|
||||
}
|
||||
|
||||
if (sscanf(linebuf, "%s", vendor) == 1) {
|
||||
if (strcmp(vendor, "AMI") == 0) {
|
||||
if (!strcmp(vendor, "AMI")) {
|
||||
numdevfound++;
|
||||
sg_nos[numdevfound - 1] = lineno;
|
||||
if (numdevfound == inplen) {
|
||||
@@ -249,7 +249,7 @@ IsG2Drive(int cd_desc)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strcmp(szSignature, "$$$AMI$$$") != 0) {
|
||||
if (strcmp(szSignature, "$$$AMI$$$")) {
|
||||
lprintf(LOG_ERR,
|
||||
"IsG2Drive:Signature mismatch when ID command sent");
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user