'\"macro stdmacro
.if n .pH g3g.bgets @(#)bgets	40.8 of 10/30/89
.\" Copyright 1989 AT&T
'''	ident	"@(#)libgen:doc/bgets.3G	1.1"
.nr X
.if \nX=0 .ds x} bgets 3G "" "\&"
.if \nX=1 .ds x} bgets 3G ""
.if \nX=2 .ds x} bgets 3G "" "\&"
.if \nX=3 .ds x} bgets "" "" "\&"
.TH \*(x}
.SH "NAME"
\f4bgets\f1 \- read stream up to next delimiter
.SH SYNOPSIS
\f4cc\f1 [\f2flag\fP \|.\|.\|.] \f2file\fP \|.\|.\|. \f4\-lgen\f1 [\f2library\fP \|.\|.\|.]
.PP
\f4#include <libgen.h>\f1
.PP
.nf
\f4char \(**bgets (char \(**buffer, size_t \(**count, FILE  \(**stream,
	const char \(**breakstring);\f1
.fi
.SH DESCRIPTION
\f4bgets\fP
reads characters from
.I stream
into
.I buffer
until either \f2count\f1 is exhausted or one of the characters in
.I breakstring
is encountered in the stream.  The read data is terminated with a null byte ('\f4\e0\f1')
and a pointer to the trailing null is returned.
If a
.I breakstring
character is encountered, the last non-null is the delimiter character that 
terminated the scan.
.PP
Note that, except for the fact that the returned value points to the
\f4end\fP
of the read string rather than to the beginning, the call
.PP
.RS
.ft 4
bgets (buffer, sizeof buffer, stream, "\en");
.ft 1
.RE
.PP
is identical to
.PP
.RS
.ft 4
fgets (buffer, sizeof buffer, stream);
.ft 1
.RE
.PP
There is always enough room reserved in the buffer for the trailing
null.
.P
If \f2breakstring\f1 is a null pointer, the value of \f2breakstring\f1
from the previous call is used.  If \f2breakstring\f1 is null at the
first call, no characters will be used to delimit the string.
.SH EXAMPLES
.ft 4
.nf
#include	<libgen.h>

char buffer[8];
/\(** read in first user name from /etc/passwd \(**/
fp = fopen("/etc/passwd","r");
bgets(buffer, 8, fp, ":");
.fi
.ft 1
.SH DIAGNOSTICS
\f4NULL\f1
is returned on error or end-of-file.  Reporting the condition is delayed to the next 
call if any characters were read but not yet returned.
.SH "SEE ALSO"
\f4gets\fP(3S).
