mirror of
git://git.sv.gnu.org/nano.git
synced 2024-12-24 03:16:52 +03:00
add a few last tweaks to ngetdelim()
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1901 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
parent
a27bd65057
commit
95f3812db1
@ -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,
|
||||
|
14
src/utils.c
14
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. */
|
||||
|
Loading…
Reference in New Issue
Block a user