Changeset 3d4d52d for lib/format_wag.c


Ignore:
Timestamp:
02/17/06 14:49:14 (16 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:
65a5900
Parents:
f03fc17
Message:

Abstract away opening up traces into a single trace_open_trace that's more
simple and reliable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_wag.c

    rf03fc17 r3d4d52d  
    148148}
    149149
    150 static int wtf_init_input(struct libtrace_t *libtrace) {
    151 
     150static int wtf_init_input(struct libtrace_t *libtrace)
     151{
    152152        libtrace->format_data = (struct libtrace_format_data_t *)
    153                 calloc(1,sizeof(struct libtrace_format_data_t));
    154         CONNINFO.path = libtrace->uridata;
    155 
    156         if (!strncmp(CONNINFO.path,"-",1)) {
    157                 /* STDIN */
    158                 INPUT.file = LIBTRACE_FDOPEN(fileno(stdin),"r");
    159         } else {
    160                 int fd;
    161                 /* TRACE */
    162 
    163                 /* we use an FDOPEN call to reopen an FD
    164                  * returned from open(), so that we can set
    165                  * O_LARGEFILE. This gets around gzopen not
    166                  * letting you do this...
    167                  */
    168                 fd = open(CONNINFO.path, O_LARGEFILE);
    169                 if (fd==-1) {
    170                         trace_set_err(errno,"open(%s)",CONNINFO.path);
    171                         return 0;
    172                 }
    173                 INPUT.file = LIBTRACE_FDOPEN(fd, "r");
    174 
    175         }
    176         return 1;
    177 }
    178 
     153                malloc(sizeof(struct libtrace_format_data_t));
     154
     155        libtrace->format_data->input.file = trace_open_file(libtrace);
     156
     157        if (libtrace->format_data->input.file)
     158                return 1;
     159
     160        return 0;
     161}
    179162
    180163static int wtf_init_output(struct libtrace_out_t *libtrace) {
     
    340323       
    341324        if ((numbytes = LIBTRACE_READ(INPUT.file, buffer, sizeof(struct frame_t))) == -1) {
    342                 libtrace_set_err(errno,"read(%s)",packet->trace->uridata);
     325                trace_set_err(errno,"read(%s)",packet->trace->uridata);
    343326                return -1;
    344327        }
     
    355338       
    356339        if ((numbytes=LIBTRACE_READ(INPUT.file, buffer2, size)) != size) {
    357                 libtrace_set_err(errno,"read(%s)",packet->trace->uridata);
     340                trace_set_err(errno,"read(%s)",packet->trace->uridata);
    358341                return -1;
    359342        }
     
    379362         */
    380363        if ((numbytes = LIBTRACE_WRITE(OUTPUT.file, packet->header, trace_get_framing_length(packet))) == -1) {
    381                 libtrace_set_err(errno,"write(%s)",packet->trace->uridata);
     364                trace_set_err(errno,"write(%s)",packet->trace->uridata);
    382365                return -1;
    383366        }
    384367        if ((numbytes = LIBTRACE_WRITE(OUTPUT.file, packet->payload,
    385368                        packet->size - trace_get_framing_length(packet))) == 0) {
    386                 libtrace_set_err(errno,"write(%s)",packet->trace->uridata);
     369                trace_set_err(errno,"write(%s)",packet->trace->uridata);
    387370                return -1;
    388371        }
Note: See TracChangeset for help on using the changeset viewer.