Browse Source

Use getline in place of fgetln

master
Causal Agent 5 months ago
parent
commit
c4c4de6923
Signed by: Curtis McEnroe <june@causal.agency> GPG Key ID: CEA2F97ADCFCD77C
1 changed files with 7 additions and 5 deletions
  1. 7
    5
      log.c

+ 7
- 5
log.c View File

@@ -132,12 +132,14 @@ void logReplay(struct Tag tag) {
132 132
 	FILE *file = logFile(tag, time);
133 133
 	rewind(file);
134 134
 
135
-	size_t len;
136
-	char *line;
137
-	while (NULL != (line = fgetln(file, &len))) {
135
+	char *line = NULL;
136
+	size_t cap = 0;
137
+	ssize_t len;
138
+	while (0 < (len = getline(&line, &cap, file))) {
139
+		if (len < 1 + StampLen + 2 + 1) continue;
138 140
 		line[len - 1] = '\0';
139
-		if (len > 1 + StampLen + 2) line = &line[1 + StampLen + 2];
140
-		uiFmt(tag, UICold, "\3%d%s", IRCGray, line);
141
+		uiFmt(tag, UICold, "\3%d%s", IRCGray, &line[1 + StampLen + 2]);
141 142
 	}
142 143
 	if (ferror(file)) err(EX_IOERR, "%s", tag.name);
144
+	free(line);
143 145
 }

Loading…
Cancel
Save