Skip to contentSkip to conversation

kconfig: Fix ignoring return value warning

PATCH Jiri Kosina 1 participant 1 message Jul 11, 2010 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Hi Jean,

adding Michal (current kbuild maintainer) and linux-kbuild to CC. Thanks.

From: Jean Sacren <[email protected]>
Date: Fri, 9 Jul 2010 13:02:50 -0600
Subject: [PATCH 1/1] kconfig: Fix ignoring return value warning

This fix takes care of fwrite() either when it succeeds with writing or when an error occurs. Also more aesthetic syntax is entered for infinite loops.

---
 scripts/kconfig/confdata.c |   22 +++++++++++++++++-----
 scripts/kconfig/lkc.h      |    1 +
 2 files changed, 18 insertions(+), 5 deletions(-)
scripts/kconfig/confdata.c +17 -5
index c4dec80..c6871d9 100644
@@ -502,10 +502,10 @@ int conf_write(const char *name)
 			case S_STRING:
 				str = sym_get_string_value(sym);
 				fprintf(out, "CONFIG_%s=\"", sym->name);
-				while (1) {
+				for (;;) {
 					l = strcspn(str, "\"\\");
 					if (l) {
-						fwrite(str, l, 1, out);
+						xfwrite(str, l, 1, out);
 						str += l;
 					}
 					if (!*str)
@@ -753,11 +753,11 @@ int conf_write_autoconf(void)
 			str = sym_get_string_value(sym);
 			fprintf(out, "CONFIG_%s=\"", sym->name);
 			fprintf(out_h, "#define CONFIG_%s \"", sym->name);
-			while (1) {
+			for (;;) {
 				l = strcspn(str, "\"\\");
 				if (l) {
-					fwrite(str, l, 1, out);
-					fwrite(str, l, 1, out_h);
+					xfwrite(str, l, 1, out);
+					xfwrite(str, l, 1, out_h);
 					str += l;
 				}
 				if (!*str)
@@ -926,3 +926,15 @@ void conf_set_all_new_symbols(enum conf_def_mode mode)
 		csym->flags &= ~(SYMBOL_VALID);
 	}
 }
+/*
+ * Helper function to facilitate fwrite() by Jean Sacren.
+ */
+void xfwrite(xstr, len, count, output)
+	const void *xstr;
+	size_t len;
+	size_t count;
+	FILE *output;
+{
+	if (fwrite(xstr, len, count, output) < count)
+		fprintf(stderr, "\nError in writing.\n");
+}
scripts/kconfig/lkc.h +1 -0
index ce6549c..7d7061a 100644
@@ -79,6 +79,7 @@ char *conf_get_default_confname(void);
 void sym_set_change_count(int count);
 void sym_add_change_count(int count);
 void conf_set_all_new_symbols(enum conf_def_mode mode);
+void xfwrite(const void *xstr, size_t len, size_t count, FILE *output);
 
 /* kconfig_load.c */
 void kconfig_load(void);
Signature · 2 lines
Jiri Kosina
SUSE Labs, Novell Inc.