示例#1
0
		int CoreIOReader::ReadU16(uint16_t *_buffer)
		{
			CoreAssert(this != NULL);
			if (!IsOpen()) return CC_ERR_INVALID_BUFFER;
			if (!_buffer) return CC_ERR_INVALID_BUFFER;

#ifndef __GNUC__
			MutexHolder mh(&m_ioMutex);
#endif
			size_t retval;
			retval = fread(_buffer, sizeof(uint16_t), 1, m_fileInputPointer);

			switch (m_endianness)
			{
			case CC_ENDIAN_LITTLE:
				*_buffer = CC_SwapLE16(*_buffer);
				break;
			case CC_ENDIAN_BIG:
				*_buffer = CC_SwapBE16(*_buffer);
				break;
			case CC_ENDIAN_NATIVE:
				/* Do nothing */
				break;
			}

			return retval;
		}
示例#2
0
		int CoreIOWriter::WriteU16(cc_uint16_t _data)
		{
			CoreAssert(this != NULL);
			if (!IsOpen()) return 0;

#ifndef __GNUC__
			MutexHolder mh(&m_ioMutex);
#endif
			switch (m_endianness)
			{
			case CC_ENDIAN_LITTLE:
				_data = CC_SwapBE16(_data);
				break;
			case CC_ENDIAN_BIG:
				_data = CC_SwapLE16(_data);
				break;
			case CC_ENDIAN_NATIVE:
				/* Do nothing */
				break;
			}
			size_t ret = fwrite(&_data, sizeof(cc_uint16_t), 1, m_fileOutputPointer);

			return ret;
		}