[net.unix] 4.2BSB Buffered I/O buffersize

jayr@well.UUCP (Jay Roth) (01/25/86)

I've got a program that is having trouble getting input because of the 
limitations of the input buffer for buffered i/o (about 256), I'm occasionally
getting myself into trouble.

1) Is there a way to change the buffersize for reading input?
2) Is there a non-buffered way to do this?

I want to read up to (and including) a carriage return (equivalent to gets).
Any ideas?  Thanks in advance.

jsdy@hadron.UUCP (01/28/86)

'man 3 setbuf' ...
setbuf(fd, (char *) NULL); will set input and output to be
unbuffered.  It is not clear whether the 4.2-only functions
setbuffer() (to change buffer size) and setlinebuf() work
on input as well as output.  The former is documented to do
so; the latter is documented only to work on stderr and stdout.
Be bold.  Experiment a little.
-- 

	Joe Yao		hadron!jsdy@seismo.{CSS.GOV,ARPA,UUCP}

meissner@datagen.UUCP (01/29/86)

In article <546@well.UUCP> jayr@well.UUCP writes:
>I've got a program that is having trouble getting input because of the 
>limitations of the input buffer for buffered i/o (about 256), I'm occasionally
>getting myself into trouble.
>
>1) Is there a way to change the buffersize for reading input?
>2) Is there a non-buffered way to do this?
>
>I want to read up to (and including) a carriage return (equivalent to gets).
>Any ideas?  Thanks in advance.

    #1	If you are using system V.2 (also in forthcoming ANSI std):
		setvbuf( FILE *stream, char *buf, int type, int size );
	where:
		stream is FILE * you want to change the buffering on
		buf    is either the buffer to use or NULL (malloc buffer)
		type   is one of:
				_IONBF	no buffering
				_IOLBF	line buffer (output only I think)
				_IOFBF	full buffer
		size   is the buffer size to use

	If you are using BSD 4.[12]:
		setbuffer( FILE *stream, char *buf, int size );

    #2	Use read instead of stdio.

Michael Meissner, Data General

ka@hropus.UUCP (Kenneth Almquist) (01/31/86)

> I've got a program that is having trouble getting input because of the 
> limitations of the input buffer for buffered i/o (about 256), I'm
> occasionally getting myself into trouble.

I assume that you are reading from a terminal.  In this case, the
problem is that the terminal driver will only buffer 256 characters.
Since the terminal driver will not pass any characters back to your
program until a carriage return is typed, if you type more than 256
characters without typing a carriage return you will hit this limit.

The limit can be changed by changing a constant in the kernel and
rebuilding your operating system.  The alternative to this is to set
CBREAK mode on your tty using the stty system call; this will cause
the characters to be passed to your program as they are typed.  When
you are in CBREAK mode the driver will not perform normal erase and
kill processing for the simple reason that the driver cannot delete
input that it has already passed to your program.  Thus you will have
to implement erase and kill processing in your program if you need it.
				Kenneth Almquist
				ihnp4!houxm!hropus!ka	(official name)
				ihnp4!opus!ka		(shorter path)

gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) (02/02/86)

>     #1	If you are using system V.2 (also in forthcoming ANSI std):
> 		setvbuf( FILE *stream, char *buf, int type, int size );

Note that setvbuf() as distributed with SVR2 was quite broken.
Some time ago I posted a replacement to net.bugs.usg.