[PATCH phosphor-event v2] Limit logging

OpenBMC Patches openbmc-patches at stwcx.xyz
Fri Apr 29 18:50:37 AEST 2016


From: Nan Li <bjlinan at cn.ibm.com>

1. Change open/tellg/close to a single stat.

Signed-off-by: Nan Li <bjlinan at cn.ibm.com>
---
 message.C | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/message.C b/message.C
index 1bf7d8b..87fb856 100644
--- a/message.C
+++ b/message.C
@@ -178,15 +178,23 @@ inline uint16_t getlen(const char *s)
 }
 
 
+/* If everything is working correctly, return file size, */
+/* Otherwise return 0 */
 size_t get_file_size(string fn)
 {
-	ifstream f;
-	size_t len=0;
+	struct stat f_stat;
+	int r = -1;
 
-	f.open(fn, ios::in|ios::binary|ios::ate);
-	len = f.tellg();
-	f.close();
-	return (len);
+	r = stat(fn.c_str(), &f_stat);
+
+	if (r < 0) {
+		fprintf(stderr, "Error get_file_size() for %s, %s\n",
+				fn.c_str(),
+				strerror(errno));
+		return 0;
+	}
+
+	return (f_stat.st_size);
 }
 
 
-- 
2.8.1




More information about the openbmc mailing list