00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdlib.h>
00022 #include <errno.h>
00023
00024 #include "libopenraw/io.h"
00025 #include "io_private.h"
00026 #include "posix_io.h"
00027 #include "or_debug.h"
00028
00029 #ifdef __cplusplus
00030 extern "C" {
00031 #endif
00032
00034 #define CHECK_PTR(p,r) \
00035 if(p == NULL) { return r; }
00036
00042 struct io_methods* get_default_io_methods(void)
00043 {
00044 return &posix_io_methods;
00045 }
00046
00052 IOFileRef raw_open(struct io_methods * methods, const char *path, int mode)
00053 {
00054 CHECK_PTR(methods, NULL);
00055 return methods->open(path, mode);
00056 }
00057
00067 int raw_close(IOFileRef f)
00068 {
00069 int retval;
00070 CHECK_PTR(f,-1);
00071 retval = f->methods->close(f);
00072 free(f);
00073 return retval;
00074 }
00075
00076
00084 int raw_seek(IOFileRef f, off_t offset, int whence)
00085 {
00086 CHECK_PTR(f,-1);
00087 return f->methods->seek(f, offset, whence);
00088 }
00089
00090
00098 int raw_read(IOFileRef f, void *buf, size_t count)
00099 {
00100 CHECK_PTR(f,-1);
00101 return f->methods->read(f, buf, count);
00102 }
00103
00104 off_t raw_filesize(IOFileRef f)
00105 {
00106 CHECK_PTR(f,0);
00107 return f->methods->filesize(f);
00108 }
00109
00110 void *raw_mmap(IOFileRef f, size_t l, off_t offset)
00111 {
00112 CHECK_PTR(f,NULL);
00113 return f->methods->mmap(f, l, offset);
00114 }
00115
00116
00117 int raw_munmap(IOFileRef f, void *addr, size_t l)
00118 {
00119 CHECK_PTR(f,-1);
00120 return f->methods->munmap(f, addr, l);
00121 }
00122
00123
00129 int raw_get_error(IOFileRef f)
00130 {
00131 CHECK_PTR(f,EFAULT);
00132 return f->error;
00133 }
00134
00135
00144 char *raw_get_path(IOFileRef f)
00145 {
00146 CHECK_PTR(f,NULL);
00147 return f->path;
00148 }
00149
00150
00151 #ifdef __cplusplus
00152 }
00153 #endif
00154