* as/asranlib/asranlib.c: retain the original file mode
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 11 Mar 2009 09:15:00 +0000 (09:15 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 11 Mar 2009 09:15:00 +0000 (09:15 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5409 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
as/asranlib/asranlib.c

index 2b0f5cf0bc48fbf83fd0ead0c0b037066a11f8a3..38e335861680085ec93d035c90edde7e4a22a8b1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-03-11 Borut Razem <borut.razem AT siol.net>
+
+       * as/asranlib/asranlib.c: retain the original file mode
+
 2009-03-10 Borut Razem <borut.razem AT siol.net>
 
        * src/mcs51/gen.c, src/z80/gen.c, src/hc08/gen.c, src/ds390/gen.c,
index 69876283d61fc67882827adb622ebaf7e1a8a950..dde9f787a24beafdac75ff1f1607070418072b89 100644 (file)
@@ -590,7 +590,10 @@ do_ranlib (const char *archive)
       int nsym;
       int symtab_size;
       char tmpfile[] = "arXXXXXX";
+      struct stat stat_buf;
+      int can_stat;
 
+      /* TODO: create tmpfile in temporery directory (TMP, TMPDIR, /usr/tmp, /tmp) */
 #ifdef _WIN32
       if (NULL == _mktemp (tmpfile) || NULL == (outfp = fopen (tmpfile, "wb")))
         {
@@ -646,7 +649,6 @@ do_ranlib (const char *archive)
           fwrite (buf, 1, sizeof (buf), outfp);
         }
 
-
       for (symp = symlist; symp; symp = symp->next)
         {
           fputs (symp->name, outfp);
@@ -662,6 +664,17 @@ do_ranlib (const char *archive)
         putc (pad, outfp);
 
       fclose (outfp);
+
+      if (0 != fstat(fileno(infp), &stat_buf))
+        {
+          fprintf (stderr, "asranlib: can't stat %s: ", infp);
+          perror (NULL);
+          fclose (infp);
+          can_stat = 0;
+        }
+      else
+        can_stat = 1;
+
       fclose (infp);
 
       if (0 != remove (archive))
@@ -674,6 +687,11 @@ do_ranlib (const char *archive)
           fprintf (stderr, "asranlib: can't rename %s to %s: ", tmpfile, archive);
           perror (NULL);
         }
+      else if (!can_stat || 0 != chmod (archive, stat_buf.st_mode))
+        {
+          fprintf (stderr, "asranlib: can't chmod %s: ", archive);
+          perror (NULL);
+        }
     }
   else
     fclose (infp);