The R Project SVN R

Rev

Rev 88625 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 88625 Rev 89494
Line 362... Line 362...
362
    return con->buff[con->buff_pos++];
362
    return con->buff[con->buff_pos++];
363
}
363
}
364
 
364
 
365
static double buff_seek(Rconnection con, double where, int origin, int rw)
365
static double buff_seek(Rconnection con, double where, int origin, int rw)
366
{
366
{
367
    size_t unread_len = con->buff_stored_len - con->buff_pos;
367
    double unread_len = (double)(con->buff_stored_len - con->buff_pos);
368
 
368
 
369
    if (rw == 2) /* write */
369
    if (rw == 2) /* write */
370
	return con->seek(con, where, origin, rw);
370
	return con->seek(con, where, origin, rw);
371
 
371
 
372
    if (ISNA(where)) /* tell */
372
    if (ISNA(where)) /* tell */
Line 3361... Line 3361...
3361
}
3361
}
3362
 
3362
 
3363
static double raw_seek(Rconnection con, double where, int origin, int rw)
3363
static double raw_seek(Rconnection con, double where, int origin, int rw)
3364
{
3364
{
3365
    Rrawconn this = con->private;
3365
    Rrawconn this = con->private;
3366
    double newpos;
3366
    double newpos; // maybe should be size_t
3367
    size_t oldpos = this->pos;
3367
    size_t oldpos = this->pos;
3368
 
3368
 
3369
    if(ISNA(where)) return (double) oldpos;
3369
    if(ISNA(where)) return (double) oldpos;
3370
 
3370
 
3371
    /* Do the calculations here as double to avoid integer overflow */
3371
    /* Do the calculations here as double to avoid integer overflow */
3372
    switch(origin) {
3372
    switch(origin) {
3373
    case 2: newpos = (double) this->pos + where; break;
3373
    case 2: newpos = (double) this->pos + where; break;
3374
    case 3: newpos = (double) this->nbytes + where; break;
3374
    case 3: newpos = (double) this->nbytes + where; break;
3375
    default: newpos = where;
3375
    default: newpos = where;
3376
    }
3376
    }
3377
    if(newpos < 0 || newpos > this->nbytes)
3377
    if(newpos < 0 || newpos > (double)this->nbytes)
3378
	error(_("attempt to seek outside the range of the raw connection"));
3378
	error(_("attempt to seek outside the range of the raw connection"));
3379
    else this->pos = (size_t) newpos;
3379
    else this->pos = (size_t) newpos;
3380
 
3380
 
3381
    return (double) oldpos;
3381
    return (double) oldpos;
3382
}
3382
}