sgwdynspeed: fgets includes EOLs in the read string, strip them off
authorFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 17 Feb 2014 15:31:12 +0000 (16:31 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 17 Feb 2014 15:31:47 +0000 (16:31 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/sgwdynspeed/src/speedFile.c

index a26ecf2..0127f9e 100644 (file)
@@ -87,6 +87,19 @@ static bool readUL(const char * valueName, const char * value, unsigned long * v
        return true;
 }
 
+/**
+ * Strip EOL characters from a string
+ *
+ * @param str the string to strip
+ */
+static void stripEols(char * str) {
+  size_t len = strlen(str);
+  while ((str[len - 1] == '\n') || (str[len - 1] == '\r')) {
+    len--;
+  }
+  str[len] = '\0';
+}
+
 /**
  * Initialises the speedFile reader.
  * @return true upon success, false otherwise
@@ -211,6 +224,8 @@ void readSpeedFile(char * fileName) {
                        goto out;
                }
 
+               stripEols(line);
+
                /* determine name/value */
                name = &line[pmatch[1].rm_so];
                line[pmatch[1].rm_eo] = '\0';