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. */