Changeset 641dc7c for lib/format_wag.c
- Timestamp:
- 10/14/05 12:43:17 (17 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
- Children:
- 5395ce6
- Parents:
- c9caf07
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_wag.c
r9c6aa95 r641dc7c 62 62 #include <string.h> 63 63 #include <stdlib.h> 64 65 #if HAVE_ZLIB 66 # include <zlib.h> 67 # define LIBTRACE_READ gzread 68 # define LIBTRACE_FDOPEN gzdopen 69 # define LIBTRACE_CLOSE gzclose 70 # define LIBTRACE_WRITE gzwrite 71 #else 72 # define LIBTRACE_READ read 73 # define LIBTRACE_FDOPEN open 74 # define LIBTRACE_CLOSE close 75 # define LIBTRACE_WRITE write 76 #endif 64 77 65 78 #ifdef HAVE_LIMITS_H … … 128 141 CONNINFO.path = libtrace->uridata; 129 142 if (!strncmp(CONNINFO.path,"-",1)) { 143 // STDIN 130 144 libtrace->sourcetype = STDIN; 131 // STDIN 132 #if HAVE_ZLIB 133 INPUT.file = gzdopen(STDIN, "r"); 134 #else 135 INPUT.file = stdin; 136 #endif 145 INPUT.file = LIBTRACE_FDOPEN(STDIN,"r"); 137 146 138 147 } else { … … 164 173 // TRACE 165 174 libtrace->sourcetype = TRACE; 166 #if HAVE_ZLIB 167 // using gzdopen means we can set O_LARGEFILE168 // ourselves. However, this way is messy and169 // we lose any error checking on "open"170 INPUT.file =171 gzdopen(open(175 176 // we use an FDOPEN call to reopen an FD 177 // returned from open(), so that we can set 178 // O_LARGEFILE. This gets around gzopen not 179 // letting you do this... 180 INPUT.file = LIBTRACE_FDOPEN(open( 172 181 CONNINFO.path, 173 182 O_LARGEFILE), "r"); 174 #else175 INPUT.file =176 fdopen(open(177 CONNINFO.path,178 O_LARGEFILE), "r");179 #endif180 183 181 184 } … … 193 196 if (!strncmp(libtrace->uridata,"-",1)) { 194 197 // STDOUT 195 #if HAVE_ZLIB 196 OUTPUT.file = gzdopen(dup(1), filemode); 197 #else 198 OUTPUT.file = stdout; 199 #endif 198 OUTPUT.file = LIBTRACE_FDOPEN(dup(1), filemode); 200 199 } else { 201 200 // TRACE 202 #if HAVE_ZLIB 203 OUTPUT.file = gzdopen(open( 201 OUTPUT.file = LIBTRACE_FDOPEN(open( 204 202 libtrace->uridata, 205 203 O_CREAT | O_LARGEFILE | O_WRONLY, 206 204 S_IRUSR | S_IWUSR), filemode); 207 #else208 OUTPUT.file = fdopen(open(209 O_CREAT | O_LARGEFILE | O_WRONLY,210 S_IRUSR | S_IWUSR), "w");211 #endif212 205 } 213 206 … … 244 237 245 238 static int wag_fin_input(struct libtrace_t *libtrace) { 246 #if HAVE_ZLIB 247 gzclose(INPUT.file); 248 #else 249 fclose(INPUT.file); 250 #endif 239 LIBTRACE_CLOSE(INPUT.file); 251 240 return 0; 252 241 } 253 242 254 243 static int wag_fin_output(struct libtrace_out_t *libtrace) { 255 #if HAVE_ZLIB 256 gzclose(OUTPUT.file); 257 #else 258 fclose(OUTPUT.file); 259 #endif 244 LIBTRACE_CLOSE(OUTPUT.file); 260 245 return 0; 261 246 } … … 279 264 break; 280 265 default: 281 #if HAVE_ZLIB 282 if ((numbytes=gzread(INPUT.file, 266 if ((numbytes=LIBTRACE_READ(INPUT.file, 283 267 buffer, 284 268 len)) == -1) { 285 perror(" gzread");269 perror("libtrace_read"); 286 270 return -1; 287 271 } 288 #else289 if ((numbytes=fread(buffer,len,1,290 INPUT.file)) == 0 ) {291 if(feof(INPUT.file)) {292 return 0;293 }294 if(ferror(INPUT.file)) {295 perror("fread");296 return -1;297 }298 return 0;299 }300 #endif301 272 } 302 273 break; … … 368 339 return -1; 369 340 } 370 #if HAVE_ZLIB 371 if ((numbytes = gzwrite(OUTPUT.file, packet->buffer, packet->size)) == 0) { 372 perror("gzwrite"); 341 if ((numbytes = LIBTRACE_WRITE(OUTPUT.file, packet->buffer, packet->size)) == 0) { 342 perror("libtrace_write"); 373 343 return -1; 374 344 } 375 #else376 if ((numbytes = write(OUTPUT.file, packet->buffer, packet->size)) == 0) {377 perror("write");378 return -1;379 }380 #endif381 345 return numbytes; 382 346 }
Note: See TracChangeset
for help on using the changeset viewer.