_export void
p4_read_write (p4_File *fid, char *p, p4ucell n, int readflag)
{
size_t len;
p4_Q_file_open (fid);
clearerr (fid->f);
if (n > fid->size)
p4_throw (P4_ON_INVALID_BLOCK);
if (readflag && n == fid->size)
{
memset (p, ' ' , BPBUF);
return;
}
if (fseek (fid->f, n * BPBUF, SEEK_SET) != 0)
p4_throws (FX_IOR, fid->name, 0);
if (readflag)
{
if (!p4_can_read (fid))
p4_throw (P4_ON_BLOCK_READ);
len = fread (p, 1, BPBUF, fid->f);
if (ferror (fid->f))
p4_throws (FX_IOR, fid->name, 0);
memset (p + len, ' ' , BPBUF - len);
}else{
if (!p4_can_write (fid))
p4_throw (P4_ON_BLOCK_WRITE);
len = fwrite (p, 1, BPBUF, fid->f);
if (len < BPBUF || ferror (fid->f))
p4_throws (FX_IOR, fid->name, 0);
if (n == fid->size)
fid->size++;
}
return;
} |