-
- vprintf(stdout, "Extract directories from tape\n");
- (void) sprintf(dirfile, "%s/rstdir%d", tmpdir, dumpdate);
- df = fopen(dirfile, "w");
- if (df == NULL) {
- fprintf(stderr,
- "restore: %s - cannot create directory temporary\n",
- dirfile);
- fprintf(stderr, "fopen: %s\n", strerror(errno));
- done(1);
+ int fd;
+
+ Vprintf(stdout, "Extract directories from tape\n");
+ (void) snprintf(dirfile, sizeof(dirfile), "%s/rstdir%ld", tmpdir,
+ (long)dumpdate);
+ if (command != 'r' && command != 'R') {
+ (void) strncat(dirfile, "-XXXXXX",
+ sizeof(dirfile) - strlen(dirfile));
+ fd = mkstemp(dirfile);
+ } else
+ fd = open(dirfile, O_RDWR|O_CREAT|O_EXCL, 0666);
+ if (fd == -1 || (df = fdopen(fd, "w")) == NULL) {
+ if (fd != -1)
+ close(fd);
+ err(1, "cannot create directory temporary %s", dirfile);