1 | /** @file |
---|
2 | * Internal IO compatibility shim |
---|
3 | */ |
---|
4 | #ifndef LIBTRACEIO_H |
---|
5 | #define LIBTRACEIO_H 1 |
---|
6 | #include "config.h" |
---|
7 | #ifndef WIN32 |
---|
8 | #include <inttypes.h> |
---|
9 | #include <unistd.h> |
---|
10 | #endif |
---|
11 | |
---|
12 | |
---|
13 | typedef struct libtrace_io_t libtrace_io_t; |
---|
14 | |
---|
15 | /** read a block from a file |
---|
16 | * @param io the io file object |
---|
17 | * @param buf the buffer to read into |
---|
18 | * @param len the number of bytes to read |
---|
19 | * |
---|
20 | * @returns -1 on error (with errno set), 0 on eof, otherwise the number of bytes |
---|
21 | * read. |
---|
22 | */ |
---|
23 | ssize_t libtrace_io_read(libtrace_io_t *io, void *buf, size_t len); |
---|
24 | /** open a file from a file descriptor (like fdopen(3)) |
---|
25 | * @param fd file descriptor to read |
---|
26 | * @param mode text string to represent what mode to read the file in. |
---|
27 | * |
---|
28 | * @returns io object, or NULL on error. |
---|
29 | */ |
---|
30 | libtrace_io_t *libtrace_io_fdopen(int fd, const char *mode); |
---|
31 | /** open a file from a path name |
---|
32 | * @param path pathname to read |
---|
33 | * @param mode text string to represent what mode to read the file in. |
---|
34 | * |
---|
35 | * @returns io object, or NULL on error. |
---|
36 | */ |
---|
37 | libtrace_io_t *libtrace_io_open(const char *path, const char *mode); |
---|
38 | /** close a file and free all of it's resources. |
---|
39 | * @param io io object |
---|
40 | * |
---|
41 | * This function doesn't return anything. In theory it could return an error |
---|
42 | * but seriously, if it did return an error, what would you do about it? |
---|
43 | */ |
---|
44 | void libtrace_io_close(libtrace_io_t *io); |
---|
45 | |
---|
46 | /** write a block of data to a file |
---|
47 | * @param io libtrace io object to write to |
---|
48 | * @param buf buffer to write to |
---|
49 | * @param len number of bytes to write |
---|
50 | * |
---|
51 | * @returns the number of bytes successfully written, or -1 on error with |
---|
52 | * errno set |
---|
53 | */ |
---|
54 | ssize_t libtrace_io_write(libtrace_io_t *io, const void *buf, size_t len); |
---|
55 | int64_t libtrace_io_seek(libtrace_io_t *io, int64_t offset, int whence); |
---|
56 | ssize_t libtrace_io_tell(libtrace_io_t *io); |
---|
57 | |
---|
58 | #endif |
---|