library/src/utility/BP-StringUtilities.cc
// Converts a string to a signed long (base10).  Stores result in store_value.
Converts a string to a signed long (base10).  Stores result in store_value.
Converts a string to a signed long ( base10 ) . Stores result in store_value .
BP_ERROR_T BP_StringToSignedLongBase10(char * str, size_t len, long * store_value)
{
	if(!str || !len)
		return ERR_FAILURE;
	if(!store_value)
		return ERR_FAILURE;
	if(!store_value)
		return ERR_FAILURE;
	if(str[0] == '-')
	{
		if(!BP_StringContainsOnlyNumericASCIIDigits(&str[1], len-1))
			return ERR_FAILURE;
	}
	else
	{
		if(!BP_StringContainsOnlyNumericASCIIDigits(str, len))
			return ERR_FAILURE;
	}
	if(str[0] == '0')
	   return ERR_FAILURE;
	errno = 0;
	long tmp_val = strtol(str, NULL, 10);
	if(errno == ERANGE || errno == EINVAL)
		return ERR_FAILURE;
	*store_value = tmp_val;
	return ERR_SUCCESS;
}
BP_ERROR_T BP_StringToSignedLongBase10 ( char * str , size_t len , long * store_value ) { if ( ! str || ! len ) return ERR_FAILURE ; if ( ! store_value ) return ERR_FAILURE ; if ( ! store_value ) return ERR_FAILURE ; if ( str [ 0 ] == ' ' ) { if ( ! BP_StringContainsOnlyNumericASCIIDigits ( & str [ 1 ] , len - 1 ) ) return ERR_FAILURE ; } else { if ( ! BP_StringContainsOnlyNumericASCIIDigits ( str , len ) ) return ERR_FAILURE ; } if ( str [ 0 ] == ' ' ) return ERR_FAILURE ; errno = 0 ; long tmp_val = strtol ( str , NULL , 10 ) ; if ( errno == ERANGE || errno == EINVAL ) return ERR_FAILURE ; * store_value = tmp_val ; return ERR_SUCCESS ; }
Converts a string to a signed long (base10).
Converts a string to a signed long ( base10 ) .
// run basic checks // if there is no where to put a result, exit failure // Run digit check on string. (offset check by one byte if it's a negative number) // check that string contains only numeric ascii digits (offset) // check that string contains only numeric ascii digits // check to ensure that the string doesn't start with zero // reset errno before strtol to catch ERANGE // set store value from pointer reference // set the storage var from the tmp value if conversion was successful // return indicating success