
/*
   utilities for hacking on streamoids 
*/

#include "io-defs.h"

extern char * realloc();

/*
   set the buf size for this streamoid.  if there's a buf there, adjust
   it (up only).  return size set, or -1 if losing.
*/
int set_stream_buffer_size(s, n)
struct streamoid * s;
int n;
{
  if (n < 0)
	return(-1);			/* bogus value */

  if (s->flags & STR_BUFFERED_P)
	{
	if (n > 0)			/* adjust size in existing stream */
		{
		if (n > s->buffer_size)	/* need to make buf bigger? */
			{
			s->buffer = realloc(s->buffer, n);
			}
		return(s->buffer_size = n);
		}
	    else			/* make it unbuffered... later */
		{
		return(s->buffer_size);
		}
	}
    else
	{
	if (n > 0)			/* make it buffered? */
		{
		return(0);		/* later */
		}
	    else			/* no op */
		{
		return(0);
		}
	}
}

int stream_readable_p(s)
struct streamoid * s;
{
  return(s->flags & STR_INPUT_P ? 1 : 0);
}

int stream_writable_p(s)
struct streamoid * s;
{
  return(s->flags & STR_OUTPUT_P ? 1 : 0);
}

