mc: watchdog set: Refactor to reduce complexity

Move option parsing for `mc wathdog set` to a separate
function, add a function for host to ipmi integer
conversion (reduce manual byte juggling).
This commit is contained in:
Alexander Amelkin
2018-06-17 12:38:05 +03:00
parent e49a20eece
commit e8e94d8976
2 changed files with 75 additions and 55 deletions

View File

@@ -111,8 +111,8 @@ uint16_t ipmi_get_oem_id(struct ipmi_intf *intf);
#define IS_SET(v, b) ((v) & (1 << (b)))
/* le16toh() doesn't exist for Windows or Apple */
/* For portability, let's simply define our own version of it here */
/* le16toh(), hto16le(), et. al. don't exist for Windows or Apple */
/* For portability, let's simply define our own versions here */
static inline uint16_t ipmi16toh(uint16_t le)
{
uint8_t *data = (uint8_t *)&le;
@@ -124,6 +124,12 @@ static inline uint16_t ipmi16toh(uint16_t le)
return h;
}
static inline void htoipmi16(uint16_t h, uint8_t *ipmi)
{
ipmi[0] = h & 0xFF; /* LSB */
ipmi[1] = h >> 8; /* MSB */
}
#define ipmi_open_file_read(file) ipmi_open_file(file, 0)
#define ipmi_open_file_write(file) ipmi_open_file(file, 1)