Fix readline() when fgets returns NULL even on success
Signed-off-by: Rafael Ravedutti <rafaelravedutti@gmail.com>
This commit is contained in:
parent
fa4e38c6c4
commit
416f042fc0
@ -4,6 +4,7 @@
|
|||||||
* Use of this source code is governed by a LGPL-3.0
|
* Use of this source code is governed by a LGPL-3.0
|
||||||
* license that can be found in the LICENSE file.
|
* license that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -84,7 +85,9 @@ int get_num_threads() {
|
|||||||
|
|
||||||
void readline(char *line, FILE *fp) {
|
void readline(char *line, FILE *fp) {
|
||||||
if(fgets(line, MAXLINE, fp) == NULL) {
|
if(fgets(line, MAXLINE, fp) == NULL) {
|
||||||
fprintf(stderr, "readline(): Error: could not read line!\n");
|
if(errno != 0) {
|
||||||
|
perror("readline()");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user