/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2011 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#include "sfhdr.h"
/* Move data from one stream to another.
** This code is written so that it'll work even in the presence
** of stacking streams, pool, and discipline.
** If you must change it, be gentle.
**
** Written by Kiem-Phong Vo.
*/
#if __STD_C
#else
#endif
{
SFMTXDECL2(fw);
if(fw)
for(n_move = 0; n != 0; )
{
if(rc >= 0) /* moving records, let sfgetr() deal with record reading */
n = 0;
else
n = 0;
}
else
{ n_move += 1;
if(n > 0)
n -= 1;
}
}
continue;
}
/* get the streams into the right mode */
break;
/* flush the write buffer as necessary to make room */
if(fw)
break;
break;
}
if(n > 0)
continue;
}
/* else: stream unstacking may happen below */
}
/* about to move all, set map to a large amount */
}
/* try reading a block of data */
direct = 0;
{ /* amount of data remained to be read */
}
/* use a decent buffer for data transfer but make sure
that if we overread, the left over can be retrieved
*/
/* direct transfer to a seekable write stream */
}
{ /* making our own buffer */
if(w >= maxw)
w = maxw;
rsize = w;
if(rbuf)
w = rsize;
}
}
}
if(!direct)
{ /* make sure we don't read too far ahead */
r = (ssize_t)n;
}
else r = -1;
break;
}
else
{ /* actual amount to be read */
if(n > 0 && n < w)
w = (ssize_t)n;
else if(r == 0)
break; /* eof */
else goto again; /* popped stack */
}
}
/* compute the extent of data to be moved */
if(n > 0)
{ if(r > n)
r = (ssize_t)n;
n -= r;
}
n_move += r;
if(!direct)
{ /* move left-over to read stream */
}
if(fw)
}
{ /* a write error happened */
if(w > 0)
{ r -= w;
n_move -= r;
}
break;
}
}
if(fw)
}
{ /* back to normal access mode */
}
if(rbuf)
if(fw)
}
}