mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 18:47:22 +00:00
add str2val() and min() helpers
This commit is contained in:
parent
a21bc00e1c
commit
68a27c2067
@ -44,6 +44,7 @@ struct valstr {
|
||||
const char * str;
|
||||
};
|
||||
const char * val2str(unsigned short val, const struct valstr * vs);
|
||||
unsigned short str2val(const char * str, const struct valstr * vs);
|
||||
|
||||
unsigned short buf2short(unsigned char * buf);
|
||||
uint32_t buf2long(unsigned char * buf);
|
||||
@ -56,5 +57,7 @@ void signal_handler(int sig, void * handler);
|
||||
#define SIG_DEFAULT(s) ((void)signal((s), SIG_DFL))
|
||||
#define SIG_HANDLE(s,h) ((void)signal_handler((s), (h)))
|
||||
|
||||
#define min(a, b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
#endif /* IPMI_HELPER_H */
|
||||
|
||||
|
@ -38,10 +38,8 @@
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <signal.h>
|
||||
#include <ipmitool/helper.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <ipmitool/helper.h>
|
||||
|
||||
uint32_t buf2long(unsigned char * buf)
|
||||
{
|
||||
@ -104,6 +102,19 @@ const char * val2str(unsigned short val, const struct valstr *vs)
|
||||
return un_str;
|
||||
}
|
||||
|
||||
unsigned short str2val(const char *str, const struct valstr *vs)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (vs[i].str) {
|
||||
if (!strncasecmp(vs[i].str, str, strlen(str)))
|
||||
return vs[i].val;
|
||||
i++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void signal_handler(int sig, void * handler)
|
||||
{
|
||||
struct sigaction act;
|
||||
@ -125,4 +136,3 @@ void signal_handler(int sig, void * handler)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user