Commit cb247618 cb24761827f2e55a8f3297a6ddd78a0d52f8908a by Sergey Poznyakoff

(_auth_lb_writelines): New function.

1 parent b637f9c8
...@@ -110,7 +110,46 @@ _auth_lb_readline (struct _line_buffer *s, const char *ptr, size_t size) ...@@ -110,7 +110,46 @@ _auth_lb_readline (struct _line_buffer *s, const char *ptr, size_t size)
110 size = p - s->buffer + 1; 110 size = p - s->buffer + 1;
111 return _auth_lb_read (s, ptr, size); 111 return _auth_lb_read (s, ptr, size);
112 } 112 }
113 113
114 int
115 _auth_lb_writelines (struct _line_buffer *s, const char *iptr, size_t isize,
116 off_t offset,
117 int (*wr) (void *data, char *start, char *end),
118 void *data,
119 size_t *nbytes)
120 {
121 if (s->level > 2)
122 {
123 char *start, *end;
124
125 for (start = s->buffer, end = strchr (start, '\n');
126 end && end < s->buffer + s->level;
127 start = end + 1, end = strchr (start, '\n'))
128 if (end[-1] == '\r')
129 {
130 int rc = wr (data, start, end);
131 if (rc)
132 return rc;
133 }
134
135 if (start > s->buffer)
136 {
137 if (start < s->buffer + s->level)
138 {
139 int rest = s->buffer + s->level - start + 1;
140 memmove (s->buffer, start, rest);
141 s->level = rest;
142 }
143 else
144 s->level = 0;
145 }
146 }
147
148 if (nbytes)
149 *nbytes = isize;
150 return 0;
151 }
152
114 int 153 int
115 _auth_lb_level (struct _line_buffer *s) 154 _auth_lb_level (struct _line_buffer *s)
116 { 155 {
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2003 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
1 struct _line_buffer; 18 struct _line_buffer;
2 19
3 int _auth_lb_create (struct _line_buffer **s); 20 int _auth_lb_create __P((struct _line_buffer **s));
4 void _auth_lb_destroy (struct _line_buffer **s); 21 void _auth_lb_destroy __P((struct _line_buffer **s));
5 void _auth_lb_drop (struct _line_buffer *s); 22 void _auth_lb_drop __P((struct _line_buffer *s));
6 23
7 int _auth_lb_grow (struct _line_buffer *s, const char *ptr, size_t size); 24 int _auth_lb_grow __P((struct _line_buffer *s, const char *ptr, size_t size));
8 int _auth_lb_read (struct _line_buffer *s, const char *ptr, size_t size); 25 int _auth_lb_read __P((struct _line_buffer *s, const char *ptr, size_t size));
9 int _auth_lb_readline (struct _line_buffer *s, const char *ptr, size_t size); 26 int _auth_lb_readline __P((struct _line_buffer *s, const char *ptr,
10 int _auth_lb_level (struct _line_buffer *s); 27 size_t size));
11 char *_auth_lb_data (struct _line_buffer *s); 28 int _auth_lb_writelines __P((struct _line_buffer *s, const char *iptr,
29 size_t isize, off_t offset,
30 int (*wr) __PMT ((void *data, char *start,
31 char *end)),
32 void *data, size_t *nbytes));
33 int _auth_lb_level __P((struct _line_buffer *s));
34 char *_auth_lb_data __P((struct _line_buffer *s));
12 35
13 36
......