about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMarco Peereboom <marco@conformal.com>2012-01-04 15:50:18 -0600
committerMarco Peereboom <marco@conformal.com>2012-01-04 15:50:18 -0600
commit37307fc15429682b70f27e6b121083bbb9650da6 (patch)
treec53f10e1b61a39d4915bd7ee687a56b5b8b5f13b
parent6363a1eed1e083314de5f640c4142ccf01874e70 (diff)
downloadxombrero-37307fc15429682b70f27e6b121083bbb9650da6.tar.gz
use a #define for buffer size
Make buffer size 64k instead of 1k to minimize churn.  Also move a
variable to where $DEITY intended it.
-rw-r--r--externaleditor.c14
-rw-r--r--xxxterm.h1
2 files changed, 8 insertions, 7 deletions
diff --git a/externaleditor.c b/externaleditor.c
index baf9b64..4cc90c7 100644
--- a/externaleditor.c
+++ b/externaleditor.c
@@ -45,6 +45,7 @@ open_external_editor_cb(gpointer data)
 	int					status;
 	int					found_tab = 0;
 	GString					*contents = NULL;
+	char					buf[XT_EE_BUFSZ];
 
 	args = (struct open_external_editor_cb_args*)data;
 
@@ -72,27 +73,26 @@ open_external_editor_cb(gpointer data)
 		DPRINTF("File %s has been modified\n", args->path);
 		args->mtime = st.st_mtime;
 
-		contents = g_string_sized_new(1024);
+		contents = g_string_sized_new(XT_EE_BUFSZ);
 		fd = open(args->path, O_RDONLY);
 		if (fd == -1) {
 			DPRINTF("open_external_editor_cb, open error, %s\n", strerror(errno));
 			goto done;
 		}
 
-		char buf[1024];
 		nb = 0;
 		for (;;) {
-			nb = read(fd, buf, 1024);
+			nb = read(fd, buf, XT_EE_BUFSZ);
 			if (nb < 0) {
 				g_string_free(contents, TRUE);
-				show_oops(args->tab,strerror(errno));
+				show_oops(args->tab, strerror(errno));
 				goto done;
 			}
 
 			buf[nb] = '\0';
 			contents = g_string_append(contents, buf);
 
-			if (nb < 1024)
+			if (nb < XT_EE_BUFSZ)
 				break;
 		}
 		close(fd);
@@ -158,8 +158,8 @@ open_external_editor(struct tab *t, const char *contents, const char *suffix,
 
 	nb = 0;
 	while (nb < strlen(contents)) {
-		if (strlen(contents) - nb > 1024)
-			cnt = 1024;
+		if (strlen(contents) - nb > XT_EE_BUFSZ)
+			cnt = XT_EE_BUFSZ;
 		else
 			cnt = strlen(contents) - nb;
 
diff --git a/xxxterm.h b/xxxterm.h
index d5396f3..608a6cc 100644
--- a/xxxterm.h
+++ b/xxxterm.h
@@ -300,6 +300,7 @@ void			completion_add(struct tab *);
 void			completion_add_uri(const gchar *uri);
 
 /* external editor */
+#define XT_EE_BUFSZ	(64 * 1024)
 int			edit_src(struct tab *t, struct karg *args);
 int			edit_element(struct tab *t, struct karg *a);