shithub: libacme

Download patch

ref: f899e08afe81920f3fcb076d8686d2fef79e8549
parent: 1bced94ed0ad5e160db18e553e2e0a58b158035b
author: james palmer <[email protected]>
date: Mon Jun 7 09:31:43 EDT 2021

add awincat to read a file into the window body

--- a/acme.h
+++ b/acme.h
@@ -43,6 +43,7 @@
 
 void	awinctl(AWin *, char *, ...);
 void	awinclear(AWin *);
+int		awincat(AWin *, char *);
 void	awinprint(AWin *, char *, ...);
 void	awinerror(AWin *, char *, ...);
 void	awinfatal(AWin *, char *, ...);
--- a/window.c
+++ b/window.c
@@ -103,6 +103,31 @@
 	fprint(w->datafd, "");
 }
 
+int
+awincat(AWin *w, char *file)
+{
+	int body, fd;
+	char *buf;
+	long n;
+	
+	buf = malloc(sizeof(8*1024));
+	body = awinfsopen(w, "body", OWRITE);
+	fd = open(file, OREAD);
+	if(fd < 0) {
+		awinerror(w, "awincat read: %r");
+		return -1;
+	}
+		
+	while((n=read(fd, buf, 8*1024)) > 0) {
+		if(write(body, buf, n) != n) {
+			awinerror(w, "awincat write: %r");
+			return -1;
+		}
+	}
+	
+	return 0;
+}
+
 void
 awinprint(AWin *w, char *fmt, ...)
 {