libopenraw  0.3.7
io.h
1 /*
2  * libopenraw - io.h
3  *
4  * Copyright (C) 2005-2020 Hubert Figuière
5  *
6  * This library is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3 of
9  * the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef LIBOPENRAW_IO_H_
22 #define LIBOPENRAW_IO_H_
23 
24 #include <sys/types.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
45 typedef struct _IOFile *IOFileRef;
46 
51 struct io_methods {
55  IOFileRef (*open)(const char *path, int mode);
57  int (*close) (IOFileRef f);
59  int (*seek) (IOFileRef f, off_t offset, int whence);
61  int (*read) (IOFileRef f, void *buf, size_t count);
62 
64  off_t (*filesize) (IOFileRef f);
66  void* (*mmap) (IOFileRef f, size_t l, off_t offset);
68  int (*munmap) (IOFileRef f, void *addr, size_t l);
69 };
70 
83 extern struct io_methods* get_default_io_methods(void);
84 
92 extern IOFileRef raw_open(struct io_methods * methods, const char *path,
93  int mode);
94 extern int raw_close(IOFileRef f);
95 extern int raw_seek(IOFileRef f, off_t offset, int whence);
96 extern int raw_read(IOFileRef f, void *buf, size_t count);
97 extern off_t raw_filesize(IOFileRef f);
98 extern void *raw_mmap(IOFileRef f, size_t l, off_t offset);
99 extern int raw_munmap(IOFileRef f, void *addr, size_t l);
100 
101 extern int raw_get_error(IOFileRef f);
102 extern char *raw_get_path(IOFileRef f);
103 
106 #ifdef __cplusplus
107 }
108 #endif
109 
112 #endif
struct _IOFile * IOFileRef
A file reference.
Definition: io.h:45
IOFileRef raw_open(struct io_methods *methods, const char *path, int mode)
Raw open function.
Definition: io.c:49
int raw_close(IOFileRef f)
Definition: io.c:64
int raw_get_error(IOFileRef f)
Definition: io.c:126
char * raw_get_path(IOFileRef f)
Definition: io.c:141
struct io_methods * get_default_io_methods(void)
Get the default IO methods.
Definition: io.c:39
int raw_seek(IOFileRef f, off_t offset, int whence)
Definition: io.c:81
int raw_read(IOFileRef f, void *buf, size_t count)
Definition: io.c:95
IO methods for the IO subsystem.
Definition: io.h:51
off_t(* filesize)(IOFileRef f)
filesize method
Definition: io.h:64
int(* seek)(IOFileRef f, off_t offset, int whence)
seek in the file
Definition: io.h:59
IOFileRef(* open)(const char *path, int mode)
open method
Definition: io.h:55
int(* close)(IOFileRef f)
close method
Definition: io.h:57
int(* read)(IOFileRef f, void *buf, size_t count)
read method
Definition: io.h:61
int(* munmap)(IOFileRef f, void *addr, size_t l)
munmap method
Definition: io.h:68