1N/A/*********************************************************************** 1N/A* This software is part of the ast package * 1N/A* Copyright (c) 1985-2011 AT&T Intellectual Property * 1N/A* and is licensed under the * 1N/A* Common Public License, Version 1.0 * 1N/A* by AT&T Intellectual Property * 1N/A* A copy of the License is available at * 1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 1N/A* Information and Software Systems Research * 1N/A* Glenn Fowler <gsf@research.att.com> * 1N/A* David Korn <dgk@research.att.com> * 1N/A* Phong Vo <kpv@research.att.com> * 1N/A***********************************************************************/ 1N/A/* Set the IO pointer to a specific location in the stream 1N/A** Written by Kiem-Phong Vo. 1N/ASfio_t* f;
/* seek to a new location in this stream */ 1N/Aint type;
/* 0: from org, 1: from here, 2: from end */ 1N/A /* set and initialize the stream to a definite mode */ 1N/A /* Xopen-compliant */ 1N/A {
/* let system call set errno */ 1N/A /* throw away ungetc data */ 1N/A /* lock the stream for internal manipulations */ 1N/A /* clear error and eof bits */ 1N/A /* check exception handler, note that this may pop stream */ 1N/A {
/* see if we can avoid flushing buffer */ 1N/A /* if get here, must be a read stream */ 1N/A /* desired position */ 1N/A {
/* if mmap is not great, stop mmaping if moving around too much */ 1N/A {
/* for mmap, f->here can be virtual except for hardseek */ 1N/A {
/* reduce wastage in future buffer fillings */ 1N/A /* buffer is now considered empty */ 1N/A /* small backseeks often come in bunches, so seek back as far as possible */ 1N/A /* try to align buffer to block boundary to enhance I/O speed */ 1N/A /* seeking around and wasting data, be conservative */ 1N/A {
if(r < p)
/* now try to just get to p */ 1N/A if(r < p)
/* read to cover p */ 1N/A else /* recover from read failure by just seeking to p */ 1N/A if(f->
here < 0)
/* hasn't been the best of time */