4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change
on this file since 15e9390 was
c66068d,
checked in by Perry Lorier <perry@…>, 12 years ago
|
Rewrite the libtrace io subsystem to use the new wandio abstraction layer.
|
-
Property mode set to
100644
|
File size:
922 bytes
|
Line | |
---|
1 | #include "wandio.h" |
---|
2 | #include <sys/types.h> |
---|
3 | #include <sys/stat.h> |
---|
4 | #include <fcntl.h> |
---|
5 | #include <stdlib.h> |
---|
6 | #include <unistd.h> |
---|
7 | #include <string.h> |
---|
8 | |
---|
9 | struct stdiow_t { |
---|
10 | int fd; |
---|
11 | }; |
---|
12 | |
---|
13 | extern iow_source_t stdio_wsource; |
---|
14 | |
---|
15 | #define DATA(iow) ((struct stdiow_t *)((iow)->data)) |
---|
16 | |
---|
17 | iow_t *stdio_wopen(const char *filename) |
---|
18 | { |
---|
19 | iow_t *iow = malloc(sizeof(iow_t)); |
---|
20 | iow->source = &stdio_wsource; |
---|
21 | iow->data = malloc(sizeof(struct stdiow_t)); |
---|
22 | |
---|
23 | if (strcmp(filename,"-") == 0) |
---|
24 | DATA(iow)->fd = 1; /* STDOUT */ |
---|
25 | else |
---|
26 | DATA(iow)->fd = open(filename,O_WRONLY|O_CREAT|O_TRUNC,0666); |
---|
27 | |
---|
28 | if (DATA(iow)->fd == -1) { |
---|
29 | free(iow); |
---|
30 | return NULL; |
---|
31 | } |
---|
32 | |
---|
33 | return iow; |
---|
34 | } |
---|
35 | |
---|
36 | static off_t stdio_wwrite(iow_t *iow, const char *buffer, off_t len) |
---|
37 | { |
---|
38 | return write(DATA(iow)->fd,buffer,len); |
---|
39 | } |
---|
40 | |
---|
41 | static void stdio_wclose(iow_t *iow) |
---|
42 | { |
---|
43 | close(DATA(iow)->fd); |
---|
44 | free(iow->data); |
---|
45 | free(iow); |
---|
46 | } |
---|
47 | |
---|
48 | iow_source_t stdio_wsource = { |
---|
49 | "stdiow", |
---|
50 | stdio_wwrite, |
---|
51 | stdio_wclose |
---|
52 | }; |
---|
Note: See
TracBrowser
for help on using the repository browser.