14 fprint(2, "out of memory allocating %d\n", sz);
22 erealloc(void *v, int sz)
26 fprint(2, "out of memory allocating %d\n", sz);
36 if((t = strdup(s)) == nil) {
37 fprint(2, "out of memory in strdup(%.10s)\n", s);
44 opentemp(char *template)
49 p = estrdup(template);
53 if(access(p, 0) < 0 && (fd=create(p, ORDWR|ORCLOSE, 0400)) >= 0)
58 fprint(2, "couldn't make temporary file\n");
68 * spool standard input to /tmp.
69 * we've already read the initial in bytes into ibuf.
72 spooltodisk(uchar *ibuf, int in, char **name)
78 strcpy(temp, "/tmp/pagespoolXXXXXXXXX");
81 *name = estrdup(temp);
83 if(write(fd, ibuf, in) != in){
84 fprint(2, "error writing temporary file\n");
88 while((n = read(stdinfd, buf, sizeof buf)) > 0){
89 if(write(fd, buf, n) != n){
90 fprint(2, "error writing temporary file\n");
91 wexits("write temp0");
99 * spool standard input into a pipe.
100 * we've already ready the first in bytes into ibuf
103 stdinpipe(uchar *ibuf, int in)
109 fprint(2, "pipe fails: %r\n");
113 switch(rfork(RFPROC|RFFDG)){
115 fprint(2, "fork fails: %r\n");
125 write(p[1], ibuf, in);
126 while((n = read(stdinfd, buf, sizeof buf)) > 0)
130 return -1; /* not reached */