'\" te .\" Copyright 1989 AT&T Copyright (c) 2001, Sun Microsystems, Inc. All Rights Reserved .TH bgets 3GEN "9 May 2001" "SunOS 5.11" "String Pattern-Matching Library Functions" .SH NAME bgets \- read stream up to next delimiter .SH SYNOPSIS .LP .nf cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lgen\fR [ \fIlibrary\fR ... ] #include \fBchar *\fR\fBbgets\fR(\fBchar *\fR\fIbuffer\fR, \fBsize_t\fR \fIcount\fR, \fBFILE *\fR\fIstream\fR, \fBconst char *\fR\fIbreakstring\fR); .fi .SH DESCRIPTION .sp .LP The \fBbgets()\fR function reads characters from \fIstream\fR into \fIbuffer\fR until either \fIcount\fR is exhausted or one of the characters in \fIbreakstring\fR is encountered in the stream. The read data is terminated with a null byte ('\fB\e0\fR\&') and a pointer to the trailing null is returned. If a \fIbreakstring\fR character is encountered, the last non-null is the delimiter character that terminated the scan. .sp .LP Note that, except for the fact that the returned value points to the \fBend\fR of the read string rather than to the beginning, the call .sp .in +2 .nf bgets(buffer, sizeof buffer, stream, "\en"); .fi .in -2 .sp .LP is identical to .sp .in +2 .nf fgets (buffer, sizeof buffer, stream); .fi .in -2 .sp .LP There is always enough room reserved in the buffer for the trailing null character. .sp .LP If \fIbreakstring\fR is a null pointer, the value of \fIbreakstring\fR from the previous call is used. If \fIbreakstring\fR is null at the first call, no characters will be used to delimit the string. .SH RETURN VALUES .sp .LP \fINULL\fR 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 EXAMPLES .LP \fBExample 1 \fRExample of the \fBbgets()\fR function. .sp .LP The following example prints the name of the first user encountered in \fB/etc/passswd\fR, including a trailing ":" .sp .in +2 .nf #include #include int main() { char buffer[8]; FILE *fp; if ((fp = fopen("/etc/passwd","r")) == NULL) { perror("/etc/passwd"); return 1; } if (bgets(buffer, 8, fp, ":") == NULL) { perror("bgets"); return 1; } (void) puts(buffer); return 0; } .fi .in -2 .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPEATTRIBUTE VALUE _ MT-LevelMT-Safe .TE .SH SEE ALSO .sp .LP \fBgets\fR(3C), \fBattributes\fR(5) .SH NOTES .sp .LP When compiling multithread applications, the \fB_REENTRANT\fR flag must be defined on the compile line. This flag should only be used in multithreaded applications.