Changeset 1678 for zzuf/trunk/src


Ignore:
Timestamp:
Jan 16, 2007, 3:21:28 PM (13 years ago)
Author:
Sam Hocevar
Message:
  • pread() implementation, thanks to Clément Stenac.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.