Preventing segment faults from occuring due to missing input files
This commit is contained in:
parent
2a12799d82
commit
37fc186cbc
|
@ -17,6 +17,7 @@
|
||||||
* Current
|
* Current
|
||||||
** Added
|
** Added
|
||||||
Incorporated High level prototypes into makefile
|
Incorporated High level prototypes into makefile
|
||||||
|
Added logic to catch non-existent input files and report a useful error message
|
||||||
|
|
||||||
** Changed
|
** Changed
|
||||||
Extended VPATH in makefile to shorten dependency names
|
Extended VPATH in makefile to shorten dependency names
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "vm.h"
|
#include "vm.h"
|
||||||
|
#include <sys/stat.h>
|
||||||
FILE* tape_01;
|
FILE* tape_01;
|
||||||
FILE* tape_02;
|
FILE* tape_02;
|
||||||
|
|
||||||
|
@ -161,13 +162,25 @@ uint32_t shift_register(uint32_t source, uint32_t amount, bool left, bool zero)
|
||||||
|
|
||||||
void vm_FOPEN_READ(struct lilith* vm)
|
void vm_FOPEN_READ(struct lilith* vm)
|
||||||
{
|
{
|
||||||
|
struct stat sb;
|
||||||
|
|
||||||
if(0x00001100 == vm->reg[0])
|
if(0x00001100 == vm->reg[0])
|
||||||
{
|
{
|
||||||
|
if(-1 == stat(tape_01_name, &sb))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "File named %s does not exist\n", tape_01_name);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
tape_01 = fopen(tape_01_name, "r");
|
tape_01 = fopen(tape_01_name, "r");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0x00001101 == vm->reg[0])
|
if (0x00001101 == vm->reg[0])
|
||||||
{
|
{
|
||||||
|
if(-1 == stat(tape_02_name, &sb))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "File named %s does not exist\n", tape_02_name);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
tape_02 = fopen(tape_02_name, "r");
|
tape_02 = fopen(tape_02_name, "r");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue