X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=binutils%2Fsrconv.c;h=7b3d4a7550cd8e29ce068aaae7e754465b1b750c;hb=889fac9b849aa6032288f723784ca1126b623bc9;hp=d1f3efdb9e016a2d9fcf710243254d0688e87ced;hpb=8f1ff9f2035b545de59f35377e084d03c25636dc;p=pf3gnuchains%2Fpf3gnuchains4x.git diff --git a/binutils/srconv.c b/binutils/srconv.c index d1f3efdb9e..7b3d4a7550 100644 --- a/binutils/srconv.c +++ b/binutils/srconv.c @@ -1,12 +1,12 @@ /* srconv.c -- Sysroff conversion program Copyright 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, - 2005 Free Software Foundation, Inc. + 2005, 2007, 2008, 2009 Free Software Foundation, Inc. This file is part of GNU Binutils. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -26,11 +26,13 @@ All debugging information is preserved */ +#include "sysdep.h" #include "bfd.h" #include "bucomm.h" #include "sysroff.h" #include "coffgrok.h" #include "libiberty.h" +#include "filenames.h" #include "getopt.h" #include "coff/internal.h" @@ -45,7 +47,7 @@ static char **rnames; static int get_member_id (int); static int get_ordinary_id (int); static char *section_translate (char *); -static char *strip_suffix (char *); +static char *strip_suffix (const char *); static void checksum (FILE *, unsigned char *, int, int); static void writeINT (int, unsigned char *, int *, int, FILE *); static void writeBITS (int, unsigned char *, int *, int); @@ -141,9 +143,8 @@ section_translate (char *n) #define DATE "940201073000"; /* Just a time on my birthday */ -static -char * -strip_suffix (char *name) +static char * +strip_suffix (const char *name) { int i; char *res; @@ -158,17 +159,17 @@ strip_suffix (char *name) /* IT LEN stuff CS */ static void -checksum (FILE *file, unsigned char *ptr, int size, int code) +checksum (FILE *ffile, unsigned char *ptr, int size, int ccode) { int j; int last; int sum = 0; int bytes = size / 8; - last = !(code & 0xff00); + last = !(ccode & 0xff00); if (size & 0x7) abort (); - ptr[0] = code | (last ? 0x80 : 0); + ptr[0] = ccode | (last ? 0x80 : 0); ptr[1] = bytes + 1; for (j = 0; j < bytes; j++) @@ -176,12 +177,14 @@ checksum (FILE *file, unsigned char *ptr, int size, int code) /* Glue on a checksum too. */ ptr[bytes] = ~sum; - fwrite (ptr, bytes + 1, 1, file); + if (fwrite (ptr, bytes + 1, 1, ffile) != 1) + /* FIXME: Return error status. */ + abort (); } static void -writeINT (int n, unsigned char *ptr, int *idx, int size, FILE *file) +writeINT (int n, unsigned char *ptr, int *idx, int size, FILE *ffile) { int byte = *idx / 8; @@ -193,7 +196,7 @@ writeINT (int n, unsigned char *ptr, int *idx, int size, FILE *file) if (byte > 240) { /* Lets write out that record and do another one. */ - checksum (file, ptr, *idx, code | 0x1000); + checksum (ffile, ptr, *idx, code | 0x1000); *idx = 16; byte = *idx / 8; } @@ -240,24 +243,24 @@ writeBITS (int val, unsigned char *ptr, int *idx, int size) static void writeBARRAY (barray data, unsigned char *ptr, int *idx, - int size ATTRIBUTE_UNUSED, FILE *file) + int size ATTRIBUTE_UNUSED, FILE *ffile) { int i; - writeINT (data.len, ptr, idx, 1, file); + writeINT (data.len, ptr, idx, 1, ffile); for (i = 0; i < data.len; i++) - writeINT (data.data[i], ptr, idx, 1, file); + writeINT (data.data[i], ptr, idx, 1, ffile); } static void -writeCHARS (char *string, unsigned char *ptr, int *idx, int size, FILE *file) +writeCHARS (char *string, unsigned char *ptr, int *idx, int size, FILE *ffile) { int i = *idx / 8; if (i > 240) { /* Lets write out that record and do another one. */ - checksum (file, ptr, *idx, code | 0x1000); + checksum (ffile, ptr, *idx, code | 0x1000); *idx = 16; i = *idx / 8; } @@ -299,7 +302,10 @@ wr_tr (void) 0x03, /* RL */ 0xfd, /* CS */ }; - fwrite (b, 1, sizeof (b), file); + + if (fwrite (b, sizeof (b), 1, file) != 1) + /* FIXME: Return error status. */ + abort (); } static void @@ -410,7 +416,7 @@ wr_hd (struct coff_ofile *p) abort (); } - if (! bfd_get_file_flags(abfd) & EXEC_P) + if (! (bfd_get_file_flags(abfd) & EXEC_P)) { hd.ep = 0; } @@ -704,6 +710,7 @@ walk_tree_type_1 (struct coff_sfile *sfile, struct coff_symbol *symbol, { struct IT_dpt dpt; + dpt.dunno = 0; walk_tree_type_1 (sfile, symbol, type->u.pointer.points_to, nest + 1); dpt.neg = 0x1001; sysroff_swap_dpt_out (file, &dpt); @@ -1451,7 +1458,10 @@ wr_cs (void) 0x00, /* dot */ 0xDE /* CS */ }; - fwrite (b, 1, sizeof (b), file); + + if (fwrite (b, sizeof (b), 1, file) != 1) + /* FIXME: Return error status. */ + abort (); } /* Write out the SC records for a unit. Create an SC @@ -1688,21 +1698,22 @@ align (int x) ordinary defs - dunno why, but thats what hitachi does with 'em. */ static void -prescan (struct coff_ofile *tree) +prescan (struct coff_ofile *otree) { struct coff_symbol *s; struct coff_section *common_section; /* Find the common section - always section 3. */ - common_section = tree->sections + 3; + common_section = otree->sections + 3; - for (s = tree->symbol_list_head; + for (s = otree->symbol_list_head; s; s = s->next_in_ofile_list) { if (s->visible->type == coff_vis_common) { struct coff_where *w = s->where; + /* s->visible->type = coff_vis_ext_def; leave it as common */ common_section->size = align (common_section->size); w->offset = common_section->size + common_section->address; @@ -1716,11 +1727,11 @@ prescan (struct coff_ofile *tree) char *program_name; static void -show_usage (FILE *file, int status) +show_usage (FILE *ffile, int status) { - fprintf (file, _("Usage: %s [option(s)] in-file [out-file]\n"), program_name); - fprintf (file, _("Convert a COFF object file into a SYSROFF object file\n")); - fprintf (file, _(" The options are:\n\ + fprintf (ffile, _("Usage: %s [option(s)] in-file [out-file]\n"), program_name); + fprintf (ffile, _("Convert a COFF object file into a SYSROFF object file\n")); + fprintf (ffile, _(" The options are:\n\ -q --quick (Obsolete - ignored)\n\ -n --noprescan Do not perform a scan to convert commons into defs\n\ -d --debug Display information about what is being done\n\ @@ -1728,8 +1739,8 @@ show_usage (FILE *file, int status) -h --help Display this information\n\ -v --version Print the program's version number\n")); - if (status == 0) - fprintf (file, _("Report bugs to %s\n"), REPORT_BUGS_TO); + if (REPORT_BUGS_TO[0] && status == 0) + fprintf (ffile, _("Report bugs to %s\n"), REPORT_BUGS_TO); exit (status); } @@ -1808,7 +1819,7 @@ main (int ac, char **av) ++optind; if (optind < ac) show_usage (stderr, 1); - if (strcmp (input_file, output_file) == 0) + if (filename_cmp (input_file, output_file) == 0) { fatal (_("input and output files must be different")); }