[Devel] [PATCH 4/4] read_dist_actions(): remove needless code

Igor Podlesny openvz at poige.ru
Tue May 14 22:22:08 PDT 2013


We don't need to call feof() on each and every line since
fgets() already handles it by itself.

There's also no point in pre-setting buf[0] -- fgets() would overwrite it
anyways if successfull.
---
 src/lib/dist.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/lib/dist.c b/src/lib/dist.c
index 3ed7347..8f37a9c 100644
--- a/src/lib/dist.c
+++ b/src/lib/dist.c
@@ -159,10 +159,7 @@ int read_dist_actions(char *dist_name, char *dir, dist_actions *actions)
 		logger(-1, errno, "Unable to open %s", file);
 		return VZ_NO_DISTR_CONF;
 	}
-	while (!feof(fp)) {
-		buf[0] = 0;
-		if (fgets(buf, sizeof(buf), fp) == NULL)
-			break;
+	while (fgets(buf, sizeof(buf), fp) != NULL) {
 		line++;
 		rtoken = parse_line(buf, ltoken, sizeof(ltoken), &parse_err);
 		if (rtoken == NULL) {
-- 
1.7.9.5




More information about the Devel mailing list