Commit 53592a6e authored by Jonas Termansen's avatar Jonas Termansen

Fix getdelim(3) not returning a final line without a delimiter.

parent 6d15ed57
/*
* Copyright (c) 2011, 2012, 2014, 2015 Jonas 'Sortie' Termansen.
* Copyright (c) 2011, 2012, 2014, 2015, 2018 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
......@@ -57,11 +57,12 @@ ssize_t getdelim(char** lineptr, size_t* n, int delim, FILE* fp)
}
if ( (c = getc_unlocked(fp)) == EOF )
{
if ( !written || feof_unlocked(fp) )
if ( !written || ferror_unlocked(fp) )
{
funlockfile(fp);
return -1;
}
break;
}
(*lineptr)[written++] = c;
} while ( c != delim );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment