source: lib/libtraceio-stdio.c @ 114b8d6

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

Merge windows portability fixes

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