summaryrefslogtreecommitdiff
path: root/chat/centericq/patches/patch-ae
blob: 7210741067463cd38467d4f6f4b996056d30f339 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$NetBSD: patch-ae,v 1.2 2005/10/16 19:28:03 tonio Exp $

--- src/hooks/gaduhook.cc.orig	2005-08-25 23:39:36.000000000 +0200
+++ src/hooks/gaduhook.cc
@@ -893,6 +893,7 @@ static char *token_ocr(const char *ocr, 
 string gaduhook::handletoken(struct gg_http *h) {
     struct gg_token *t;
     string fname, r;
+    char *tmpfilep = NULL;
 
     if(!h)
 	return "";
@@ -907,8 +908,22 @@ string gaduhook::handletoken(struct gg_h
 	return "";
 
     do {
-	fname = (getenv("TMPDIR") ? getenv("TMPDIR") : "/tmp");
-	fname += "/gg.token." + i2str(getpid()) + i2str(time(0));
+    while (tmpfilep == NULL) {
+      char tmpnam[100];
+      int tmpfiledes;
+      if (getenv("TMPDIR") && strlen(getenv("TMPDIR")) < 50)
+	sprintf (tmpnam, "%s/gg.token.XXXXXX", getenv("TMPDIR"));
+      else
+	sprintf (tmpnam, "/tmp/gg.token.XXXXXX");
+
+      if ((tmpfilep = mktemp (tmpnam)) != NULL) {
+	if ((tmpfiledes = open (tmpnam, O_CREAT | O_EXCL, S_IREAD | S_IWRITE)) == -1)
+	  tmpfilep = NULL;
+	else
+	  close (tmpfiledes);
+      }
+      fname = tmpnam;
+    }
     } while(!access(fname.c_str(), F_OK));
 
     ofstream bf(fname.c_str());