page: remove temporary file at program exit; fixes reading from stdin

http://codereview.appspot.com/105097
This commit is contained in:
J.R. Mauro 2009-08-20 14:38:31 -04:00
parent 8ff457f56d
commit 2fb0c4447e
3 changed files with 16 additions and 5 deletions

View file

@ -21,6 +21,7 @@ int truecolor;
int imagemode; int imagemode;
int notewatcher; int notewatcher;
int notegp; int notegp;
char tempfile[40];
int int
watcher(void *v, char *x) watcher(void *v, char *x)
@ -83,6 +84,12 @@ usage(void)
wexits("usage"); wexits("usage");
} }
void
cleanup(void)
{
remove(tempfile);
}
void void
threadmain(int argc, char **argv) threadmain(int argc, char **argv)
{ {
@ -173,6 +180,8 @@ threadmain(int argc, char **argv)
fprint(2, "page: short read reading %s\n", argv[0]); fprint(2, "page: short read reading %s\n", argv[0]);
wexits("read"); wexits("read");
} }
atexit(cleanup);
}else if(argc != 0){ }else if(argc != 0){
if(!(b = Bopen(argv[0], OREAD))) { if(!(b = Bopen(argv[0], OREAD))) {
fprint(2, "page: cannot open \"%s\"\n", argv[0]); fprint(2, "page: cannot open \"%s\"\n", argv[0]);

View file

@ -99,9 +99,12 @@ Image* convert(Graphic *g);
Image* cachedpage(Document*, int, int); Image* cachedpage(Document*, int, int);
void cacheflush(void); void cacheflush(void);
extern char tempfile[40];
extern int stdinfd; extern int stdinfd;
extern int truecolor; extern int truecolor;
/* BUG BUG BUG BUG BUG: cannot use new draw operations in drawterm, /* 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 * or in vncs, and there is a bug in the kernel for copying images
* from cpu memory -> video memory (memmove is not being used). * from cpu memory -> video memory (memmove is not being used).

View file

@ -50,12 +50,11 @@ spooltodisk(uchar *ibuf, int in, char **name)
{ {
uchar buf[8192]; uchar buf[8192];
int fd, n; int fd, n;
char temp[40];
strcpy(tempfile, "/tmp/pagespoolXXXXXXXXX");
strcpy(temp, "/tmp/pagespoolXXXXXXXXX"); fd = opentemp(tempfile, ORDWR);
fd = opentemp(temp, ORDWR|ORCLOSE);
if(name) if(name)
*name = estrdup(temp); *name = estrdup(tempfile);
if(write(fd, ibuf, in) != in){ if(write(fd, ibuf, in) != in){
fprint(2, "error writing temporary file\n"); fprint(2, "error writing temporary file\n");