Module Name: xsrc
Committed By: christos
Date: Wed Apr 13 22:25:58 UTC 2016
Modified Files:
xsrc/external/mit/ctwm/dist: session.c
Log Message:
use mkstemp/mktemp
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 xsrc/external/mit/ctwm/dist/session.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: xsrc/external/mit/ctwm/dist/session.c
diff -u xsrc/external/mit/ctwm/dist/session.c:1.1 xsrc/external/mit/ctwm/dist/session.c:1.2
--- xsrc/external/mit/ctwm/dist/session.c:1.1 Thu Sep 3 18:16:33 2015
+++ xsrc/external/mit/ctwm/dist/session.c Wed Apr 13 18:25:57 2016
@@ -840,29 +840,32 @@ int GetWindowConfig (TwmWindow *theWindo
/*===[ Unique Filename Generator ]===========================================*/
-static char *unique_filename (char *path, char *prefix)
-/* this function attempts to allocate a temporary filename to store the
+static FILE *unique_file (char **filename, char *path, char *prefix)
+/* this function attempts to allocate a temporary file to store the
* information of the windows
*/
{
-
-#ifndef X_NOT_POSIX
- return ((char *) tempnam (path, prefix));
+ int fd;
+ char tmp[PATH_MAX], template[PATH_MAX];
+ FILE *fp;
+
+ snprintf(tmp, sizeof(tmp), "%s/%sXXXXXX", path, prefix);
+#ifndef HAVE_MKSTEMP
+ do {
+ if (fd == -1)
+ strcpy(template, tmp);
+ if ((mktemp(template) == NULL) || (template[0] == '\0'))
+ return NULL;
+ fd = open(template, O_RDWR | O_CREAT | O_EXCL, 0600);
+ } while ((fd == -1) && (errno == EEXIST || errno == EINTR));
#else
- char tempFile[PATH_MAX];
- char *tmp;
-
- sprintf (tempFile, "%s/%sXXXXXX", path, prefix);
- tmp = (char *) mktemp (tempFile);
- if (tmp)
- {
- char *ptr = (char *) malloc (strlen (tmp) + 1);
- strcpy (ptr, tmp);
- return (ptr);
- }
- else
- return (NULL);
+ if ((fd = mkstemp(tmp)) == -1)
+ return NULL;
#endif
+ if ((fp = fdopen(fd, "wb")) == NULL)
+ close(fd);
+ *filename = strdup(template);
+ return fp;
}
/*===[ SAVE WINDOW INFORMATION ]=============================================*/
@@ -942,10 +945,7 @@ void SaveYourselfPhase2CB (SmcConn smcCo
* no longer the same since the new format supports
* virtaul workspaces.
*========================================================*/
- if ((filename = unique_filename (path, ".ctwm")) == NULL)
- goto bad;
-
- if (!(configFile = fopen (filename, "wb"))) /* wb = write bytes ? */
+ if ((configFile = unique_file (&filename, path, ".ctwm")) == NULL)
goto bad;
if (!write_ushort (configFile, SAVEFILE_VERSION))