Example #1
0
/* <file> fileposition <int> */
static int
zfileposition(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    stream *s;

    check_file(s, op);
    /*
     * The PLRM says fileposition must give an error for non-seekable
     * streams.
     */
    if (!s_can_seek(s))
	return_error(e_ioerror);
    make_int(op, stell(s));
    return 0;
}
Example #2
0
/*
 * Seek to a position in the stream. Returns the 0, or -1 if error
 */
int
sfseek(stream *s, long offset, int whence)
{
    long newpos = offset;

    if (whence == SEEK_CUR)
	newpos += stell(s);
    if (whence == SEEK_END) {
	long endpos;

	if (savailable(s, &endpos) < 0)
	    return -1;
	newpos = endpos - offset;
    }
    if (s_can_seek(s) || newpos == stell(s)) {
	return sseek(s, newpos);
    }
    return -1;		/* fail */
}