mirror of
https://github.com/pevans/erc-c.git
synced 2025-07-17 14:24:22 +00:00
Write an fread function for segments; use in apple2.dd
This commit is contained in:
@@ -204,3 +204,25 @@ vm_segment_write_map(vm_segment *segment,
|
||||
segment->write_table[addr] = fn;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read the given file stream and write the contents into the given
|
||||
* segment, up to len bytes. If we could not read from the file stream
|
||||
* for some reason, signal that and return an error.
|
||||
*/
|
||||
int
|
||||
vm_segment_fread(vm_segment *segment, FILE *stream, size_t len)
|
||||
{
|
||||
fread(segment->memory, sizeof(vm_8bit), len, stream);
|
||||
|
||||
// fread() may return zero in the case of an error, but it may
|
||||
// return a positive non-zero number short of len; we can't quite
|
||||
// count on just that to tell us something went wrong (especially if
|
||||
// len was not a valid length for the file to begin with).
|
||||
if (ferror(stream)) {
|
||||
log_critical("Could not read file stream: %s\n", strerror(errno));
|
||||
return ERR_BADFILE;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
Reference in New Issue
Block a user