mirror of
https://github.com/pevans/erc-c.git
synced 2024-12-21 08:30:55 +00:00
Allow us to call objstore_init more than once.
This also separates some code into objstore_ready().
This commit is contained in:
parent
7182608473
commit
06d37d24d7
@ -1,6 +1,8 @@
|
||||
#ifndef _OBJSTORE_H_
|
||||
#define _OBJSTORE_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "apple2.mem.h"
|
||||
#include "vm_bits.h"
|
||||
|
||||
@ -12,6 +14,7 @@ typedef struct {
|
||||
} objstore;
|
||||
|
||||
extern int objstore_init();
|
||||
extern bool objstore_ready();
|
||||
|
||||
#define OBJSTORE_DECL(x) \
|
||||
const vm_8bit *objstore_##x()
|
||||
|
@ -27,7 +27,11 @@ static objstore store;
|
||||
int
|
||||
objstore_init()
|
||||
{
|
||||
int cmp;
|
||||
// Oh, you're calling this again? Cool, but let's bail before we do
|
||||
// anything else.
|
||||
if (objstore_ready()) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
// We want to input some bad header data and compare with what
|
||||
// eventually should get put into there by memcmp.
|
||||
@ -38,6 +42,20 @@ objstore_init()
|
||||
|
||||
memcpy(&store, store_data, sizeof(store));
|
||||
|
||||
// If the copy didn't work out somehow...
|
||||
if (!objstore_ready()) {
|
||||
log_critical("Object store initialization failed with bad data");
|
||||
return ERR_BADFILE;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
bool
|
||||
objstore_ready()
|
||||
{
|
||||
int cmp;
|
||||
|
||||
// Test if the header field data is exactly equivalent to that
|
||||
// defined in HEADER_DATA. Note we use memcmp(), because the header
|
||||
// field is an array of just 4 bytes; strcmp() and strncmp() have an
|
||||
@ -47,13 +65,7 @@ objstore_init()
|
||||
cmp = memcmp(store.header, HEADER_DATA,
|
||||
sizeof(store.header) / sizeof(char));
|
||||
|
||||
// If the two areas of memory were not a complete match...
|
||||
if (cmp != 0) {
|
||||
log_critical("Object store initialization failed with bad data");
|
||||
return ERR_BADFILE;
|
||||
}
|
||||
|
||||
return OK;
|
||||
return cmp == 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user