commit 2fb0c4447ef493da81703dd20090676ed8cae834 from: J.R. Mauro date: Thu Aug 20 18:38:31 2009 UTC page: remove temporary file at program exit; fixes reading from stdin http://codereview.appspot.com/105097 commit - 8ff457f56db9f94f4baf68f53d87e791584d1dfe commit + 2fb0c4447ef493da81703dd20090676ed8cae834 blob - 23da4b91b84d5df9e9f4dbc25d600b5ec1f611da blob + e4a9c76238c2d7e38bed4f88a223a9afe126f43e --- src/cmd/page/page.c +++ src/cmd/page/page.c @@ -21,6 +21,7 @@ int truecolor; int imagemode; int notewatcher; int notegp; +char tempfile[40]; int watcher(void *v, char *x) @@ -84,6 +85,12 @@ usage(void) } void +cleanup(void) +{ + remove(tempfile); +} + +void threadmain(int argc, char **argv) { Document *doc; @@ -173,6 +180,8 @@ threadmain(int argc, char **argv) fprint(2, "page: short read reading %s\n", argv[0]); wexits("read"); } + + atexit(cleanup); }else if(argc != 0){ if(!(b = Bopen(argv[0], OREAD))) { fprint(2, "page: cannot open \"%s\"\n", argv[0]); blob - e4b320e5a389d014dc80c20ca497938d723c3420 blob + 93e0da79cf1774fbae7cda1d7abfb53eafdf1076 --- src/cmd/page/page.h +++ src/cmd/page/page.h @@ -99,9 +99,12 @@ Image* convert(Graphic *g); Image* cachedpage(Document*, int, int); void cacheflush(void); +extern char tempfile[40]; + extern int stdinfd; extern int truecolor; + /* BUG BUG BUG BUG BUG: cannot use new draw operations in drawterm, * or in vncs, and there is a bug in the kernel for copying images * from cpu memory -> video memory (memmove is not being used). blob - 74dd9bfefdaa56ac52c54ac29c871ec407d88783 blob + f10ef6db3a681a0a9048b1931c4496d7cb650777 --- src/cmd/page/util.c +++ src/cmd/page/util.c @@ -50,12 +50,11 @@ spooltodisk(uchar *ibuf, int in, char **name) { uchar buf[8192]; int fd, n; - char temp[40]; - - strcpy(temp, "/tmp/pagespoolXXXXXXXXX"); - fd = opentemp(temp, ORDWR|ORCLOSE); + + strcpy(tempfile, "/tmp/pagespoolXXXXXXXXX"); + fd = opentemp(tempfile, ORDWR); if(name) - *name = estrdup(temp); + *name = estrdup(tempfile); if(write(fd, ibuf, in) != in){ fprint(2, "error writing temporary file\n");