summaryrefslogtreecommitdiff
path: root/man/getln.3
blob: 01f8b895789b04125a1d9680162acfc338ec45ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
.TH glibs: getln 3
.SH NAME
getln \ - read one line of data  
.SH SYNTAX
.B #include \(dqgetln.h\(dq

int \fBgetln\fP(&buf,&sa,&match,sep);
.br
int \fBgetln2\fP(&buf,&sa,&cont,&clen,sep);

buffer \fIbuf\fR; 
.br
stralloc \fIsa\fR; 
.br
int \fImatch\fR; 
.br
int \fIsep\fR;  
.br
char *\fIcont\fR; 
.br
unsigned int \fIclen\fR; 
.SH DESCRIPTION
.B getln 
reads a line of characters, terminated by a sep character, from 
.IR buf . 
It returns the line in 
.I sa 
and sets match to 
.IR 1 .
If 
.B getln 
sees end-of-input before it sees 
.IR sep , 
it returns the partial line in 
.I sa 
and sets match to
.IR  0 .

.B getln2 
reads a line of characters, terminated by a 
.I sep 
character from 
.IR buf .
The line is returned in two pieces. The first piece is stored in 
.IR sa . 
The second piece is 
.IR cont , 
a pointer to 
.I clen 
characters inside 
.IR buf .
The second piece must be copied somewhere else before 
.I sa 
is used again.
If 
.B getln2 
sees end-of-input before it sees 
.IR sep , 
it sets 
.I clen 
to 
.I 0 
and does not set 
.IR cont . 
It puts the partial line into 
.IR sa.
.SH "BUFFER"
.I buf
can be a pre-allocated buffer like
.I buffer_0 
reading from
.I STDIN 
or any other explicitly generated buffer on a given file descriptor.
.SH "RETURN CODES"
.B getln 
normally returns 
.IR 0 . 
If it runs out of memory, or encounters an error from 
.IR sa , 
it returns 
.IR -1 , 
setting 
.I errno 
appropriately.  

.B getln2 
normally returns 
.IR 0 . 
If it runs out of memory, or encounters an error from 
.IR sa , 
it returns 
.IR -1 , 
setting 
.I errno 
appropriately.  
.SH CREDITS
The
.B getln 
and
.B getln2
man page were taken from Bruce Guenther and 
originally published by Dan Bernstein for qmail-1.03.
.SH SEE ALSO
stralloc(3), buffer(3).