posix: Fix getline
@@ -1016,8 +1016,6 @@ ssize_t getdelim(char **line, size_t *n, int delim, FILE *stream) {
return -1;
}
- constexpr size_t chunk = 1024;
-
char *buffer = *line;
size_t capacity = *n, nwritten = 0;
@@ -1034,7 +1032,7 @@ ssize_t getdelim(char **line, size_t *n, int delim, FILE *stream) {
while (true) {
// Fill the buffer
- while (capacity > 0 && nwritten < capacity - 1) {
+ while (buffer && capacity > 0 && nwritten < capacity - 1) {
auto c = fgetc_unlocked(stream);
if (ferror(stream)) {
return -1;
@@ -1053,7 +1051,7 @@ ssize_t getdelim(char **line, size_t *n, int delim, FILE *stream) {
// Double the size of the buffer (but make sure it's at least 1024)
capacity = (capacity >= 1024) ? capacity * 2 : 1024;
- buffer = reinterpret_cast<char *>(getAllocator().reallocate(*line, capacity));
+ buffer = reinterpret_cast<char *>(realloc(*line, capacity));
if (!buffer) {
errno = ENOMEM;
return -1;
