/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2010 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"
/* Write with discipline.
**
** Written by Kiem-Phong Vo.
*/
/* hole preserving writes */
#if __STD_C
#else
Sfio_t* f;
char* buf;
size_t n;
#endif
s = w = 0;
while(n > 0)
{ buf += n;
s = n = 0;
}
{ /* see if a hole of 0's starts here */
{ /* check byte at a time until int-aligned */
{ if(*sp != 0)
goto chk_hole;
sp += 1;
}
/* check using int to speed up */
{ if(*((int*)sp) != 0)
goto chk_hole;
sp += sizeof(int);
}
/* check the remaining bytes */
{ sp -= sizeof(int);
{ if(*sp != 0)
goto chk_hole;
sp += 1;
}
}
}
break;
/* skip a dirty page */
n -= _Sfpage;
}
/* write out current dirty pages */
n = s = 0;
}
{ w += wr;
}
break;
}
/* seek to a rounded boundary within the hole */
if(s >= _Sfpage)
break;
w += s;
n -= s;
if(n > 0)
{ /* next page must be dirty */
buf += s;
n -= s;
}
}
}
return w > 0 ? w : -1;
}
#if __STD_C
#else
Sfio_t* f;
size_t n;
#endif
{
SFMTXDECL(f);
}
for(;;)
{ /* stream locked by sfsetfd() */
SFMTXRETURN(f,(ssize_t)0);
/* clear current error states */
else
{ /* warn that a write is about to happen */
if(local)
SETLOCAL(f);
n = rv;
else if(rv < 0)
SFMTXRETURN(f, rv);
}
}
if(f->extent >= 0)
{ /* make sure we are at the right place to write */
if(f->flags&SF_APPENDWR)
}
}
}
errno = 0;
}
else if(SFISNULL(f))
w = n;
goto do_write;
goto do_write;
}
else
{
}
if(errno == 0)
if(w > 0)
else f->here += w;
}
SFMTXRETURN(f, (ssize_t)w);
}
}
if(local)
SETLOCAL(f);
{
case SF_ECONT :
goto do_continue;
case SF_EDONE :
w = local ? 0 : w;
SFMTXRETURN(f, (ssize_t)w);
case SF_EDISC :
goto do_continue;
/* else fall thru */
case SF_ESTACK :
}
break;
}
}