Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions include/libchdr/chd.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ extern "C" {
/* A/V laserdisc frame metadata */
#define AV_LD_METADATA_TAG CHD_MAKE_TAG('A','V','L','D')

/* DVD metadata */
#define DVD_METADATA_TAG CHD_MAKE_TAG('D','V','D',' ')

/* CHD open values */
#define CHD_OPEN_READ 1
#define CHD_OPEN_READWRITE 2
Expand Down Expand Up @@ -375,7 +378,8 @@ struct _chd_verify_result
/* chd_error chd_create_file(core_file *file, uint64_t logicalbytes, uint32_t hunkbytes, uint32_t compression, chd_file *parent); */

/* open an existing CHD file */
CHD_EXPORT chd_error chd_open_core_file(core_file *file, int mode, chd_file *parent, chd_file **chd);
CHD_EXPORT chd_error chd_open_core_file_callbacks(const core_file_callbacks *callbacks, const void *user_data, int mode, chd_file *parent, chd_file **chd);
CHD_EXPORT chd_error chd_open_core_file(core_file *file, int mode, chd_file *parent, chd_file **chd); /* Legacy; use chd_open_core_file_callbacks instead! */
CHD_EXPORT chd_error chd_open_file(FILE *file, int mode, chd_file *parent, chd_file **chd);
CHD_EXPORT chd_error chd_open(const char *filename, int mode, chd_file *parent, chd_file **chd);

Expand All @@ -399,7 +403,8 @@ CHD_EXPORT const char *chd_error_string(chd_error err);
CHD_EXPORT const chd_header *chd_get_header(chd_file *chd);

/* read CHD header data from file into the pointed struct */
CHD_EXPORT chd_error chd_read_header_core_file(core_file *file, chd_header *header);
CHD_EXPORT chd_error chd_read_header_core_file_callbacks(const core_file_callbacks *callback, const void *user_data, chd_header *header);
CHD_EXPORT chd_error chd_read_header_core_file(core_file *file, chd_header *header); /* Legacy; use chd_read_header_core_file_callbacks instead! */
CHD_EXPORT chd_error chd_read_header_file(FILE *file, chd_header *header);
CHD_EXPORT chd_error chd_read_header(const char *filename, chd_header *header);

Expand Down
52 changes: 34 additions & 18 deletions include/libchdr/coretypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
#endif

typedef struct chd_core_file {
/*
* arbitrary pointer to data the implementation uses to implement the below functions
*/
void *argp;

typedef struct chd_core_file_callbacks {
/*
* return the size of a given file as a 64-bit unsigned integer.
* the position of the file pointer after calling this function is
Expand All @@ -30,36 +25,57 @@ typedef struct chd_core_file {
*
* on error, (uint64_t)-1 is returned.
*/
uint64_t(*fsize)(struct chd_core_file*);
uint64_t(*fsize)(void*);

/*
* should match the behavior of fread, except the FILE* argument at the end
* will be replaced with a struct chd_core_file*.
* will be replaced with a void*.
*/
size_t(*fread)(void*,size_t,size_t,struct chd_core_file*);
size_t(*fread)(void*,size_t,size_t,void*);

// closes the given file.
int (*fclose)(struct chd_core_file*);
int (*fclose)(void*);

// fseek clone
int (*fseek)(void*, int64_t, int);
} core_file_callbacks;

typedef struct chd_core_file_callbacks_and_argp {
const core_file_callbacks *callbacks;

/*
* arbitrary pointer to data the implementation uses to implement the above functions
*/
void *argp;
} core_file_callbacks_and_argp;

/* Legacy API */

typedef struct chd_core_file {
void *argp;
uint64_t(*fsize)(struct chd_core_file*);
size_t(*fread)(void*,size_t,size_t,struct chd_core_file*);
int (*fclose)(struct chd_core_file*);
int (*fseek)(struct chd_core_file*, int64_t, int);
} core_file;

static inline int core_fclose(core_file *fp) {
return fp->fclose(fp);
/* File IO shortcuts */

static inline int core_fclose(const core_file_callbacks_and_argp *fp) {
return fp->callbacks->fclose(fp->argp);
}

static inline size_t core_fread(core_file *fp, void *ptr, size_t len) {
return fp->fread(ptr, 1, len, fp);
static inline size_t core_fread(const core_file_callbacks_and_argp *fp, void *ptr, size_t len) {
return fp->callbacks->fread(ptr, 1, len, fp->argp);
}

static inline int core_fseek(core_file* fp, int64_t offset, int whence) {
return fp->fseek(fp, offset, whence);
static inline int core_fseek(const core_file_callbacks_and_argp* fp, int64_t offset, int whence) {
return fp->callbacks->fseek(fp->argp, offset, whence);
}

static inline uint64_t core_fsize(core_file *fp)
static inline uint64_t core_fsize(const core_file_callbacks_and_argp *fp)
{
return fp->fsize(fp);
return fp->callbacks->fsize(fp->argp);
}

#endif
2 changes: 1 addition & 1 deletion src/libchdr_cdrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

cdrom.c

Generic MAME CD-ROM utilties - build IDE and SCSI CD-ROMs on top of this
Generic MAME CD-ROM utilities - build IDE and SCSI CD-ROMs on top of this

****************************************************************************

Expand Down
Loading