Changeset 1602 for zzuf


Ignore:
Timestamp:
Jan 7, 2007, 3:14:19 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • Implemented refill(). Untested yet.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/src/load-stream.c

    r1600 r1602  
    3737#include "load.h"
    3838
     39#ifdef HAVE___SREFILL
     40int __srefill(FILE *fp);
     41#endif
     42
    3943/* Library functions that we divert */
    4044static FILE *  (*fopen_orig)    (const char *path, const char *mode);
     
    7680#endif
    7781#ifdef HAVE___SREFILL
    78 int         *  (*__srefill_orig) (FILE *fp);
     82int            (*__srefill_orig) (FILE *fp);
    7983#endif
    8084
     
    234238          ptr, (long int)size, (long int)nmemb, fd, (long int)ret);
    235239
     240    newpos = ftell(stream);
     241#if defined HAVE___SREFILL /* Don't fuzz if we have __srefill() */
     242    if(newpos != pos)
     243        _zz_setpos(fd, ftell(stream));
     244#else
    236245    /* XXX: the number of bytes read is not ret * size, because
    237246     * a partial read may have advanced the stream pointer. However,
    238247     * when reading from a pipe ftell() will return 0, and ret * size
    239248     * is then better than nothing. */
    240     newpos = ftell(stream);
    241249    if(newpos <= 0)
    242250        newpos = ret * size;
     
    246254        _zz_setpos(fd, newpos);
    247255    }
     256#endif
    248257
    249258    return ret;
    250259}
     260
     261#if defined HAVE___SREFILL /* Don't fuzz if we have __srefill() */
     262#   define FGETC_FUZZ
     263#else
     264#   define FGETC_FUZZ \
     265        if(ret != EOF) \
     266        { \
     267            uint8_t ch = ret; \
     268            _zz_fuzz(fd, &ch, 1); \
     269            _zz_addpos(fd, 1); \
     270            ret = ch; \
     271        }
     272#endif
    251273
    252274#define FGETC(fn) \
     
    261283        ret = ORIG(fn)(stream); \
    262284        _zz_disabled = 0; \
    263         if(ret != EOF) \
    264         { \
    265             uint8_t ch = ret; \
    266             _zz_fuzz(fd, &ch, 1); \
    267             _zz_addpos(fd, 1); \
    268             ret = ch; \
    269         } \
     285        FGETC_FUZZ \
    270286        if(ret >= 0x20 && ret <= 0x7f) \
    271287            debug(STR(fn)"([%i]) = 0x%02x '%c'", fd, ret, (char)ret); \
     
    303319        return fgets_orig(s, size, stream);
    304320
     321#if defined HAVE___SREFILL /* Don't fuzz if we have __srefill() */
     322    _zz_disabled = 1;
     323    ret = fgets_orig(s, size, stream);
     324    _zz_disabled = 0;
     325    _zz_setpos(fd, ftell(stream));
     326#else
    305327    if(size <= 0)
    306328        ret = NULL;
     
    334356        }
    335357    }
     358#endif
    336359
    337360    debug("fgets(%p, %i, [%i]) = %p", s, size, fd, ret);
     
    351374
    352375    _zz_addpos(fd, -1);
     376#if defined HAVE___SREFILL /* Don't fuzz if we have __srefill() */
     377#else
    353378    _zz_fuzz(fd, &ch, 1);
     379#endif
     380    _zz_disabled = 1;
    354381    ret = ungetc_orig((int)ch, stream);
     382    _zz_disabled = 0;
    355383    if(ret >= 0)
    356384        ret = c;
     
    462490char *fgetln(FILE *stream, size_t *len)
    463491{
     492    char *ret;
    464493    struct fuzz *fuzz;
    465494    size_t i, size;
     
    472501        return fgetln_orig(stream, len);
    473502
     503#if defined HAVE___SREFILL /* Don't fuzz if we have __srefill() */
     504    _zz_disabled = 1;
     505    ret = fgetln_orig(stream, len);
     506    _zz_disabled = 0;
     507#else
    474508    fuzz = _zz_getfuzz(fd);
    475509
     
    497531
    498532    *len = i;
     533    ret = fuzz->tmp;
     534#endif
    499535
    500536    debug("fgetln([%i], &%li) = %p", fd, (long int)*len, fuzz->tmp);
    501     return fuzz->tmp;
     537    return ret;
    502538}
    503539#endif
     
    512548    fd = fileno(fp);
    513549    ret = __srefill_orig(fp);
    514     if(!_zz_ready || !_zz_iswatched(fd))
     550    if(!_zz_ready || !_zz_iswatched(fd) || _zz_disabled)
    515551        return ret;
     552
     553    if(ret != EOF)
     554        _zz_fuzz(fd, fp->_p, fp->_r);
    516555
    517556    debug("__srefill([%i]) = %i", fd, ret);
Note: See TracChangeset for help on using the changeset viewer.