31#include "io_private.h"
41static IOFileRef raw_posix_open(
const char *path,
int mode);
42static int raw_posix_close(IOFileRef f);
43static int raw_posix_seek(IOFileRef f, off_t offset,
int whence);
44static int raw_posix_read(IOFileRef f,
void *buf,
size_t count);
45static off_t raw_posix_filesize(IOFileRef f);
46static void *raw_posix_mmap(IOFileRef f,
size_t length, off_t offset);
47static int raw_posix_munmap(IOFileRef f,
void *addr,
size_t length);
62static IOFileRef raw_posix_open(
const char *path,
int mode)
66 IOFileRef f = (IOFileRef)malloc(
sizeof(
struct _IOFile));
68 memset(f, 0,
sizeof(
struct _IOFile));
73 f->
path = strdup(path);
74 data->
fd = open(path, mode);
88static int raw_posix_close(IOFileRef f)
93 retval = close(data->
fd);
101static int raw_posix_seek(IOFileRef f, off_t offset,
int whence)
106 retval = lseek(data->
fd, offset, whence);
118static int raw_posix_read(IOFileRef f,
void *buf,
size_t count)
123 retval = read(data->
fd, buf, count);
134static off_t raw_posix_filesize(IOFileRef f)
140 if(fstat(data->
fd, &sb) >= 0) {
149static void *raw_posix_mmap(IOFileRef f,
size_t length, off_t offset)
153 return mmap(NULL, length, PROT_READ, MAP_SHARED, data->
fd, offset);
157static int raw_posix_munmap(IOFileRef f,
void *addr,
size_t length)
160 return munmap(addr, length);
struct io_methods * methods