Index: lib/helper.c
===================================================================
RCS file: /cvsroot/ipmitool/ipmitool/lib/helper.c,v
retrieving revision 1.38
diff -c -r1.38 helper.c
*** lib/helper.c	21 Jan 2012 08:31:09 -0000	1.38
--- lib/helper.c	22 Jan 2012 17:36:21 -0000
***************
*** 35,40 ****
--- 35,41 ----
  #include <sys/ioctl.h>  /* For TIOCNOTTY */
  
  #include <stdlib.h>
+ #include <stdint.h>
  #include <stdio.h>
  #include <inttypes.h>
  #include <signal.h>
***************
*** 143,149 ****
--- 144,247 ----
  
  	return un_str;
  }
+ /* str2long - safely convert string to int32
+  *
+  * @str: source string to convert from
+  * @lout_ptr: pointer where to store result
+  *
+  * returns zero on success
+  * returns (-1) if one of args is NULL, (-2) invalid input, (-3) for *flow
+  */
+ int16_t str2long(const char * str, int32_t * lout_ptr)
+ {
+ 	char * end_ptr = 0;
+ 	if (!str || !lout_ptr)
+ 		return (-1);
+ 
+ 	*lout_ptr = 0;
+ 	errno = 0;
+ 	*lout_ptr = strtol(str, &end_ptr, 0);
+ 
+ 	if (end_ptr != '\0')
+ 		return (-2);
+ 
+ 	if (errno != 0)
+ 		return (-3);
+ 	
+ 	return 0;
+ } /* str2long(...) */
+ /* str2ulong - safely convert string to uint32
+  *
+  * @str: source string to convert from
+  * @ulout_ptr: pointer where to store result
+  *
+  * returns zero on success
+  * returns (-1) if one of args is NULL, (-2) invalid input, (-3) for *flow
+  */
+ int str2ulong(const char * str, uint32_t * ulout_ptr)
+ {
+ 	char * end_ptr = 0;
+ 	if (!str || !ulout_ptr)
+ 		return (-1);
+ 
+ 	*ulout_ptr = 0;
+ 	errno = 0;
+ 	*ulout_ptr = strtoul(str, &end_ptr, 0);
+ 
+ 	if (end_ptr != '\0')
+ 		return (-2);
+ 
+ 	if (errno != 0)
+ 		return (-3);
+ 
+ 	return 0;
+ } /* str2ulong(...) */
+ /* str2short - safely convert string to int16_t
+  *
+  * @str: source string to convert from
+  * @shrt_ptr: pointer where to store result
+  *
+  * returns zero on success
+  * returns (-1) if one of args is NULL, (-2) invalid input, (-3) for *flow
+  */
+ int str2short(const char * str, int16_t * shrt_ptr)
+ {
+ 	int rc = (-3);
+ 	int arg_long = 0;
+ 	if ( (rc = str2long(str, &arg_long)) ) {
+ 		*shrt_ptr = 0;
+ 		return rc;
+ 	}
+ 
+ 	if (arg_long < INT16_MIN || arg_long > INT16_MAX)
+ 		return (-3);
+ 
+ 	*shrt_ptr = (int16_t)arg_long;
+ 	return 0;
+ } /* str2short(...) */
+ /* str2uchar - safely convert string to uint8
+  *
+  * @str: source string to convert from
+  * @uchrout_ptr: pointer where to store result
+  *
+  * returns zero on success
+  * returns (-1) if one of args is NULL, (-2) or (-3) if conversion fails
+  */
+ int str2uchar(const char * str, uint8_t * uchrout_ptr)
+ {
+ 	int rc = (-3);
+ 	int arg_long = 0;
+ 	if ( (rc = str2ulong(str, &arg_long)) != 0 ) {
+ 		*uchrout_ptr = 0;
+ 		return rc;
+ 	}
+ 
+ 	if (arg_long > UINT8_MAX)
+ 		return (-3);
  
+ 	*uchrout_ptr = (uint8_t)arg_long;
+ 	return 0;
+ } /* str2uchar(...) */
  uint16_t str2val(const char *str, const struct valstr *vs)
  {
  	int i;
