aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorRichard M. Stallman1994-10-24 04:41:21 +0000
committerRichard M. Stallman1994-10-24 04:41:21 +0000
commitb6606ad82121b79500fcb7e6951341a6faae2047 (patch)
treef6898123b7bc25e50af9ed65eef632de9103bf43 /lib-src
parentc3a646c2abf74ab099670c5f47346f6e141a76da (diff)
downloademacs-b6606ad82121b79500fcb7e6951341a6faae2047.tar.gz
emacs-b6606ad82121b79500fcb7e6951341a6faae2047.zip
(getline): When a search of already-read input for CRLF
fails, store the fact that we've searched it and don't search it again after reading more data. (getline): When determining whether or not it's necessary to grow the input buffer, take into account the null that's stored at the end of already-read input in the buffer.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/pop.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib-src/pop.c b/lib-src/pop.c
index 878de5efc8d..125df24f130 100644
--- a/lib-src/pop.c
+++ b/lib-src/pop.c
@@ -1184,7 +1184,8 @@ getline (server)
1184#define GETLINE_ERROR "Error reading from server: " 1184#define GETLINE_ERROR "Error reading from server: "
1185 1185
1186 int ret; 1186 int ret;
1187 1187 int search_offset = 0;
1188
1188 if (server->data) 1189 if (server->data)
1189 { 1190 {
1190 char *cp = find_crlf (server->buffer + server->buffer_index); 1191 char *cp = find_crlf (server->buffer + server->buffer_index);
@@ -1208,6 +1209,14 @@ getline (server)
1208 { 1209 {
1209 bcopy (server->buffer + server->buffer_index, 1210 bcopy (server->buffer + server->buffer_index,
1210 server->buffer, server->data); 1211 server->buffer, server->data);
1212 /* Record the fact that we've searched the data already in
1213 the buffer for a CRLF, so that when we search below, we
1214 don't have to search the same data twice. There's a "-
1215 1" here to account for the fact that the last character
1216 of the data we have may be the CR of a CRLF pair, of
1217 which we haven't read the second half yet, so we may have
1218 to search it again when we read more data. */
1219 search_offset = server->data - 1;
1211 server->buffer_index = 0; 1220 server->buffer_index = 0;
1212 } 1221 }
1213 } 1222 }
@@ -1218,7 +1227,10 @@ getline (server)
1218 1227
1219 while (1) 1228 while (1)
1220 { 1229 {
1221 if (server->data == server->buffer_size) 1230 /* There's a "- 1" here to leave room for the null that we put
1231 at the end of the read data below. We put the null there so
1232 that find_crlf knows where to stop when we call it. */
1233 if (server->data == server->buffer_size - 1)
1222 { 1234 {
1223 server->buffer_size += GETLINE_INCR; 1235 server->buffer_size += GETLINE_INCR;
1224 server->buffer = realloc (server->buffer, server->buffer_size); 1236 server->buffer = realloc (server->buffer, server->buffer_size);
@@ -1251,7 +1263,7 @@ getline (server)
1251 server->data += ret; 1263 server->data += ret;
1252 server->buffer[server->data] = '\0'; 1264 server->buffer[server->data] = '\0';
1253 1265
1254 cp = find_crlf (server->buffer); 1266 cp = find_crlf (server->buffer + search_offset);
1255 if (cp) 1267 if (cp)
1256 { 1268 {
1257 int data_used = (cp + 2) - server->buffer; 1269 int data_used = (cp + 2) - server->buffer;
@@ -1263,6 +1275,7 @@ getline (server)
1263 fprintf (stderr, "<<< %s\n", server->buffer); 1275 fprintf (stderr, "<<< %s\n", server->buffer);
1264 return (server->buffer); 1276 return (server->buffer);
1265 } 1277 }
1278 search_offset += ret;
1266 } 1279 }
1267 } 1280 }
1268 1281