- char * tmpDir;
-
- strcpy (savedOldDir, smGD.etcPath);
-
- tmpName = (char *) XtMalloc (strlen (smGD.restoreSession) + 2);
- sprintf (tmpName, "%s.", smGD.restoreSession);
- if (strlen (tmpName) > 5) {
- tmpName[4] = '.';
- tmpName[5] = '\000';
- }
- tmpDir = (char *) tempnam (smGD.savePath, tmpName);
- MoveDirectory (smGD.etcPath, tmpDir, False);
-
- strcpy (savedTmpDir, tmpDir);
- free (tmpDir);
- XtFree ((char *) tmpName);
+ int len, tfd;
+
+ strcpy(savedOldDir, smGD.etcPath);
+
+ len = strlen(smGD.savePath) + strlen(smGD.restoreSession)
+ + strlen("XXXXXX") + 3;
+ tmpName = (char *) XtCalloc(1, len);
+
+ sprintf(tmpName, "%s/%s.XXXXXX", smGD.savePath,
+ smGD.restoreSession);
+
+ if ((tfd = mkstemp(tmpName)) == -1)
+ {
+ PrintErrnoError(DtError, smNLS.cantCreateDirsString);
+ }
+ else
+ {
+ close(tfd);
+ unlink(tmpName);
+
+ MoveDirectory(smGD.etcPath, tmpName, False);
+
+ strncpy(savedTmpDir, tmpName, len - 1);
+ }
+ XtFree((char *) tmpName);