Changeset 1678


Ignore:
Timestamp:
Jan 16, 2007, 3:21:28 PM (16 years ago)
Author:
Sam Hocevar
Message:
  • pread() implementation, thanks to Clément Stenac.
Location:
zzuf/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/AUTHORS

    r1676 r1678  
    66other contributors:
    77 Rémi Denis-Courmont <rdenis#simphalempin:com> (readv support)
     8 Clément Stenac <zorglub#diwi:org> (pread support)
    89
  • zzuf/trunk/doc/zzuf.1

    r1676 r1678  
    318318.TP
    319319Unix file descriptor handling:
    320 \fBopen\fR(), \fBlseek\fR(), \fBread\fR(), \freadv\fR(), \fBaccept\fR(),
    321 \fBsocket\fR(), \fBclose\fR()
     320\fBopen\fR(), \fBlseek\fR(), \fBread\fR(), \fBreadv\fR(), \fBpread\fR(),
     321\fBaccept\fR(), \fBsocket\fR(), \fBclose\fR()
    322322.TP
    323323Standard IO streams:
  • zzuf/trunk/src/load-fd.c

    r1677 r1678  
    33 *  Copyright (c) 2006, 2007 Sam Hocevar <sam@zoy.org>
    44 *                2007 Rémi Denis-Courmont <rdenis#simphalempin:com>
     5 *                2007 Clément Stenac <zorglub#diwi:org>
    56 *                All Rights Reserved
    67 *
     
    6364static ssize_t (*read_orig)    (int fd, void *buf, size_t count);
    6465static ssize_t (*readv_orig)   (int fd, const struct iovec *iov, int count);
     66static ssize_t (*pread_orig)   (int fd, void *buf, size_t count, off_t offset);
    6567static off_t   (*lseek_orig)   (int fd, off_t offset, int whence);
    6668#ifdef HAVE_LSEEK64
     
    7981    LOADSYM(socket);
    8082    LOADSYM(read);
     83    LOADSYM(readv);
     84    LOADSYM(pread);
    8185    LOADSYM(lseek);
    8286#ifdef HAVE_LSEEK64
     
    238242}
    239243
     244ssize_t pread(int fd, void *buf, size_t count, off_t offset)
     245{
     246    int ret;
     247
     248    LOADSYM(pread);
     249    ret = pread_orig(fd, buf, count, offset);
     250    if(!_zz_ready || !_zz_iswatched(fd) || _zz_disabled)
     251        return ret;
     252
     253    if(ret > 0)
     254    {
     255        long int curoff = _zz_getpos(fd);
     256        char *b = buf;
     257
     258        _zz_setpos(fd, offset);
     259        _zz_fuzz(fd, buf, ret);
     260        _zz_setpos(fd, curoff);
     261
     262        if(ret >= 4)
     263            debug("pread(%i, %p, %li, %li) = %i \"%c%c%c%c...", fd, buf,
     264                  (long int)count, (long int)offset, ret,
     265                  b[0], b[1], b[2], b[3]);
     266        else
     267            debug("pread(%i, %p, %li, %li) = %i \"%c...", fd, buf,
     268                  (long int)count, (long int)offset, ret, b[0]);
     269    }
     270    else
     271        debug("pread(%i, %p, %li, %li) = %i", fd, buf,
     272              (long int)count, (long int)offset, ret);
     273
     274    return ret;
     275}
     276
    240277#define LSEEK(fn, off_t) \
    241278    do \
Note: See TracChangeset for help on using the changeset viewer.