- while ((f = fgets(line_ptr, line_free, file)) != NULL) {
- /*
- * Note that we only have to search what we just read, not
- * the whole buffer.
- */
- if ((cp = strchr (line_ptr, '\n')) != NULL) {
- line_len += cp - line_ptr;
- *cp = '\0'; /* zap the newline */
- break; /* got to end of line */
- }
- line_len += line_free - 1; /* bytes read minus '\0' */
- size_save = line_size;
- if (line_size < 256 * AGETS_LINE_INCR) {
- line_size *= 2;
- } else {
- line_size += 256 * AGETS_LINE_INCR;
+ /*
+ * Reallocate input line.
+ * alloc() never return NULL pointer.
+ */
+ tmpline = alloc(line_size + AGETS_LINE_INCR);
+ memcpy(tmpline, line, line_size);
+ amfree(line);
+ line = tmpline;
+ line_size = line_size + AGETS_LINE_INCR;