mirror of
https://github.com/ipmitool/ipmitool.git
synced 2026-06-24 06:11:36 +00:00
Refactoring. Improve code reuse ratio.
Add ARRAY_SIZE() macro. Use the new macro in all places where array size is calculated by means of sizeof(array)/sizeof(array[0]). Fix minor bugs and warnings in the affected code. Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
This commit is contained in:
@@ -241,12 +241,12 @@ serial_bm_open(struct ipmi_intf * intf)
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(rates) / sizeof(rates[0]); i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(rates); i++) {
|
||||
if (rates[i].baudrate == rate) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i >= sizeof(rates) / sizeof(rates[0])) {
|
||||
if (i >= ARRAY_SIZE(rates)) {
|
||||
lprintf(LOG_ERR, "Unsupported baud rate %i specified", rate);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ ipmi_serial_term_open(struct ipmi_intf * intf)
|
||||
struct termios ti;
|
||||
unsigned int rate = 9600;
|
||||
char *p;
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
if (!intf->devfile) {
|
||||
lprintf(LOG_ERR, "Serial device is not specified");
|
||||
@@ -188,12 +188,12 @@ ipmi_serial_term_open(struct ipmi_intf * intf)
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(rates) / sizeof(rates[0]); i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(rates); i++) {
|
||||
if (rates[i].baudrate == rate) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i >= sizeof(rates) / sizeof(rates[0])) {
|
||||
if (i >= ARRAY_SIZE(rates)) {
|
||||
lprintf(LOG_ERR, "Unsupported baud rate %i specified", rate);
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user