add a few last tweaks to ngetdelim()

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1901 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2004-08-17 16:00:29 +00:00
parent a27bd65057
commit 95f3812db1
2 changed files with 7 additions and 9 deletions

View File

@ -236,7 +236,7 @@ CVS code -
ngetdelim(), ngetline() ngetdelim(), ngetline()
- New functions equivalent to getdelim() and getline(), which - New functions equivalent to getdelim() and getline(), which
are both GNU extensions. (DLR, adapted from GNU mailutils are both GNU extensions. (DLR, adapted from GNU mailutils
0.5) 0.5 with minor changes to better integrate with nano)
- winio.c: - winio.c:
get_kbinput() get_kbinput()
- Since the only valid values for escapes are 0, 1, and 2, - Since the only valid values for escapes are 0, 1, and 2,

View File

@ -254,8 +254,6 @@ ssize_t ngetline(char **lineptr, size_t *n, FILE *stream)
* GNU mailutils' getdelim() function. */ * GNU mailutils' getdelim() function. */
ssize_t ngetdelim(char **lineptr, size_t *n, int delim, FILE *stream) 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; size_t indx = 0;
int c; int c;
@ -265,15 +263,15 @@ ssize_t ngetdelim(char **lineptr, size_t *n, int delim, FILE *stream)
/* Allocate the line the first time. */ /* Allocate the line the first time. */
if (*lineptr == NULL) { if (*lineptr == NULL) {
*lineptr = charalloc(line_size); *lineptr = charalloc(128);
*n = line_size; *n = 128;
} }
while ((c = getc(stream)) != EOF) { while ((c = getc(stream)) != EOF) {
/* Check if more memory is needed. */ /* Check if more memory is needed. */
if (indx >= *n) { if (indx >= *n) {
*lineptr = charealloc(*lineptr, *n + line_size); *lineptr = charealloc(*lineptr, *n + 128);
*n += line_size; *n += 128;
} }
/* Push the result in the line. */ /* 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. */ /* Make room for the null character. */
if (indx >= *n) { if (indx >= *n) {
*lineptr = charealloc(*lineptr, *n + line_size); *lineptr = charealloc(*lineptr, indx + 1);
*n += line_size; *n = indx + 1;
} }
/* Null terminate the buffer. */ /* Null terminate the buffer. */