mirror of
https://github.com/vivier/EMILE.git
synced 2024-09-08 04:54:25 +00:00
Add libstream-like interface
This commit is contained in:
parent
8a104ca7ca
commit
bce8a698c5
@ -8,28 +8,35 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "device.h"
|
||||||
|
|
||||||
#define SECTOR_SIZE (2048)
|
#define SECTOR_SIZE (2048)
|
||||||
#define ISO_BLOCKS(X) (((X) / SECTOR_SIZE) + (((X)%SECTOR_SIZE)?1:0))
|
#define ISO_BLOCKS(X) (((X) / SECTOR_SIZE) + (((X)%SECTOR_SIZE)?1:0))
|
||||||
|
|
||||||
static const char *filename = "/dev/cdrom";
|
static const char *filename = "/dev/cdrom";
|
||||||
static FILE *infile = NULL;
|
|
||||||
|
|
||||||
int device_open(void)
|
int device_read_sector(void *data,off_t offset, void* buffer, size_t size)
|
||||||
{
|
{
|
||||||
infile = fopen(filename, "rb");
|
FILE* file = (FILE*)data;
|
||||||
if (infile == NULL)
|
|
||||||
return -1;
|
lseek(fileno(file), offset << 11, SEEK_SET);
|
||||||
return 0;
|
return read(fileno(file), buffer, ISO_BLOCKS(size) << 11);
|
||||||
}
|
}
|
||||||
|
|
||||||
void device_close(void)
|
void device_close(void *data)
|
||||||
{
|
{
|
||||||
if (infile)
|
FILE* file = (FILE*)data;
|
||||||
fclose(infile);
|
if (file)
|
||||||
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void device_read(off_t offset, void* buffer, size_t size)
|
FILE *device_open(void)
|
||||||
{
|
{
|
||||||
lseek(fileno(infile), offset << 11, SEEK_SET);
|
FILE* file;
|
||||||
read(fileno(infile), buffer, ISO_BLOCKS(size) << 11);
|
|
||||||
|
file = fopen(filename, "rb");
|
||||||
|
if (file == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return file;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
extern int device_open(void);
|
#include <libstream.h>
|
||||||
extern void device_close(void);
|
|
||||||
extern void device_read(off_t offset, void* buffer, size_t size);
|
extern FILE *device_open(void);
|
||||||
|
extern void device_close(void *data);
|
||||||
|
extern int device_read_sector(void *data, off_t offset, void* buffer, size_t size);
|
||||||
|
Loading…
Reference in New Issue
Block a user