I am writing an emulator that uses read() to load the contents of a file into an array:
Code:
int load_roms(unsigned char userom[])
{
	FILE *romfile; /* Create pointer to ROM file */
	romfile=fopen(userom,"r"); /* Load apple.rom read-only */
	if (!romfile) /* Check for problems opening the file */
	{
		printf("Cannot read %s \n", userom);
		return 1;
	}
	int errcheck = read(romfile, &memory[0xF000], 1024); 
	if(errcheck = -1)
	{
		printf("ROM-File read error \n");
	}
	else printf("Bytes Read: %i \n", errcheck);
	
	fclose(romfile); /*Close romfile */
	return 0;
}
Whenever I run it, however, read() returns -1! What am I doing wrong?