Fix readline() when fgets returns NULL even on success
Signed-off-by: Rafael Ravedutti <rafaelravedutti@gmail.com>
This commit is contained in:
		| @@ -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); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user