From c60e33c0ee9d866293c0e423d6c14e7c49f76430 Mon Sep 17 00:00:00 2001 From: isaac Date: Thu, 23 Feb 2006 08:28:15 +0000 Subject: [PATCH] r=liangzhen readline() should return NULL when EOF and the last line if empty, otherwise Parser_commands() will loop forever waiting for a NULL return from readline(). --- lustre/utils/parser.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lustre/utils/parser.c b/lustre/utils/parser.c index 513a5d7..2cb518d 100644 --- a/lustre/utils/parser.c +++ b/lustre/utils/parser.c @@ -333,6 +333,7 @@ char * readline(char * prompt) char *line = malloc(size); char *ptr = line; int c; + int eof = 0; if (line == NULL) return NULL; @@ -358,6 +359,7 @@ char * readline(char * prompt) line = tmp; } } else { + eof = 1; if (ferror(stdin)) goto outfree; goto out; @@ -365,6 +367,10 @@ char * readline(char * prompt) } out: *ptr = 0; + if (eof && (strlen(line) == 0)) { + free(line); + line = NULL; + } return line; outfree: free(line); -- 1.8.3.1