mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 10:37:22 +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:
parent
232773d171
commit
bb1a4cc805
@ -38,6 +38,8 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
@ -327,8 +327,7 @@ pef_b2s_generic_ER[] __attribute__((unused)) = {
|
||||
&pef_b2s_gentype_11,
|
||||
&pef_b2s_gentype_12,
|
||||
};
|
||||
#define PEF_B2S_GENERIC_ER_ENTRIES \
|
||||
(sizeof(pef_b2s_generic_ER) / sizeof(pef_b2s_generic_ER[0]))
|
||||
#define PEF_B2S_GENERIC_ER_ENTRIES ARRAY_SIZE(pef_b2s_generic_ER)
|
||||
|
||||
#ifdef HAVE_PRAGMA_PACK
|
||||
#pragma pack(1)
|
||||
|
@ -898,6 +898,7 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru,
|
||||
uint8_t * fru_data;
|
||||
uint32_t fru_len, i;
|
||||
uint8_t tmp[2];
|
||||
size_t chassis_type;
|
||||
|
||||
fru_len = 0;
|
||||
|
||||
@ -931,10 +932,10 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru,
|
||||
*/
|
||||
i = 2;
|
||||
|
||||
printf(" Chassis Type : %s\n",
|
||||
chassis_type_desc[fru_data[i] >
|
||||
(sizeof(chassis_type_desc)/sizeof(chassis_type_desc[0])) - 1 ?
|
||||
2 : fru_data[i]]);
|
||||
chassis_type = (fru_data[i] > ARRAY_SIZE(chassis_type_desc) - 1)
|
||||
? 2
|
||||
: fru_data[i];
|
||||
printf(" Chassis Type : %s\n", chassis_type_desc[chassis_type]);
|
||||
|
||||
i++;
|
||||
|
||||
|
@ -1027,9 +1027,7 @@ static void lanp_print_usage(int cmd)
|
||||
printf("\n available parameters:\n");
|
||||
/* 'save' shall use 'write' filter, since it outputs a block
|
||||
* of 'set's */
|
||||
ipmi_cfgp_usage(lan_cfgp,
|
||||
sizeof(lan_cfgp)/sizeof(lan_cfgp[0]),
|
||||
cmd != LANP_CMD_PRINT);
|
||||
ipmi_cfgp_usage(lan_cfgp, ARRAY_SIZE(lan_cfgp), cmd != LANP_CMD_PRINT);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1161,8 +1159,8 @@ ipmi_lan6_main(struct ipmi_intf *intf, int argc, char **argv)
|
||||
*/
|
||||
|
||||
ipmi_cfgp_init(&ctx, lan_cfgp,
|
||||
sizeof(lan_cfgp)/sizeof(lan_cfgp[0]), "lan6 set nolock",
|
||||
lanp_ip6_cfgp, &lp);
|
||||
ARRAY_SIZE(lan_cfgp), "lan6 set nolock",
|
||||
lanp_ip6_cfgp, &lp);
|
||||
|
||||
ret = ipmi_cfgp_parse_sel(&ctx, argc, (const char **)argv, &sel);
|
||||
if (ret == -1) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user