Esempio n. 1
0
File: base64.c Progetto: Anode1/nid
/*
 ** Decode source from Base64 encoded string into raw data
 **
 ** Returns: 0 - Success
 ** 1 - Error - Source underflow - need more base64 data
 ** 2 - Error - Chunk contains half a byte of data
 ** 3 - Error - Decoded results will overflow output buffer
 */
int decode(unsigned s_len, char *src, unsigned d_len, char *dst){
	unsigned six, dix;

	dix = 0;

	for (six = 0; six < s_len; six += 4){
		unsigned long sr;
		unsigned ix;

		sr = 0;
		for (ix = 0; ix < 4; ++ix)
		{
			int sextet;

			if (six+ix >= s_len)
				return 1;
			if ((sextet = tlu(*(src+six+ix))) < 0)
				break;
			sr <<= 6;
			sr |= (sextet & 0x3f);
		}

		switch (ix){
		case 0: /* end of data, no padding */
			return 0;

		case 1: /* can't happen */
			return 2;

		case 2: /* 1 result byte */
			sr >>= 4;
			if (dix > d_len) return 3;
			*(dst+dix) = (sr & 0xff);
			++dix;
			break;

		case 3: /* 2 result bytes */
			sr >>= 2;
			if (dix+1 > d_len) return 3;
			*(dst+dix+1) = (sr & 0xff);
			sr >>= 8;
			*(dst+dix) = (sr & 0xff);
			dix += 2;
			break;

		case 4: /* 3 result bytes */
			if (dix+2 > d_len) return 3;
			*(dst+dix+2) = (sr & 0xff);
			sr >>= 8;
			*(dst+dix+1) = (sr & 0xff);
			sr >>= 8;
			*(dst+dix) = (sr & 0xff);
			dix += 3;
			break;
		}
	}
	return 0;

}
/*!
 * This method converts rectangle widths and heights to device units while 
 * taking account rounding down errors.
 * This fixes off-by-1-pixel-bugs in Rectangle widths and heights.
 */
UT_sint32 GR_Graphics::_tduR(UT_sint32 layoutUnits) const
{
	UT_sint32 idh = tdu(layoutUnits);
	if(tlu(idh) < layoutUnits)
	{
		idh += 1;
	}
	return idh;
}