From: borutr Date: Wed, 11 Mar 2009 09:15:00 +0000 (+0000) Subject: * as/asranlib/asranlib.c: retain the original file mode X-Git-Url: https://git.gag.com/?p=fw%2Fsdcc;a=commitdiff_plain;h=1edc7c1316ae901d7dc6aeaae8117c6af4089c89 * as/asranlib/asranlib.c: retain the original file mode git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5409 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 2b0f5cf0..38e33586 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2009-03-11 Borut Razem + + * as/asranlib/asranlib.c: retain the original file mode + 2009-03-10 Borut Razem * src/mcs51/gen.c, src/z80/gen.c, src/hc08/gen.c, src/ds390/gen.c, diff --git a/as/asranlib/asranlib.c b/as/asranlib/asranlib.c index 69876283..dde9f787 100644 --- a/as/asranlib/asranlib.c +++ b/as/asranlib/asranlib.c @@ -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);