Changeset 2569 for zzuf/trunk


Ignore:
Timestamp:
Jul 18, 2008, 11:28:30 AM (12 years ago)
Author:
Sam Hocevar
Message:
  • Implement srget on FreeBSD, which is yet another version of srefill.
Location:
zzuf/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/configure.ac

    r2562 r2569  
    4040
    4141AC_CHECK_FUNCS(setenv waitpid setrlimit gettimeofday fork kill pipe _pipe)
    42 AC_CHECK_FUNCS(open64 __open64 lseek64 __lseek64 mmap64 fopen64 __fopen64 freopen64 __freopen64 dup dup2 fseeko fseeko64 __fseeko64 fsetpos64 __fsetpos64 _IO_getc getline getdelim __getdelim fgetln __srefill __filbuf map_fd memalign posix_memalign aio_read accept bind connect socket readv pread recv recvfrom recvmsg mmap valloc sigaction getpagesize getc_unlocked getchar_unlocked fgetc_unlocked fread_unlocked fgets_unlocked)
     42AC_CHECK_FUNCS(open64 __open64 lseek64 __lseek64 mmap64 fopen64 __fopen64 freopen64 __freopen64 dup dup2 fseeko fseeko64 __fseeko64 fsetpos64 __fsetpos64 _IO_getc getline getdelim __getdelim fgetln __srefill __filbuf __srget map_fd memalign posix_memalign aio_read accept bind connect socket readv pread recv recvfrom recvmsg mmap valloc sigaction getpagesize getc_unlocked getchar_unlocked fgetc_unlocked fread_unlocked fgets_unlocked)
    4343
    4444AC_CHECK_TYPES(sighandler_t, [], [],
     
    7474AC_TRY_COMPILE([#include <stdio.h>],
    7575 [FILE *fp; fp->__cnt++; fp->__ptr++],
    76  [ac_v_fp_cnt=__cnt; ac_v_fp_ptr=__ptr])
    77 AC_TRY_COMPILE([#include <stdio.h>],
    78  [FILE *fp; fp->_cnt++; fp->_ptr++],
    79  [ac_v_fp_cnt=_cnt; ac_v_fp_ptr=_ptr])
    80 AC_TRY_COMPILE([#include <stdio.h>],
    81  [FILE *fp; fp->_c++; fp->_p++],
    82  [ac_v_fp_cnt=_c; ac_v_fp_ptr=_p])
     76 [ac_v_fp_cnt=__cnt; ac_v_fp_ptr=__ptr],
     77 [AC_TRY_COMPILE([#include <stdio.h>],
     78   [FILE *fp; fp->_cnt++; fp->_ptr++],
     79   [ac_v_fp_cnt=_cnt; ac_v_fp_ptr=_ptr],
     80   [AC_TRY_COMPILE([#include <stdio.h>],
     81     [FILE *fp; fp->_c++; fp->_p++],
     82     [ac_v_fp_cnt=_c; ac_v_fp_ptr=_p],
     83     [AC_TRY_COMPILE([#include <stdio.h>],
     84       [FILE *fp; fp->_r++; fp->_p++],
     85       [ac_v_fp_cnt=_r; ac_v_fp_ptr=_p])])])])
    8386AC_MSG_RESULT($ac_v_fp_cnt/$ac_v_fp_ptr)
    8487AC_DEFINE_UNQUOTED(FILE_CNT, $ac_v_fp_cnt, [Define to the FILE::cnt member name])
  • zzuf/trunk/doc/libzzuf.3

    r2552 r2569  
    101101.TP
    102102Required on BSD systems:
    103 \fBfgetln\fR(), \fB__srefill\fR()
     103\fBfgetln\fR(), \fB__srefill\fR(), \fB__srget\fR()
    104104.TP
    105105Required on Mac OS X:
  • zzuf/trunk/src/lib-stream.c

    r2568 r2569  
    5656#endif
    5757
     58#if defined HAVE___SRGET
     59int NEW(__srget)(FILE *fp);
     60#endif
     61
    5862/* Library functions that we divert */
    5963static FILE *  (*ORIG(fopen))    (const char *path, const char *mode);
     
    138142#if defined HAVE___SREFILL
    139143int            (*ORIG(__srefill)) (FILE *fp);
     144#endif
     145#if defined HAVE___SRGET
     146int            (*ORIG(__srget))   (FILE *fp);
    140147#endif
    141148
     
    749756#endif
    750757
     758#define REFILL(fn) \
     759    do \
     760    { \
     761        off_t newpos; \
     762        int fd; \
     763        LOADSYM(fn); \
     764        fd = fileno(fp); \
     765        if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \
     766            return ORIG(fn)(fp); \
     767        _zz_lock(fd); \
     768        ret = ORIG(fn)(fp); \
     769        newpos = lseek(fd, 0, SEEK_CUR); \
     770        _zz_unlock(fd); \
     771        if(ret != EOF) \
     772        { \
     773            if(newpos != -1) \
     774                _zz_setpos(fd, newpos - fp->FILE_CNT - 1); \
     775            _zz_fuzz(fd, fp->FILE_PTR - 1, fp->FILE_CNT + 1); \
     776            ret = (uint8_t)fp->FILE_PTR[-1]; \
     777            _zz_addpos(fd, fp->FILE_CNT + 1); \
     778        } \
     779        if(!_zz_islocked(fd)) \
     780            debug("%s([%i]) = %i", __func__, fd, ret); \
     781    } \
     782    while(0)
     783
    751784#if defined HAVE___SREFILL
    752785int NEW(__srefill)(FILE *fp)
    753786{
    754     off_t newpos;
    755     int ret, fd;
    756 
    757     LOADSYM(__srefill);
    758     fd = fileno(fp);
    759     if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd))
    760         return ORIG(__srefill)(fp);
    761 
    762     _zz_lock(fd);
    763     ret = ORIG(__srefill)(fp);
    764     newpos = lseek(fd, 0, SEEK_CUR);
    765     _zz_unlock(fd);
    766     if(ret != EOF)
    767     {
    768         /* FIXME: do we have to fuzz ret, too, like in __filbuf? */
    769         if(newpos != -1)
    770             _zz_setpos(fd, newpos - fp->_r);
    771         _zz_fuzz(fd, fp->_p, fp->_r);
    772         _zz_addpos(fd, fp->_r);
    773     }
    774 
    775     if(!_zz_islocked(fd))
    776         debug("%s([%i]) = %i", __func__, fd, ret);
    777 
    778     return ret;
     787    int ret; REFILL(__srefill); return ret;
     788}
     789#endif
     790
     791#if defined HAVE___SRGET
     792int NEW(__srget)(FILE *fp)
     793{
     794    int ret; REFILL(__srget); return ret;
    779795}
    780796#endif
     
    783799int NEW(__filbuf)(FILE *fp)
    784800{
    785     off_t newpos;
    786     int ret, fd;
    787 
    788     LOADSYM(__filbuf);
    789     fd = fileno(fp);
    790     if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd))
    791         return ORIG(__filbuf)(fp);
    792 
    793     _zz_lock(fd);
    794     ret = ORIG(__filbuf)(fp);
    795     newpos = lseek(fd, 0, SEEK_CUR);
    796     _zz_unlock(fd);
    797     if(ret != EOF)
    798     {
    799         if(newpos != -1)
    800             _zz_setpos(fd, newpos - fp->FILE_CNT - 1);
    801         _zz_fuzz(fd, fp->FILE_PTR - 1, fp->FILE_CNT + 1);
    802         ret = (uint8_t)fp->FILE_PTR[-1];
    803         _zz_addpos(fd, fp->FILE_CNT + 1);
    804     }
    805 
    806     if(!_zz_islocked(fd))
    807         debug("%s([%i]) = %i", __func__, fd, ret);
    808 
    809     return ret;
    810 }
    811 #endif
    812 
     801    int ret; REFILL(__filbuf); return ret;
     802}
     803#endif
     804
Note: See TracChangeset for help on using the changeset viewer.