add str2val() and min() helpers

This commit is contained in:
Duncan Laurie 2004-04-15 20:24:35 +00:00
parent a21bc00e1c
commit 68a27c2067
2 changed files with 17 additions and 4 deletions

View File

@ -44,6 +44,7 @@ struct valstr {
const char * str; const char * str;
}; };
const char * val2str(unsigned short val, const struct valstr * vs); 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); unsigned short buf2short(unsigned char * buf);
uint32_t buf2long(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_DEFAULT(s) ((void)signal((s), SIG_DFL))
#define SIG_HANDLE(s,h) ((void)signal_handler((s), (h))) #define SIG_HANDLE(s,h) ((void)signal_handler((s), (h)))
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif /* IPMI_HELPER_H */ #endif /* IPMI_HELPER_H */

View File

@ -38,10 +38,8 @@
#include <stdio.h> #include <stdio.h>
#include <inttypes.h> #include <inttypes.h>
#include <signal.h> #include <signal.h>
#include <ipmitool/helper.h>
#include <string.h> #include <string.h>
#include <ipmitool/helper.h>
uint32_t buf2long(unsigned char * buf) uint32_t buf2long(unsigned char * buf)
{ {
@ -104,6 +102,19 @@ const char * val2str(unsigned short val, const struct valstr *vs)
return un_str; 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) void signal_handler(int sig, void * handler)
{ {
struct sigaction act; struct sigaction act;
@ -125,4 +136,3 @@ void signal_handler(int sig, void * handler)
return; return;
} }
} }