From: David Lawrence Ramsey Date: Tue, 17 Aug 2004 16:00:29 +0000 (+0000) Subject: add a few last tweaks to ngetdelim() X-Git-Tag: v1.3.4~5 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=95f3812db1d318433185bd104c8f0a4912f9f985;p=nano.git add a few last tweaks to ngetdelim() git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1901 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 700f5108..caf9ea8f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -236,7 +236,7 @@ CVS code - ngetdelim(), ngetline() - New functions equivalent to getdelim() and getline(), which are both GNU extensions. (DLR, adapted from GNU mailutils - 0.5) + 0.5 with minor changes to better integrate with nano) - winio.c: get_kbinput() - Since the only valid values for escapes are 0, 1, and 2, diff --git a/src/utils.c b/src/utils.c index 5619f936..d11465dc 100644 --- a/src/utils.c +++ b/src/utils.c @@ -254,8 +254,6 @@ ssize_t ngetline(char **lineptr, size_t *n, FILE *stream) * GNU mailutils' getdelim() function. */ ssize_t ngetdelim(char **lineptr, size_t *n, int delim, FILE *stream) { - static const int line_size = 128; - /* Default value for line length. */ size_t indx = 0; int c; @@ -265,15 +263,15 @@ ssize_t ngetdelim(char **lineptr, size_t *n, int delim, FILE *stream) /* Allocate the line the first time. */ if (*lineptr == NULL) { - *lineptr = charalloc(line_size); - *n = line_size; + *lineptr = charalloc(128); + *n = 128; } while ((c = getc(stream)) != EOF) { /* Check if more memory is needed. */ if (indx >= *n) { - *lineptr = charealloc(*lineptr, *n + line_size); - *n += line_size; + *lineptr = charealloc(*lineptr, *n + 128); + *n += 128; } /* Push the result in the line. */ @@ -286,8 +284,8 @@ ssize_t ngetdelim(char **lineptr, size_t *n, int delim, FILE *stream) /* Make room for the null character. */ if (indx >= *n) { - *lineptr = charealloc(*lineptr, *n + line_size); - *n += line_size; + *lineptr = charealloc(*lineptr, indx + 1); + *n = indx + 1; } /* Null terminate the buffer. */