Exemplo n.º 1
0
		int CoreIOReader::ReadLine(char *_buffer, size_t _bufferLength)
		{
			CoreAssert(this != NULL);
			if (!IsOpen()) return CC_ERR_INVALID_BUFFER;
			if (!_buffer) return CC_ERR_INVALID_BUFFER;
			if (!_bufferLength) return CC_ERR_INVALID_BUFFER;

#ifndef __GNUC__
			MutexHolder mh(&m_ioMutex);
#endif

			/* We use fgets because it detects line endings. */
			_buffer[0] = '\x0';
			char *ret = fgets(_buffer, (int)_bufferLength, m_fileInputPointer);
			if (ret != _buffer)
				return -1;

			/* Detect line endings. */
			char *endl = NULL;
			char *cr = strchr(_buffer, '\r');
			char *lf = strchr(_buffer, '\n');
			char *crlf = strstr(_buffer, "\r\n");
			if (crlf) {
				SetLineEndings(CC_LN_CRLF); endl = crlf;
			} else if (cr) {
				SetLineEndings(CC_LN_CR); endl = cr;
			} else if (lf) {
				SetLineEndings(CC_LN_LF); endl = lf;
			}

			if (endl)
				*endl = '\x0';

			return (int)strlen(_buffer);
		}
Exemplo n.º 2
0
		CoreIOWriter::CoreIOWriter(FILE * _fileBuffer, bool _isUnicode, LineEndingType _lnEnding, Endian _outputEndianness)
		: m_fileOutputPointer(_fileBuffer),
		  m_unicode(_isUnicode)
		{
			SetLineEndings(_lnEnding);
			SetEndian(_outputEndianness);
		}