Fix getdelim(3) not returning a final line without a delimiter.
This commit is contained in:
parent
6d15ed575f
commit
53592a6e3f
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* 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
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* 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 ( (c = getc_unlocked(fp)) == EOF )
|
||||||
{
|
{
|
||||||
if ( !written || feof_unlocked(fp) )
|
if ( !written || ferror_unlocked(fp) )
|
||||||
{
|
{
|
||||||
funlockfile(fp);
|
funlockfile(fp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
(*lineptr)[written++] = c;
|
(*lineptr)[written++] = c;
|
||||||
} while ( c != delim );
|
} while ( c != delim );
|
||||||
|
|
Loading…
Reference in New Issue