aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/page/util.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2007-03-26 20:55:26 +0000
committerrsc <devnull@localhost>2007-03-26 20:55:26 +0000
commit05a4d855f167ae2d0d2c0ba0e386d933172b71ea (patch)
tree8a1c64cf67479d8cab98b70fd25a12929f566634 /src/cmd/page/util.c
parent6c4c5c5b959ec8a2e85510bdf85339582f638f36 (diff)
downloadplan9port-05a4d855f167ae2d0d2c0ba0e386d933172b71ea.tar.gz
plan9port-05a4d855f167ae2d0d2c0ba0e386d933172b71ea.tar.bz2
plan9port-05a4d855f167ae2d0d2c0ba0e386d933172b71ea.zip
add page (Kris Maglione)
Diffstat (limited to 'src/cmd/page/util.c')
-rw-r--r--src/cmd/page/util.c79
1 files changed, 36 insertions, 43 deletions
diff --git a/src/cmd/page/util.c b/src/cmd/page/util.c
index 2669df84..1f6fdeff 100644
--- a/src/cmd/page/util.c
+++ b/src/cmd/page/util.c
@@ -1,9 +1,9 @@
#include <u.h>
#include <libc.h>
#include <draw.h>
-#include <cursor.h>
-#include <event.h>
+#include <thread.h>
#include <bio.h>
+#include <cursor.h>
#include "page.h"
void*
@@ -41,30 +41,6 @@ estrdup(char *s)
return t;
}
-int
-opentemp(char *template)
-{
- int fd, i;
- char *p;
-
- p = estrdup(template);
- fd = -1;
- for(i=0; i<10; i++){
- mktemp(p);
- if(access(p, 0) < 0 && (fd=create(p, ORDWR|ORCLOSE, 0400)) >= 0)
- break;
- strcpy(p, template);
- }
- if(fd < 0){
- fprint(2, "couldn't make temporary file\n");
- wexits("Ecreat");
- }
- strcpy(template, p);
- free(p);
-
- return fd;
-}
-
/*
* spool standard input to /tmp.
* we've already read the initial in bytes into ibuf.
@@ -96,37 +72,54 @@ spooltodisk(uchar *ibuf, int in, char **name)
return fd;
}
+typedef struct StdinArg StdinArg;
+
+struct StdinArg {
+ Channel *cp;
+ uchar *ibuf;
+ int in;
+};
+
/*
* spool standard input into a pipe.
* we've already ready the first in bytes into ibuf
*/
-int
-stdinpipe(uchar *ibuf, int in)
+static void
+_stdinpipe(void *a)
{
uchar buf[8192];
- int n;
+ StdinArg *arg;
int p[2];
+ int n;
+
+ arg = a;
+
if(pipe(p) < 0){
fprint(2, "pipe fails: %r\n");
wexits("pipe");
}
- switch(rfork(RFPROC|RFFDG)){
- case -1:
- fprint(2, "fork fails: %r\n");
- wexits("fork");
- default:
- close(p[1]);
- return p[0];
- case 0:
- break;
- }
+ send(arg->cp, &p[0]);
- close(p[0]);
- write(p[1], ibuf, in);
+ write(p[1], arg->ibuf, arg->in);
while((n = read(stdinfd, buf, sizeof buf)) > 0)
write(p[1], buf, n);
+
+ close(p[1]);
+ threadexits(0);
+}
+
+int
+stdinpipe(uchar *ibuf, int in) {
+ StdinArg arg;
+ int fd;
- _exits(0);
- return -1; /* not reached */
+ arg.ibuf = ibuf;
+ arg.in = in;
+ arg.cp = chancreate(sizeof(int), 0);
+ proccreate(_stdinpipe, &arg, mainstacksize);
+ recv(arg.cp, &fd);
+ chanfree(arg.cp);
+
+ return fd;
}