]> git.sur5r.net Git - cc65/blobdiff - src/ar65/library.c
Deduct temporary library path name from library path name.
[cc65] / src / ar65 / library.c
index 9046e315fa97b2fad93d4a80769115f0873c93ad..e68f23d3dac22b884102db279d35d703b4a81bee 100644 (file)
 
 /* Name of the library file */
 const char*             LibName = 0;
+static char*            NewLibName = 0;
 
 /* File descriptor for the library file */
-FILE*                   NewLib = 0;
 static FILE*            Lib = 0;
+static FILE*            NewLib = 0;
 
 /* The library header */
 static LibHeader        Header = {
@@ -246,10 +247,16 @@ void LibOpen (const char* Name, int MustExist, int NeedTemp)
     }
 
     if (NeedTemp) {
+
+        /* Create the temporary library name */
+        NewLibName = xmalloc (strlen (Name) + strlen (".temp") + 1);
+        strcpy (NewLibName, Name);
+        strcat (NewLibName, ".temp");
+
         /* Create the temporary library */
-        NewLib = tmpfile ();
+        NewLib = fopen (NewLibName, "w+b");
         if (NewLib == 0) {
-            Error ("Cannot create temporary file: %s", strerror (errno));
+            Error ("Cannot create temporary library file: %s", strerror (errno));
         }
 
         /* Write a dummy header to the temp file */
@@ -378,7 +385,7 @@ void LibClose (void)
                    LibName, strerror (errno));
         }
 
-        /* Copy the new library to the new one */
+        /* Copy the temporary library to the new one */
         fseek (NewLib, 0, SEEK_SET);
         while ((Count = fread (Buf, 1, sizeof (Buf), NewLib)) != 0) {
             if (fwrite (Buf, 1, Count, Lib) != Count) {
@@ -394,6 +401,9 @@ void LibClose (void)
     if (NewLib && fclose (NewLib) != 0) {
         Error ("Problem closing temporary library file: %s", strerror (errno));
     }
+    if (NewLibName && remove (NewLibName) != 0) {
+        Error ("Problem deleting temporary library file: %s", strerror (errno));
+    }
 }