-#ifndef __WIN32__
- char tmp[144];
- ::GetTempFileName(0, WXSTRINGCAST prefix, 0, tmp);
-#else
- char tmp[MAX_PATH];
- char tmpPath[MAX_PATH];
- ::GetTempPath(MAX_PATH, tmpPath);
- ::GetTempFileName(tmpPath, WXSTRINGCAST prefix, 0, tmp);
-#endif
- if (buf) strcpy(buf, tmp);
- else buf = copystring(tmp);
- return buf;
-
-#else
- static short last_temp = 0; // cache last to speed things a bit
- // At most 1000 temp files to a process! We use a ring count.
- char tmp[100]; // FIXME static buffer
-
- for (short suffix = last_temp + 1; suffix != last_temp; ++suffix %= 1000)
- {
- sprintf (tmp, "/tmp/%s%d.%03x", WXSTRINGCAST prefix, (int) getpid (), (int) suffix);
- if (!wxFileExists( tmp ))
- {
- // Touch the file to create it (reserve name)
- FILE *fd = fopen (tmp, "w");
- if (fd)
- fclose (fd);
- last_temp = suffix;
- if (buf)
- strcpy( buf, tmp);
- else
- buf = copystring( tmp );
- return buf;
- }
- }
- wxLogError( _("wxWindows: error finding temporary file name.\n") );
- if (buf) buf[0] = 0;
- return (char *) NULL;
-#endif