avr-fw-modules/core/include/sys/fastfile.h

52 lines
1.1 KiB
C
Executable File

#pragma once
#include <sys/assert.h>
#include <sys/errno.h>
struct fastfile;
typedef struct fastfile fastfile_t;
struct fastfile {
int size;
struct {
int (*seek) (fastfile_t *ff,int position);
int (*tell) (fastfile_t *ff);
int (*read) (fastfile_t *ff,void *buffer,int len);
int (*write)(fastfile_t *ff,void *buffer,int len);
int (*close)(fastfile_t *ff);
} ops;
};
static inline int ff_seek(fastfile_t *ff,int position) {
if (!ff || !ff->ops.seek)
return -ENULLPTR;
return ff->ops.seek(ff,position);
};
static inline int ff_tell(fastfile_t *ff) {
if (!ff || !ff->ops.tell)
return -ENULLPTR;
return ff->ops.tell(ff);
};
static inline int ff_read(fastfile_t *ff,void *buffer,int len) {
if (!ff || !ff->ops.read)
return -ENULLPTR;
return ff->ops.read(ff,buffer,len);
};
static inline int ff_write(fastfile_t *ff,void *buffer,int len) {
if (!ff || !ff->ops.write)
return -ENULLPTR;
return ff->ops.write(ff,buffer,len);
};
static inline int ff_close(fastfile_t *ff) {
if (!ff || !ff->ops.close)
return -ENULLPTR;
return ff->ops.close(ff);
};