diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/idiff.c | 23 | ||||
-rw-r--r-- | src/cmd/page/filter.c | 2 | ||||
-rw-r--r-- | src/cmd/page/page.h | 1 | ||||
-rw-r--r-- | src/cmd/page/util.c | 2 | ||||
-rw-r--r-- | src/cmd/page/view.c | 2 | ||||
-rw-r--r-- | src/cmd/vbackup/vbackup.c | 2 | ||||
-rw-r--r-- | src/lib9/opentemp.c | 13 |
7 files changed, 15 insertions, 30 deletions
diff --git a/src/cmd/idiff.c b/src/cmd/idiff.c index 234333fa..aaf78be3 100644 --- a/src/cmd/idiff.c +++ b/src/cmd/idiff.c @@ -7,14 +7,11 @@ #include <libc.h> #include <bio.h> -#define opentemp idiffopentemp - int diffbflag; int diffwflag; void copy(Biobuf*, char*, Biobuf*, char*); void idiff(Biobuf*, char*, Biobuf*, char*, Biobuf*, char*, Biobuf*, char*); -int opentemp(char*, int, long); void rundiff(char*, char*, int); void @@ -63,9 +60,9 @@ main(int argc, char **argv) sysfatal("open %s: %r", argv[1]); strcpy(diffout, "/tmp/idiff.XXXXXX"); - fd = opentemp(diffout, ORDWR|ORCLOSE, 0); + fd = opentemp(diffout, ORDWR|ORCLOSE); strcpy(idiffout, "/tmp/idiff.XXXXXX"); - ofd = opentemp(idiffout, ORDWR|ORCLOSE, 0); + ofd = opentemp(idiffout, ORDWR|ORCLOSE); rundiff(argv[0], argv[1], fd); seek(fd, 0, 0); Binit(&bdiff, fd, OREAD); @@ -80,22 +77,6 @@ main(int argc, char **argv) exits(nil); } -int -opentemp(char *template, int mode, long perm) -{ - int fd; - Dir d; - - fd = mkstemp(template); - if(fd < 0) - sysfatal("could not create temporary file"); - nulldir(&d); - d.mode = perm; - dirfwstat(fd, &d); - - return fd; -} - void rundiff(char *arg1, char *arg2, int outfd) { diff --git a/src/cmd/page/filter.c b/src/cmd/page/filter.c index 2e0482fc..f9b2a8a2 100644 --- a/src/cmd/page/filter.c +++ b/src/cmd/page/filter.c @@ -32,7 +32,7 @@ initfilt(Biobuf *b, int argc, char **argv, uchar *buf, int nbuf, char *type, cha p[1] = open("/dev/null", ORDWR); } - ofd = opentemp(template); + ofd = opentemp(template, ORDWR|ORCLOSE); switch(fork()){ case -1: fprint(2, "fork fails: %r\n"); diff --git a/src/cmd/page/page.h b/src/cmd/page/page.h index 7e6c526e..c31c1b92 100644 --- a/src/cmd/page/page.h +++ b/src/cmd/page/page.h @@ -96,7 +96,6 @@ int min(int, int); void wexits(char*); Image* xallocimage(Display*, Rectangle, ulong, int, ulong); int bell(void*, char*); -int opentemp(char *template); Image* convert(Graphic *g); extern int stdinfd; diff --git a/src/cmd/page/util.c b/src/cmd/page/util.c index 1f6fdeff..74dd9bfe 100644 --- a/src/cmd/page/util.c +++ b/src/cmd/page/util.c @@ -53,7 +53,7 @@ spooltodisk(uchar *ibuf, int in, char **name) char temp[40]; strcpy(temp, "/tmp/pagespoolXXXXXXXXX"); - fd = opentemp(temp); + fd = opentemp(temp, ORDWR|ORCLOSE); if(name) *name = estrdup(temp); diff --git a/src/cmd/page/view.c b/src/cmd/page/view.c index ab409cc7..8fc6fa79 100644 --- a/src/cmd/page/view.c +++ b/src/cmd/page/view.c @@ -732,7 +732,7 @@ viewer(Document *dd) } if(showdata(pm)) { s = estrdup("/tmp/pageplumbXXXXXXX"); - fd = opentemp(s); + fd = opentemp(s, ORDWR|ORCLOSE); write(fd, pm->data, pm->ndata); /* lose fd reference on purpose; the file is open ORCLOSE */ } else if(pm->data[0] == '/') { diff --git a/src/cmd/vbackup/vbackup.c b/src/cmd/vbackup/vbackup.c index 07000b1f..db26bc32 100644 --- a/src/cmd/vbackup/vbackup.c +++ b/src/cmd/vbackup/vbackup.c @@ -260,7 +260,7 @@ threadmain(int argc, char **argv) if(tmpnam == nil) sysfatal("smprint: %r"); - if((fd = opentemp(tmpnam)) < 0) + if((fd = opentemp(tmpnam, ORDWR|ORCLOSE)) < 0) sysfatal("opentemp %s: %r", tmpnam); if(statustime) print("# %T reading scores into %s\n", tmpnam); diff --git a/src/lib9/opentemp.c b/src/lib9/opentemp.c index f90bf771..9d4e2d07 100644 --- a/src/lib9/opentemp.c +++ b/src/lib9/opentemp.c @@ -2,14 +2,19 @@ #include <libc.h> int -opentemp(char *template) +opentemp(char *template, int mode) { - int fd; + int fd, fd1; fd = mkstemp(template); if(fd < 0) return -1; - remove(template); - return fd; + if((fd1 = open(template, mode)) < 0){ + remove(template); + close(fd); + return -1; + } + close(fd); + return fd1; } |