changeset 2670:f6f2871d77c2

[gaim-migrate @ 2683] "just come a little closer" committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sun, 04 Nov 2001 10:46:39 +0000
parents 44773c4b0f16
children ffa58bbe595d
files plugins/lagmeter.c src/gtkspell.c
diffstat 2 files changed, 35 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/lagmeter.c	Sun Nov 04 07:42:28 2001 +0000
+++ b/plugins/lagmeter.c	Sun Nov 04 10:46:39 2001 +0000
@@ -79,6 +79,7 @@
 		ms += tv.tv_usec - my_lag_tv.tv_usec;
 
 		update_lag(ms);
+		g_free(*message);
 		*message = NULL;
 	}
 	g_free(name);
--- a/src/gtkspell.c	Sun Nov 04 07:42:28 2001 +0000
+++ b/src/gtkspell.c	Sun Nov 04 10:46:39 2001 +0000
@@ -76,26 +76,44 @@
 }
 
 static char *readline() {
-	int len = 1024;
-	gchar *buf = g_malloc(len);
-	int pos = 0;
-	do {
-		int val = read(fd_read[0], buf + pos, 1);
-		if (val <= 0) {
+	static gchar *buf = NULL;
+	char *end;
+	char *ret;
+	char *tmp;
+
+	/* read until we get a newline */
+	while (!buf || (end = strchr(buf, '\n')) == NULL) {
+		char space[1024];
+		int ret = read(fd_read[0], space, 1023);
+		if (ret < 0) {
 			error_print("read: %s\n", strerror(errno));
-			g_free(buf);
 			return NULL;
 		}
-		pos += val;
-		if (pos == len) {
-			len *= 2;
-			buf = g_realloc(buf, len);
-		}
-	} while (buf[pos - 1] != '\n');
+		space[ret] = 0;
+		if (buf) {
+			tmp = buf;
+			buf = g_strconcat(tmp, space, NULL);
+			g_free(tmp);
+		} else
+			buf = g_strdup(space);
+	}
+
+	/* we got a newline, and end points to it.
+	 * copy out the data, reset buf, return */
 
-	buf = g_realloc(buf, pos + 1);
-	buf[pos] = 0;
-	return buf;
+	if (end[1] == 0) {
+		/* only one line is in the buffer */
+		ret = buf;
+		buf = NULL;
+		return ret;
+	}
+
+	ret = g_strndup(buf, end - buf + 1);
+	tmp = buf;
+	buf = g_strdup(end + 1);
+	g_free(tmp);
+
+	return ret;
 }
 
 static char *readresponse() {