Esempio n. 1
0
char *core_fgets(char *s, int n, core_file *file)
{
	char *cur = s;

	/* loop while we have characters */
	while (n > 0)
	{
		int c = core_fgetc(file);
		if (c == EOF)
			break;

		/* if there's a CR, look for an LF afterwards */
		if (c == 0x0d)
		{
			int c2 = core_fgetc(file);
			if (c2 != 0x0a)
				core_ungetc(c2, file);
			*cur++ = 0x0d;
			n--;
			break;
		}

		/* if there's an LF, reinterp as a CR for consistency */
		else if (c == 0x0a)
		{
			*cur++ = 0x0d;
			n--;
			break;
		}

		/* otherwise, pop the character in and continue */
		*cur++ = c;
		n--;
	}

	/* if we put nothing in, return NULL */
	if (cur == s)
		return NULL;

	/* otherwise, terminate */
	if (n > 0)
		*cur++ = 0;
	return s;
}
Esempio n. 2
0
int emu_file::getc()
{
    // load the ZIP file now if we haven't yet
    if (compressed_file_ready())
        return EOF;

    // read the data if we can
    if (m_file != NULL)
        return core_fgetc(m_file);

    return EOF;
}
Esempio n. 3
0
int emu_file::getc()
{
	// load the ZIP file now if we haven't yet
	if (m_zipfile != NULL && load_zipped_file() != FILERR_NONE)
		return EOF;

	// read the data if we can
	if (m_file != NULL)
		return core_fgetc(m_file);

	return EOF;
}