]>
Commit | Line | Data |
---|---|---|
066649ef AG |
1 | --- cscope-15.3.orig/src/main.c |
2 | +++ cscope-15.3/src/main.c | |
3 | @@ -336,9 +336,32 @@ | |
4 | } | |
5 | ||
6 | /* create the temporary file names */ | |
7 | - pid = getpid(); | |
8 | - (void) sprintf(temp1, "%s/cscope%d.1", tmpdir, pid); | |
9 | - (void) sprintf(temp2, "%s/cscope%d.2", tmpdir, pid); | |
10 | + do { | |
11 | + char *tempfile = tempnam(tmpdir, "cscope1"); | |
12 | + if (!tempfile) { | |
13 | + fprintf (stderr, "Can't create tempfile\n"); | |
14 | + exit(1); | |
15 | + } | |
16 | + if (strlen(tempfile) >= sizeof(temp1)) { | |
17 | + fprintf (stderr, "TMPDIR path is too long\n"); | |
18 | + exit(1); | |
19 | + } | |
20 | + strncpy (temp1, tempfile, sizeof (temp1)); | |
21 | + free (tempfile); | |
22 | + } while (open (temp1, O_CREAT|O_EXCL|O_WRONLY, S_IREAD|S_IWRITE) < 0); | |
23 | + do { | |
24 | + char *tempfile = tempnam(tmpdir, "cscope2"); | |
25 | + if (!tempfile) { | |
26 | + fprintf (stderr, "Can't create tempfile\n"); | |
27 | + exit(1); | |
28 | + } | |
29 | + if (strlen(tempfile) >= sizeof(temp2)) { | |
30 | + fprintf (stderr, "TMPDIR path is too long\n"); | |
31 | + exit(1); | |
32 | + } | |
33 | + strncpy (temp2, tempfile, sizeof (temp2)); | |
34 | + free (tempfile); | |
35 | + } while (open (temp2, O_CREAT|O_EXCL|O_WRONLY, S_IREAD|S_IWRITE) < 0); | |
36 | ||
37 | /* if running in the foreground */ | |
38 | if (signal(SIGINT, SIG_IGN) != SIG_IGN) { |