Ignore:
Timestamp:
Jul 16, 2008, 11:52:02 AM (12 years ago)
Author:
Sam Hocevar
Message:
  • Implement srefill() for full HP-UX support on parisc-gcc.
File:
1 edited

Legend:

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

    r2528 r2533  
    4040#include "fd.h"
    4141
     42#if defined HAVE___SREFILL || defined HAVE___FILBUF
     43#   define HAVE_REFILL_STDIO
     44#endif
     45
    4246#if defined HAVE___SREFILL
    4347int NEW(__srefill)(FILE *fp);
     48#endif
     49
     50#if defined HAVE___FILBUF
     51int NEW(__filbuf)(FILE *fp);
    4452#endif
    4553
     
    6472#if defined HAVE___FSEEKO64
    6573static int     (*ORIG(__fseeko64)) (FILE *stream, off_t offset, int whence);
     74#endif
     75#if defined HAVE___FSETPOS64
     76static int     (*ORIG(__fsetpos64)) (FILE *stream, const fpos64_t *pos);
    6677#endif
    6778static void    (*ORIG(rewind))   (FILE *stream);
     
    115126#endif
    116127
     128/* Additional HP-UXisms */
     129#if defined HAVE___FILBUF
     130int            (*ORIG(__filbuf))  (FILE *fp);
     131#endif
     132
    117133/* Our function wrappers */
     134#if defined HAVE_REFILL_STDIO /* Fuzz fp if we have __srefill() */
     135#   define FOPEN_FUZZ() \
     136    _zz_fuzz(fd, ret->__ptr, ret->__cnt)
     137#else
     138#   define FOPEN_FUZZ()
     139#endif
     140
    118141#define FOPEN(fn) \
    119142    do \
     
    130153            _zz_register(fd); \
    131154            debug("%s(\"%s\", \"%s\") = [%i]", __func__, path, mode, fd); \
     155            FOPEN_FUZZ(); \
    132156        } \
    133157    } while(0)
     
    188212#endif
    189213
    190 #if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
     214#if defined HAVE_REFILL_STDIO /* Don't fuzz or seek if we have __srefill() */
    191215#   define FSEEK_FUZZ(fn2)
    192216#else
     
    245269#endif
    246270
     271#if defined HAVE___FSETPOS64
     272int NEW(__fsetpos64)(FILE *stream, const fpos64_t *pos)
     273{
     274    int ret, fd;
     275
     276    LOADSYM(__fsetpos64);
     277    fd = fileno(stream);
     278    if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd))
     279        return ORIG(__fsetpos64)(stream, pos);
     280    _zz_lock(fd);
     281    ret = ORIG(__fsetpos64)(stream, pos);
     282    _zz_unlock(fd);
     283    debug("%s([%i], %lli) = %i", __func__,
     284          fd, (long long int)*pos, ret);
     285    /* On HP-UX at least, fpos64_t == int64_t */
     286    _zz_setpos(fd, (int64_t)*pos);
     287
     288    return ret;
     289}
     290#endif
     291
    247292void NEW(rewind)(FILE *stream)
    248293{
     
    262307    debug("%s([%i])", __func__, fd);
    263308
    264 #if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
     309#if defined HAVE_REFILL_STDIO /* Don't fuzz or seek if we have __srefill() */
    265310#else
    266311    /* FIXME: check what happens when rewind()ing a pipe */
     
    269314}
    270315
    271 #if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
     316#if defined HAVE_REFILL_STDIO /* Don't fuzz or seek if we have __srefill() */
    272317#   define FREAD_FUZZ() \
    273318    do \
     
    339384#endif
    340385
    341 #if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
     386#if defined HAVE_REFILL_STDIO /* Don't fuzz or seek if we have __srefill() */
    342387#   define FGETC_FUZZ
    343388#else
     
    417462#endif
    418463
    419 #if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
     464#if defined HAVE_REFILL_STDIO /* Don't fuzz or seek if we have __srefill() */
    420465#   define FGETS_FUZZ(fn, fn2) \
    421466        _zz_lock(fd); \
     
    501546        fuzz->upos = _zz_getpos(fd) - 1;
    502547        fuzz->uchar = c;
    503 #if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
     548#if defined HAVE_REFILL_STDIO /* Don't fuzz or seek if we have __srefill() */
    504549#else
    505550        _zz_addpos(fd, -1);
     
    614659{
    615660    char *ret;
    616 #if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
     661#if defined HAVE_REFILL_STDIO /* Don't fuzz or seek if we have __srefill() */
    617662#else
    618663    struct fuzz *fuzz;
     
    627672        return ORIG(fgetln)(stream, len);
    628673
    629 #if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
     674#if defined HAVE_REFILL_STDIO /* Don't fuzz or seek if we have __srefill() */
    630675    _zz_lock(fd);
    631676    ret = ORIG(fgetln)(stream, len);
     
    682727    if(ret != EOF)
    683728    {
     729        /* FIXME: do we have to fuzz ret, too, like in __filbuf? */
    684730        if(newpos != -1)
    685731            _zz_setpos(fd, newpos - fp->_r);
     
    695741#endif
    696742
     743#if defined HAVE___FILBUF
     744int NEW(__filbuf)(FILE *fp)
     745{
     746    off_t newpos;
     747    int ret, fd;
     748
     749    LOADSYM(__filbuf);
     750    fd = fileno(fp);
     751    if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd))
     752        return ORIG(__filbuf)(fp);
     753
     754    _zz_lock(fd);
     755    ret = ORIG(__filbuf)(fp);
     756    newpos = lseek(fd, 0, SEEK_CUR);
     757    _zz_unlock(fd);
     758    if(ret != EOF)
     759    {
     760        if(newpos != -1)
     761            _zz_setpos(fd, newpos - fp->__cnt - 1);
     762        _zz_fuzz(fd, fp->__ptr - 1, fp->__cnt + 1);
     763        ret = (uint8_t)fp->__ptr[-1];
     764        _zz_addpos(fd, fp->__cnt + 1);
     765    }
     766
     767    if(!_zz_islocked(fd))
     768        debug("%s([%i]) = %i", __func__, fd, ret);
     769
     770    return ret;
     771}
     772#endif
     773
Note: See TracChangeset for help on using the changeset viewer.