[PATCH phosphor-event] Limit logging

OpenBMC Patches openbmc-patches at stwcx.xyz
Fri Apr 29 12: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 | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/message.C b/message.C
index 1bf7d8b..2a5e530 100644
--- a/message.C
+++ b/message.C
@@ -180,13 +180,17 @@ inline uint16_t getlen(const char *s)
 
 size_t get_file_size(string fn)
 {
-	ifstream f;
-	size_t len=0;
+	struct stat f_stat;
+	int r;
 
-	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 getting log size: %s\n", strerror(-r));
+		return 0;
+	}
+
+	return (f_stat.st_size);
 }
 
 
-- 
2.8.1




More information about the openbmc mailing list