Fix readline() when fgets returns NULL even on success

Signed-off-by: Rafael Ravedutti <rafaelravedutti@gmail.com>
This commit is contained in:
Rafael Ravedutti 2022-11-30 17:43:35 +01:00
parent fa4e38c6c4
commit 416f042fc0

View File

@ -4,6 +4,7 @@
* Use of this source code is governed by a LGPL-3.0
* license that can be found in the LICENSE file.
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -84,7 +85,9 @@ int get_num_threads() {
void readline(char *line, FILE *fp) {
if(fgets(line, MAXLINE, fp) == NULL) {
fprintf(stderr, "readline(): Error: could not read line!\n");
if(errno != 0) {
perror("readline()");
exit(-1);
}
}
}