4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change
on this file since 222d8f5 was
222d8f5,
checked in by Perry Lorier <perry@…>, 16 years ago
|
More bug fixes, now erf works again properly
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | #include "libtraceio.h" |
---|
2 | #include <zlib.h> |
---|
3 | #include <stdlib.h> |
---|
4 | #include <errno.h> |
---|
5 | |
---|
6 | struct libtrace_io_t { |
---|
7 | gzFile *file; |
---|
8 | }; |
---|
9 | |
---|
10 | ssize_t libtrace_io_read(libtrace_io_t *io, void *buf, size_t len) |
---|
11 | { |
---|
12 | int err=gzread(io->file,buf,len); |
---|
13 | int err2=errno; |
---|
14 | if (err>=0) { |
---|
15 | return err; |
---|
16 | } |
---|
17 | switch(err) { |
---|
18 | case Z_STREAM_END: |
---|
19 | return 0; |
---|
20 | case Z_ERRNO: |
---|
21 | if (err2==0) |
---|
22 | return 0; /* EOF */ |
---|
23 | return -1; |
---|
24 | case Z_MEM_ERROR: errno=ENOMEM; return -1; |
---|
25 | default: |
---|
26 | /* Some decompression error or something */ |
---|
27 | errno=EINVAL; |
---|
28 | return -1; |
---|
29 | } |
---|
30 | } |
---|
31 | |
---|
32 | libtrace_io_t *libtrace_io_fdopen(int fd, const char *mode) |
---|
33 | { |
---|
34 | libtrace_io_t *io = malloc(sizeof(libtrace_io_t)); |
---|
35 | io->file = gzdopen(fd,mode); |
---|
36 | return io; |
---|
37 | } |
---|
38 | |
---|
39 | libtrace_io_t *libtrace_io_open(const char *path, const char *mode) |
---|
40 | { |
---|
41 | libtrace_io_t *io = malloc(sizeof(libtrace_io_t)); |
---|
42 | io->file = gzopen(path,mode); |
---|
43 | return io; |
---|
44 | } |
---|
45 | |
---|
46 | /* Technically close returns -1 on failure, but if the close fails, really |
---|
47 | * what are you going to do about it? |
---|
48 | */ |
---|
49 | void libtrace_io_close(libtrace_io_t *io) |
---|
50 | { |
---|
51 | gzclose(io->file); |
---|
52 | io->file=NULL; |
---|
53 | free(io); |
---|
54 | } |
---|
55 | |
---|
56 | ssize_t libtrace_io_write(libtrace_io_t *io, const void *buf, size_t len) |
---|
57 | { |
---|
58 | return gzwrite(io->file,buf,len); |
---|
59 | } |
---|
60 | |
---|
61 | off_t libtrace_io_seek(libtrace_io_t *io, off_t offset, int whence) |
---|
62 | { |
---|
63 | return gzseek(io->file,offset,whence); |
---|
64 | } |
---|
65 | |
---|
66 | ssize_t libtrace_io_tell(libtrace_io_t *io) |
---|
67 | { |
---|
68 | return gztell(io->file); |
---|
69 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.