aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/adaint.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/ada/adaint.c')
-rw-r--r--gcc/ada/adaint.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/gcc/ada/adaint.c b/gcc/ada/adaint.c
index 73eb814..9d4f051 100644
--- a/gcc/ada/adaint.c
+++ b/gcc/ada/adaint.c
@@ -1170,23 +1170,37 @@ __gnat_tmp_name (char *tmp_filename)
sprintf (tmp_filename, "%s/gnat-XXXXXX", tmpdir);
close (mkstemp(tmp_filename));
-#elif defined (__vxworks) && !(defined (__RTP__) || defined (VTHREADS))
- int index;
- char * pos;
- ushort_t t;
+#elif defined (__vxworks) && !defined (VTHREADS)
+ int index;
+ char *pos;
+ char *savepos;
static ushort_t seed = 0; /* used to generate unique name */
- /* generate unique name */
+ /* Generate a unique name. */
strcpy (tmp_filename, "tmp");
- /* fill up the name buffer from the last position */
index = 5;
- pos = tmp_filename + strlen (tmp_filename) + index;
+ savepos = pos = tmp_filename + strlen (tmp_filename) + index;
*pos = '\0';
- seed++;
- for (t = seed; 0 <= --index; t >>= 3)
- *--pos = '0' + (t & 07);
+ while (1)
+ {
+ FILE *f;
+ ushort_t t;
+
+ /* Fill up the name buffer from the last position. */
+ seed++;
+ for (t = seed; 0 <= --index; t >>= 3)
+ *--pos = '0' + (t & 07);
+
+ /* Check to see if its unique, if not bump the seed and try again. */
+ f = fopen (tmp_filename, "r");
+ if (f == NULL)
+ break;
+ fclose (f);
+ pos = savepos;
+ index = 5;
+ }
#else
tmpnam (tmp_filename);
#endif