summaryrefslogtreecommitdiff
path: root/emulators/snes9x/files/patch-aj
blob: 09cbf1e05c4b520b47ed3812bb854446c28ce1c3 (plain) (blame)
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
38
39
40
41
--- NETPLAY.CPP.orig	Fri Jul 25 23:20:20 2003
+++ NETPLAY.CPP	Sat Aug  9 01:16:22 2003
@@ -719,22 +719,24 @@
         return;
     }
     char fname [L_tmpnam];
-    FILE *tmp;
-    if (tmpnam (fname))
+    int tmp;
+    int flen = snprintf(fname, sizeof(fname), "%s/snes9x.XXXXXX",
+      getenv("TMPDIR") ? getenv("TMPDIR") : P_tmpdir);
+    if (flen == -1 || flen >= sizeof(fname) || (tmp = mkstemp(fname)) == -1)
     {
-        if ((tmp = fopen (fname, "wb")))
-        {
-            if (fwrite (data, 1, len, tmp) == len)
-            {
-                fclose (tmp);
-                if (!S9xUnfreezeGame (fname))
-                    S9xNPSetError ("Unable to load freeze file just received.");
-            }
-            else
-                fclose (tmp);
-        }
-        remove (fname);
+	S9xNPSetError("Unable to open a temporary freeze file.");
+	delete data;
+	return;
     }
+    if (write(tmp, data, len) == len)
+    {
+        close(tmp);
+        if (!S9xUnfreezeGame (fname))
+            S9xNPSetError ("Unable to load freeze file just received.");
+    }
+    else
+        close(tmp);
+    remove(fname);
     delete data;
 }