#include "PalmType.h"

ULONG p_atol(PXCHAR pBuf, UCHAR iRadix)
{
	DCHAR iPos, iVal;
	DLONG iTotal;

	iTotal = 0;
	iPos = 0;
	do
	{
		iVal = pBuf[iPos];
		if (iVal >= '0' && iVal <= '9')
		{
			iVal -= '0';
		}
		else 
		{
			if (iRadix == 16)
			{
				if (iVal >= 'a' && iVal <= 'f')
				{
					iVal -= 'a' - 10;
				}
				else if (iVal >= 'A' && iVal <= 'F')
				{
					iVal -= 'A' - 10;
				}
				else
				{
					break;
				}
			}
			else
			{
				break;
			}
		}
		iTotal *= iRadix;
		iTotal += iVal;
		iPos ++;
	} while (1);
	return iTotal;
}
