- (void) sprintf(modefile, "%s/rstmode%d", tmpdir, dumpdate);
- mf = fopen(modefile, "w");
- if (mf == NULL) {
- fprintf(stderr,
- "restore: %s - cannot create modefile \n",
- modefile);
- fprintf(stderr, "fopen: %s\n", strerror(errno));
+ (void) sprintf(modefile, "%s/rstmode%ld", tmpdir, dumpdate);
+ if (command != 'r' && command != 'R') {
+ (void *) strcat(modefile, "-XXXXXX");
+ fd = mkstemp(modefile);
+ } else
+ fd = open(modefile, O_RDWR|O_CREAT|O_EXCL, 0666);
+ if (fd == -1 || (mf = fdopen(fd, "w")) == NULL) {
+ if (fd != -1)
+ close(fd);
+ warn("%s - cannot create modefile\nfopen", modefile);