source: lib/libtraceio-stdio.c @ edb18ce

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since edb18ce was edb18ce, checked in by Perry Lorier <perry@…>, 15 years ago

Rewrote libtrace's IO handling to use shim functions when needing to do
zlib io

  • Property mode set to 100644
File size: 1.0 KB
Line 
1#include "libtraceio.h"
2#include <sys/types.h> /* for ssize_t/off_t */
3#include <stdio.h>
4
5struct libtrace_io_t {
6        FILE *file;
7};
8
9ssize_t libtrace_io_read(libtrace_io_t *io, void *buf, size_t len)
10{
11        return fread(buf,len,1,io->file);
12}
13
14libtrace_io_t *libtrace_io_fdopen(int fd, const char *mode)
15{
16        libtrace_io_t *io = malloc(sizeof(libtrace_io_t));
17        io->file = fdopen(fd,mode);
18        return io;
19}
20
21libtrace_io_t *libtrace_io_open(const char *path, const char *mode)
22{
23        libtrace_io_t *io = malloc(sizeof(libtrace_io_t));
24        io->file = fopen(path,mode);
25        return io;
26}
27
28/* Technically close returns -1 on failure, but if the close fails, really
29 * what are you going to do about it?
30 */
31void libtrace_io_close(libtrace_io_t *io)
32{
33        fclose(io->file);
34        io->file=NULL;
35        free(io);
36}
37
38ssize_t libtrace_io_write(libtrace_io_t *io, const void *buf, size_t len)
39{
40        return fwrite(buf,len,1,io->file);
41}
42
43off_t libtrace_io_seek(libtrace_io_t *io, off_t offset, int whence)
44{
45        return fseek(io->file,offset,whence);
46}
47
48ssize_t libtrace_io_tell(libtrace_io_t *io)
49{
50        return ftell(io->file);
51}
Note: See TracBrowser for help on using the repository browser.