* Bugfix of "rename" across volumes, now simply copies the file instead.
authorcarl <cecodere@yahoo.ca>
Sun, 17 Mar 2019 15:19:16 +0000 (23:19 +0800)
committercarl <cecodere@yahoo.ca>
Sun, 17 Mar 2019 15:19:16 +0000 (23:19 +0800)
util/LLgen/src/machdep.c
util/LLgen/src/main.c

index babe3b3..d04f9ac 100644 (file)
@@ -43,17 +43,7 @@ void UNLINK(string x)
 #endif
 }
 
-void RENAME(string x,string y)
-{
-       /* Must move the file "x" to the file "y" */
 
-#ifdef USE_SYS
-       if(!sys_rename(x,y)) fatal(1,"Cannot rename to %s",y);
-#else
-       if (rename(x, y) == -1)
-               fatal(1, "Cannot rename to %s", y);
-#endif
-}
 
 string libpath(string s)
 {
index f26446e..1f1cab2 100644 (file)
@@ -353,6 +353,28 @@ void copyfile(string file)
        fclose(f);
 }
 
+void copyto(string target, string source)
+{
+       FILE *fsource;
+       FILE *ftarget;
+       int c;
+
+       ftarget = fopen(target,"wb+");
+       if (ftarget == NULL)
+       {
+               fatal(0, "Cannot open file %s, call an expert", target);
+       }
+       fsource = fopen(source,"rb");
+       if (fsource == NULL)
+       {
+               fatal(0, "Cannot open file %s, call an expert", source);
+       }
+       while ((c = getc(fsource)) != EOF)
+               putc(c, ftarget);
+       fclose(fsource);
+       fclose(ftarget);
+}
+
 void install(string target, string source)
 {
        /*
@@ -377,7 +399,7 @@ void install(string target, string source)
        if ((f2 = fopen(target, "r")) == NULL)
        {
                fclose(f1);
-               RENAME(f_pars, target);
+               copyto(target, f_pars);
                return;
        }
        /*
@@ -406,6 +428,6 @@ void install(string target, string source)
                {
                        fatal(0, "%s : not a file generated by LLgen", target);
                }
-               RENAME(f_pars, target);
+               copyto(target, f_pars);
        }
 }