load binary image from disk

This commit is contained in:
Laurent Vivier 2004-05-26 21:59:06 +00:00
parent c680062e0c
commit 4e162a6fd7
2 changed files with 52 additions and 0 deletions

45
second/load.c Normal file
View File

@ -0,0 +1,45 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include <stdio.h>
#include <malloc.h>
#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(&param_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(&param_block);
if (err != noErr)
{
free(image);
return NULL;
}
return image;
}

7
second/load.h Normal file
View File

@ -0,0 +1,7 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
extern char* load_image(unsigned long offset, unsigned long size);