Преглед изворни кода

coroparse: Handle different EOLs and pass error_string

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2186 fd59a12c-fef9-0310-b244-a6a79926bd2f
Jan Friesse пре 16 година
родитељ
комит
94b64352a4
1 измењених фајлова са 11 додато и 5 уклоњено
  1. 11 5
      exec/coroparse.c

+ 11 - 5
exec/coroparse.c

@@ -93,9 +93,13 @@ static int parse_section(FILE *fp,
 	int i;
 	char *loc;
 
-	while (fgets (line, 255, fp)) {
-		if (strlen(line) > 0)
-			line[strlen(line) - 1] = '\0';
+	while (fgets (line, sizeof (line), fp)) {
+		if (strlen(line) > 0) {
+			if (line[strlen(line) - 1] == '\n')
+				line[strlen(line) - 1] = '\0';
+			if (strlen (line) > 0 && line[strlen(line) - 1] == '\r')
+				line[strlen(line) - 1] = '\0';
+		}
 		/*
 		 * Clear out white space and tabs
 		 */
@@ -181,9 +185,11 @@ static int read_config_file_into_objdb(
 
 	fclose(fp);
 
-	snprintf (error_reason, sizeof(error_string_response),
+	if (res == 0) {
+		snprintf (error_reason, sizeof(error_string_response),
 			"Successfully read main configuration file '%s'.\n", filename);
-	*error_string = error_reason;
+		*error_string = error_reason;
+	}
 
 	return res;
 }