1bgets(3GEN)        String Pattern-Matching Library Functions       bgets(3GEN)
2
3
4

NAME

6       bgets - read stream up to next delimiter
7

SYNOPSIS

9       cc [ flag ... ] file ... -lgen [ library ... ]
10       #include <libgen.h>
11
12       char *bgets(char *buffer, size_t count, FILE  *stream,
13            const char *breakstring);
14
15

DESCRIPTION

17       The  bgets()  function  reads  characters from stream into buffer until
18       either count is exhausted or one of the characters  in  breakstring  is
19       encountered in the stream. The read data is terminated with a null byte
20       ('\0') and a pointer to the trailing null is returned. If a breakstring
21       character  is encountered, the last non-null is the delimiter character
22       that  terminated the scan.
23
24
25       Note that, except for the fact that the returned value  points  to  the
26       end of the read string rather than to the beginning, the call
27
28         bgets(buffer, sizeof buffer, stream, "\n");
29
30
31
32       is identical to
33
34         fgets (buffer, sizeof buffer, stream);
35
36
37
38       There  is  always  enough  room reserved in the buffer for the trailing
39       null character.
40
41
42       If breakstring is a null pointer, the value  of  breakstring  from  the
43       previous  call  is  used.  If breakstring is null at the first call, no
44       characters will be used to delimit the string.
45

RETURN VALUES

47       NULL is returned on error or end-of-file.  Reporting the  condition  is
48       delayed  to  the  next   call  if  any characters were read but not yet
49       returned.
50

EXAMPLES

52       Example 1 Example of the bgets() function.
53
54
55       The following example prints the name of the first user encountered  in
56       /etc/passswd, including a trailing ":"
57
58
59         #include <stdio.h>
60         #include<libgen.h>
61
62         int main()
63         {
64             char buffer[8];
65             FILE *fp;
66
67             if ((fp = fopen("/etc/passwd","r")) == NULL) {
68                 perror("/etc/passwd");
69                 return 1;
70             }
71             if (bgets(buffer, 8, fp, ":") == NULL) {
72                 perror("bgets");
73                 return 1;
74             }
75             (void) puts(buffer);
76             return 0;
77         }
78
79

ATTRIBUTES

81       See attributes(5) for descriptions of the following attributes:
82
83
84
85
86       ┌─────────────────────────────┬─────────────────────────────┐
87       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
88       ├─────────────────────────────┼─────────────────────────────┤
89       │MT-Level                     │MT-Safe                      │
90       └─────────────────────────────┴─────────────────────────────┘
91

SEE ALSO

93       gets(3C), attributes(5)
94

NOTES

96       When  compiling  multithread  applications, the _REENTRANT flag must be
97       defined on the compile line.  This flag should only be used  in  multi‐
98       threaded applications.
99
100
101
102SunOS 5.11                        9 May 2001                       bgets(3GEN)
Impressum