/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* 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> *
* *
***********************************************************************/
#if defined(__STDPP__directive) && defined(__STDPP__hide)
#else
#define getpagesize ______getpagesize
#endif
#include "sfhdr.h"
#if defined(__STDPP__directive) && defined(__STDPP__hide)
#else
#endif
#if _lib_getpagesize
extern int getpagesize _ARG_((void));
#endif
/* Set a (new) buffer for a stream.
** If size < 0, it is assigned a suitable value depending on the
** kind of stream. The actual buffer size allocated is dependent
** on how much memory is available.
**
** Written by Kiem-Phong Vo.
*/
#if !_sys_stat
struct stat
{ int st_mode;
int st_size;
};
#endif /*_sys_stat*/
#if _PACKAGE_ast && !defined(SFSETLINEMODE)
#endif
#if SFSETLINEMODE
static int sfsetlinemode()
{ char* astsfio;
char* endw;
if (modes < 0)
{ modes = 0;
++astsfio;
;
#if _PACKAGE_ast
#else
#endif
modes |= SF_WCWIDTH;
}
}
}
return modes;
}
#endif
#if __STD_C
#else
Sfio_t* f; /* stream to be buffered */
#endif
{
SFMTXDECL(f);
SFONCE();
{ /* special case to get buffer info */
}
/* cleanup actions already done, don't allow write buffering any more */
size = 0;
}
{ if(!f->pool && _sfsetpool(f) < 0)
}
if(init)
else
{ int rv;
/* make sure there is no hidden read data */
/* synchronize first */
if(rv < 0)
/* turn off the SF_SYNCED bit because buffer is changing */
}
blksz = -1;
else /* setting alignment size only */
if(!init) /* stream already initialized */
goto done;
}
else /* initialize stream as if in the default case */
}
}
bufsize = 0;
/* see if memory mapping is possible (see sfwrite for SF_BOTH) */
/* save old buffer info */
#ifdef MAP_TYPE
{ if(f->data)
}
} else
#endif
f->size = 0;
}
size = 0;
/* set disc to the first discipline with a seekf */
break;
{ /* ASSERT(f->file >= 0) */
/* if has discipline, set size by discipline if possible */
goto unseekable;
else
{ Sfoff_t e;
goto setbuf;
}
}
/* get file descriptor status */
f->here = -1;
else
{
#endif
okmmap = 0;
else f->here = -1;
#if O_TEXT /* no memory mapping with O_TEXT because read()/write() alter data stream */
okmmap = 0;
#endif
}
#if SFSETLINEMODE
if(init)
f->flags |= sfsetlinemode();
#endif
if(f->here >= 0)
/* seekable std-devices are share-public by default */
}
else
{
f->extent = -1;
f->here = 0;
if(init)
/* set line mode for terminals */
#if _sys_stat
if(!null_checked)
null_checked = -1;
else
{ null_checked = 1;
}
}
SFSETNULL(f);
}
#endif
}
/* initialize side buffer for r+w unseekable streams */
}
}
/* set page size, this is also the desired default buffer size */
if(_Sfpage <= 0)
{
#if _lib_getpagesize
#endif
}
}
#ifdef MAP_TYPE
{ /* see if we can try memory mapping */
if(!disc)
break;
if(!disc)
}
}
}
#endif
/* get buffer space */
{ /* define a default size suitable for block transfer */
size = 0;
}
sf_malloc = 0;
{ /* try to allocate a buffer */
}
if(!buf)
{ /* do allocation */
break;
else size /= 2;
}
if(size > 0)
}
}
{ /* use the internal buffer */
}
/* set up new buffer */
{ /* these fields are used to test actual size - see sfseek() */
f->here = 0;
/* read+string stream should have all data available */
}
}
done:
/* blksz is used for aligning disk block boundary while reading data to
** optimize data transfer from disk (eg, via direct I/O). blksz can be
** at most f->size/2 so that data movement in buffer can be optimized.
** blksz should also be a power-of-2 for optimal disk seeks.
*/
blksz /= 2;
}