Changeset 1619 for zzuf


Ignore:
Timestamp:
Jan 7, 2007, 9:50:49 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • Implemented freopen().
Location:
zzuf/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/doc/zzuf.1

    r1616 r1619  
    267267.TP
    268268Standard IO streams:
    269 \fBfopen\fR(), \fBfseek\fR(), \fBfseeko\fR(), \fBrewind\fR(), \fBfread\fR(),
    270 \fBgetc\fR(), \fBfgetc\fR(), \fBfgets\fR(), \fBungetc\fR(), \fBfclose\fR()
     269\fBfopen\fR(), \fBfreopen\fR(), \fBfseek\fR(), \fBfseeko\fR(), \fBrewind\fR(),
     270\fBfread\fR(), \fBgetc\fR(), \fBfgetc\fR(), \fBfgets\fR(), \fBungetc\fR(),
     271\fBfclose\fR()
    271272.TP
    272273Linux-specific:
  • zzuf/trunk/src/load-stream.c

    r1618 r1619  
    5555static FILE *  (*fopen64_orig)  (const char *path, const char *mode);
    5656#endif
     57static FILE *  (*freopen_orig)  (const char *path, const char *mode,
     58                                 FILE *stream);
    5759static int     (*fseek_orig)    (FILE *stream, long offset, int whence);
    5860#ifdef HAVE_FSEEKO
     
    99101    LOADSYM(fopen64);
    100102#endif
     103    LOADSYM(freopen);
    101104    LOADSYM(fseek);
    102105#ifdef HAVE_FSEEKO
     
    161164}
    162165#endif
     166
     167FILE *freopen(const char *path, const char *mode, FILE *stream)
     168{
     169    FILE *ret;
     170    int fd0 = -1, fd1 = -1, disp = 0;
     171
     172    if(!_zz_ready)
     173        LOADSYM(freopen);
     174    if(_zz_ready && (fd0 = fileno(stream)) >= 0 && _zz_iswatched(fd0))
     175    {
     176        _zz_unregister(fd0);
     177        disp = 1;
     178    }
     179
     180    _zz_disabled = 1;
     181    ret = freopen_orig(path, mode, stream);
     182    _zz_disabled = 0;
     183
     184    if(ret && _zz_mustwatch(path))
     185    {
     186        fd1 = fileno(ret);
     187        _zz_register(fd1);
     188        disp = 1;
     189    }
     190
     191    if(disp)
     192        debug("freopen(\"%s\", \"%s\", [%i]) = [%i]", path, mode, fd0, fd1);
     193
     194    return ret;
     195}
    163196
    164197#if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
Note: See TracChangeset for help on using the changeset viewer.