diff options
author | Richard M. Stallman <rms@gnu.org> | 1994-10-24 04:41:21 +0000 |
---|---|---|
committer | Richard M. Stallman <rms@gnu.org> | 1994-10-24 04:41:21 +0000 |
commit | 0b7203703c2d23d76d8da987bebcedb4814864cc (patch) | |
tree | 272a302fbc429bae80283aeabdc5b7ae435d0954 /lib-src/pop.c | |
parent | 0f74d35e13f60e00955d4f2c2075a2377f2ac5da (diff) | |
download | emacs-0b7203703c2d23d76d8da987bebcedb4814864cc.tar.gz |
(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/pop.c')
-rw-r--r-- | lib-src/pop.c | 19 |
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) #define GETLINE_ERROR "Error reading from server: " int ret; - + int search_offset = 0; + if (server->data) { char *cp = find_crlf (server->buffer + server->buffer_index); @@ -1208,6 +1209,14 @@ getline (server) { bcopy (server->buffer + server->buffer_index, server->buffer, server->data); + /* Record the fact that we've searched the data already in + the buffer for a CRLF, so that when we search below, we + don't have to search the same data twice. There's a "- + 1" here to account for the fact that the last character + of the data we have may be the CR of a CRLF pair, of + which we haven't read the second half yet, so we may have + to search it again when we read more data. */ + search_offset = server->data - 1; server->buffer_index = 0; } } @@ -1218,7 +1227,10 @@ getline (server) while (1) { - if (server->data == server->buffer_size) + /* There's a "- 1" here to leave room for the null that we put + at the end of the read data below. We put the null there so + that find_crlf knows where to stop when we call it. */ + if (server->data == server->buffer_size - 1) { server->buffer_size += GETLINE_INCR; server->buffer = realloc (server->buffer, server->buffer_size); @@ -1251,7 +1263,7 @@ getline (server) server->data += ret; server->buffer[server->data] = '\0'; - cp = find_crlf (server->buffer); + cp = find_crlf (server->buffer + search_offset); if (cp) { int data_used = (cp + 2) - server->buffer; @@ -1263,6 +1275,7 @@ getline (server) fprintf (stderr, "<<< %s\n", server->buffer); return (server->buffer); } + search_offset += ret; } } |