Ignore:
Timestamp:
04/23/06 14:21:02 (15 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:
e4e95499
Parents:
4315572b
Message:

Fix the stdio error handling
Document better the libtraceio API. See the trac wiki for more information.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/libtraceio-stdio.c

    r4315572b r698a217  
    55#include <stdio.h>
    66#include <stdlib.h>
    7 
    8 #include <errno.h> /* for debugging */
    97
    108struct libtrace_io_t {
     
    1715
    1816        if (ret==(int)len) {
    19                 printf("read %i bytes\n",ret);
    2017                return len;
    2118        }
     
    2320        /* EOF or an Error occurred */
    2421        if (ferror(io->file)) {
    25                 int err=errno;
    26                 perror("fread");
    27                 errno=err;
    2822                /* errno will be set */
    2923                return -1;
    3024        }
    31 
    32         printf("eof\n");
    3325
    3426        return 0; /* EOF */
     
    6153ssize_t libtrace_io_write(libtrace_io_t *io, const void *buf, size_t len)
    6254{
    63         return fwrite(buf,len,1,io->file);
     55        int ret=fwrite(buf,1,len,io->file);
     56        if (ret==len) {
     57                return ret;
     58        }
     59       
     60        /* Error occurred? */
     61        if (ferror(io->file))
     62                return -1; /* errno will already be set */
     63
     64        return 0; /* eof */
    6465}
    6566
Note: See TracChangeset for help on using the changeset viewer.