Ignore:
Timestamp:
12/03/08 13:24:55 (13 years ago)
Author:
Perry Lorier <perry@…>
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:
f66a2dca
Parents:
7157db8
Message:

Rewrite the libtrace io subsystem to use the new wandio abstraction layer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_helper.c

    rf3f3558 rc66068d  
    3535#include "libtrace.h"
    3636#include "libtrace_int.h"
     37#include "wandio.h"
    3738
    3839#include <stdlib.h>
     
    198199 * @internal
    199200 */
    200 libtrace_io_t *trace_open_file(libtrace_t *trace)
    201 {
    202         int fd;
    203         libtrace_io_t *ret;
    204 
    205 
    206         if (strcmp(trace->uridata,"-")==0) {
    207                 ret=libtrace_io_fdopen(fileno(stdin),"rb");
    208                 return ret;
    209         }
    210 
    211         /* We open the file with open(2), so we can provide O_LARGEFILE
    212          * as zlib doesn't always do it itself
    213          */
    214         fd=open(trace->uridata,O_LARGEFILE|O_RDONLY|O_BINARY);
    215         if (fd==-1) {
    216                 trace_set_err(trace,errno,"Unable to open %s",trace->uridata);
    217                 return 0;
    218         }
    219         ret=libtrace_io_fdopen(fd,"rb");
    220         return ret;
     201io_t *trace_open_file(libtrace_t *trace)
     202{
     203        return wandio_create(trace->uridata);
    221204}
    222205
     
    224207 * @internal
    225208 */
    226 libtrace_io_t *trace_open_file_out(libtrace_out_t *trace,int level, int fileflag)
    227 {
    228         int fd;
    229         libtrace_io_t *ret;
    230         char filemode[4]; /* wb9\0 */
     209iow_t *trace_open_file_out(libtrace_out_t *trace,int level, int fileflag)
     210{
    231211        assert(level<10);
    232212        assert(level>=0);
    233 #ifdef HAVE_LIBZ
    234         snprintf(filemode,sizeof(filemode),"wb%d",level);
    235 #else
    236         snprintf(filemode,sizeof(filemode),"wb");
    237 #endif
    238 
    239         if (strcmp(trace->uridata,"-")==0) {
    240                 ret=libtrace_io_fdopen(fileno(stdout),filemode);
    241                 return ret;
    242         }
    243 
    244         /* We open the file with open(2), so we can provide O_LARGEFILE
    245          * as zlib doesn't always do it itself
    246          */
    247         fd=open(trace->uridata,fileflag|O_LARGEFILE|O_BINARY,0666);
    248         if (fd==-1) {
    249                 trace_set_err_out(trace,
    250                                 errno,"Unable to open %s",trace->uridata);
    251                 return 0;
    252         }
    253         ret=libtrace_io_fdopen(fd,filemode);
    254         if (!ret) {
    255                 trace_set_err_out(trace,
    256                                 TRACE_ERR_INIT_FAILED,"gz out of memory");
    257         }
    258         return ret;
     213
     214        return wandio_wcreate(trace->uridata, level, fileflag);
    259215}
    260216
Note: See TracChangeset for help on using the changeset viewer.