From 4e162a6fd7d0e1edda87cd3a2099ef8ffa9db978 Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Wed, 26 May 2004 21:59:06 +0000 Subject: [PATCH] load binary image from disk --- second/load.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ second/load.h | 7 +++++++ 2 files changed, 52 insertions(+) create mode 100644 second/load.c create mode 100644 second/load.h diff --git a/second/load.c b/second/load.c new file mode 100644 index 0000000..67aedf0 --- /dev/null +++ b/second/load.c @@ -0,0 +1,45 @@ +/* + * + * (c) 2004 Laurent Vivier + * + */ + +#include +#include +#include "glue.h" +#include "load.h" + +char* load_image(unsigned long offset, unsigned long size) +{ + int err; + char* image; + ParamBlockRec_t param_block; + + if (size == 0) + return NULL; + + image = malloc(size); + if (image == 0) + { + free(image); + return NULL; + } + + memset(¶m_block, 0, sizeof(param_block)); + + param_block.ioBuffer = (unsigned long)image; + param_block.ioVRefNum = 1; + param_block.ioRefNum = -5; + param_block.ioReqCount = size; + param_block.ioPosMode = fsFromStart; + param_block.ioPosOffset = offset; + + err = PBReadSync(¶m_block); + if (err != noErr) + { + free(image); + return NULL; + } + + return image; +} diff --git a/second/load.h b/second/load.h new file mode 100644 index 0000000..8a8a929 --- /dev/null +++ b/second/load.h @@ -0,0 +1,7 @@ +/* + * + * (c) 2004 Laurent Vivier + * + */ + +extern char* load_image(unsigned long offset, unsigned long size);