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