Commit 1fab8e81 by Richard Stallman

*** empty log message ***

From-SVN: r656
parent ef137e0a
...@@ -45,12 +45,10 @@ extern int errno; ...@@ -45,12 +45,10 @@ extern int errno;
#include "config.h" #include "config.h"
#ifndef __STDC__ #ifndef __STDC__
#include "gvarargs.h"
#define generic char #define generic char
#define const #define const
#else #else
#include "gstdarg.h"
#define generic void #define generic void
#endif #endif
...@@ -198,11 +196,8 @@ static void choose_temp_base (); ...@@ -198,11 +196,8 @@ static void choose_temp_base ();
generic *xcalloc (); generic *xcalloc ();
generic *xmalloc (); generic *xmalloc ();
#if !defined(HAVE_STRERROR) && !defined(_OSF_SOURCE)
char * char *
strerror (e) my_strerror (e)
int e; int e;
{ {
extern char *sys_errlist[]; extern char *sys_errlist[];
...@@ -218,9 +213,6 @@ strerror (e) ...@@ -218,9 +213,6 @@ strerror (e)
sprintf (buffer, "Unknown error %d", e); sprintf (buffer, "Unknown error %d", e);
return buffer; return buffer;
} }
#endif
/* Delete tempfiles and exit function. */ /* Delete tempfiles and exit function. */
...@@ -238,109 +230,43 @@ my_exit (status) ...@@ -238,109 +230,43 @@ my_exit (status)
} }
#ifndef __STDC__
/* Die when sys call fails. */ /* Die when sys call fails. */
/*VARARGS*/
static void static void
fatal_perror (va_alist) fatal_perror (string, arg1, arg2, arg3)
char *string;
{ {
char *string;
va_list vptr;
int e = errno; int e = errno;
va_start (vptr);
string = va_arg (vptr, char *);
fprintf (stderr, "collect: "); fprintf (stderr, "collect: ");
vfprintf (stderr, string, vptr); fprintf (stderr, string, arg1, arg2, arg3);
fprintf (stderr, ": %s\n", strerror (e)); fprintf (stderr, ": %s\n", my_strerror (e));
va_end (vptr);
my_exit (1); my_exit (1);
} }
/* Just die. */ /* Just die. */
/*VARARGS*/
static void static void
fatal (va_alist) fatal (string, arg1, arg2, arg3)
char *string;
{ {
char *string;
va_list vptr;
va_start (vptr);
string = va_arg (vptr, char *);
fprintf (stderr, "collect: "); fprintf (stderr, "collect: ");
vfprintf (stderr, string, vptr); fprintf (stderr, string, arg1, arg2, arg3);
fprintf (stderr, "\n"); fprintf (stderr, "\n");
va_end (vptr);
my_exit (1); my_exit (1);
} }
/* Write error message. */ /* Write error message. */
/*VARARGS*/
static void static void
error (va_alist) error (string, arg1, arg2, arg3, arg4)
char *string;
{ {
char *string;
va_list vptr;
va_start (vptr);
string = va_arg (vptr, char *);
fprintf (stderr, "collect: "); fprintf (stderr, "collect: ");
vfprintf (stderr, string, vptr); fprintf (stderr, string, arg1, arg2, arg3, arg4);
fprintf (stderr, "\n"); fprintf (stderr, "\n");
va_end (vptr);
} }
#else
static void
fatal_perror (char *string, ...)
{
va_list vptr;
int e = errno;
va_start (vptr, string);
fprintf (stderr, "collect: ");
vfprintf (stderr, string, vptr);
fprintf (stderr, ": %s\n", strerror (e));
va_end (vptr);
my_exit (1);
}
/* Just die. */
static void
fatal (char *string, ...)
{
va_list vptr;
va_start (vptr, string);
fprintf (stderr, "collect: ");
vfprintf (stderr, string, vptr);
fprintf (stderr, "\n");
va_end (vptr);
my_exit (1);
}
/* Write error message. */
static void
error (char *string, ...)
{
va_list vptr;
va_start (vptr, string);
fprintf (stderr, "collect: ");
vfprintf (stderr, string, vptr);
fprintf (stderr, "\n");
va_end (vptr);
}
#endif
/* In case obstack is linked in, and abort is defined to fancy_abort, /* In case obstack is linked in, and abort is defined to fancy_abort,
provide a default entry. */ provide a default entry. */
...@@ -374,7 +300,7 @@ xcalloc (size1, size2) ...@@ -374,7 +300,7 @@ xcalloc (size1, size2)
if (ptr) if (ptr)
return ptr; return ptr;
fatal ("Out of memory."); fatal ("out of memory");
return (generic *)0; return (generic *)0;
} }
...@@ -386,7 +312,7 @@ xmalloc (size) ...@@ -386,7 +312,7 @@ xmalloc (size)
if (ptr) if (ptr)
return ptr; return ptr;
fatal ("Out of memory."); fatal ("out of memory");
return (generic *)0; return (generic *)0;
} }
...@@ -398,7 +324,8 @@ savestring (input, size) ...@@ -398,7 +324,8 @@ savestring (input, size)
int size; int size;
{ {
char *output = (char *) xmalloc (size + 1); char *output = (char *) xmalloc (size + 1);
strcpy (output, input); bcopy (input, output, size);
output[size] = 0;
return output; return output;
} }
...@@ -792,12 +719,12 @@ main (argc, argv) ...@@ -792,12 +719,12 @@ main (argc, argv)
outf = fopen (c_file, "w"); outf = fopen (c_file, "w");
if (outf == (FILE *)0) if (outf == (FILE *)0)
fatal_perror ("Can't write %s", c_file); fatal_perror ("%s", c_file);
write_c_file (outf, c_file); write_c_file (outf, c_file);
if (fclose (outf)) if (fclose (outf))
fatal_perror ("Can't close %s", c_file); fatal_perror ("closing %s", c_file);
if (debug) if (debug)
{ {
...@@ -897,7 +824,7 @@ fork_execute (prog, argv) ...@@ -897,7 +824,7 @@ fork_execute (prog, argv)
if (pid == 0) /* child context */ if (pid == 0) /* child context */
{ {
execvp (prog, argv); execvp (prog, argv);
fatal_perror ("Execute %s", prog); fatal_perror ("executing %s", prog);
} }
int_handler = (void (*) ())signal (SIGINT, SIG_IGN); int_handler = (void (*) ())signal (SIGINT, SIG_IGN);
...@@ -1070,16 +997,16 @@ scan_prog_file (prog_name, which_pass) ...@@ -1070,16 +997,16 @@ scan_prog_file (prog_name, which_pass)
{ {
/* setup stdout */ /* setup stdout */
if (dup2 (pipe_fd[1], 1) < 0) if (dup2 (pipe_fd[1], 1) < 0)
fatal_perror ("Dup2 (%d, 1)", pipe_fd[1]); fatal_perror ("dup2 (%d, 1)", pipe_fd[1]);
if (close (pipe_fd[0]) < 0) if (close (pipe_fd[0]) < 0)
fatal_perror ("Close (%d)", pipe_fd[0]); fatal_perror ("close (%d)", pipe_fd[0]);
if (close (pipe_fd[1]) < 0) if (close (pipe_fd[1]) < 0)
fatal_perror ("Close (%d)", pipe_fd[1]); fatal_perror ("close (%d)", pipe_fd[1]);
execv (nm_file_name, nm_argv); execv (nm_file_name, nm_argv);
fatal_perror ("Execute %s", nm_file_name); fatal_perror ("executing %s", nm_file_name);
} }
/* Parent context from here on. */ /* Parent context from here on. */
...@@ -1087,7 +1014,7 @@ scan_prog_file (prog_name, which_pass) ...@@ -1087,7 +1014,7 @@ scan_prog_file (prog_name, which_pass)
quit_handler = (void (*) ())signal (SIGQUIT, SIG_IGN); quit_handler = (void (*) ())signal (SIGQUIT, SIG_IGN);
if (close (pipe_fd[1]) < 0) if (close (pipe_fd[1]) < 0)
fatal_perror ("Close (%d)", pipe_fd[1]); fatal_perror ("close (%d)", pipe_fd[1]);
if (debug) if (debug)
fprintf (stderr, "\nnm output with constructors/destructors.\n"); fprintf (stderr, "\nnm output with constructors/destructors.\n");
...@@ -1351,7 +1278,7 @@ scan_prog_file (prog_name, which_pass) ...@@ -1351,7 +1278,7 @@ scan_prog_file (prog_name, which_pass)
prog_fd = open (prog_name, (rw) ? O_RDWR : O_RDONLY); prog_fd = open (prog_name, (rw) ? O_RDWR : O_RDONLY);
if (prog_fd < 0) if (prog_fd < 0)
fatal_perror ("Can't read %s", prog_name); fatal_perror ("can't read %s", prog_name);
obj_file = read_file (prog_name, prog_fd, rw); obj_file = read_file (prog_name, prog_fd, rw);
obj = obj_file->start; obj = obj_file->start;
...@@ -1374,7 +1301,7 @@ scan_prog_file (prog_name, which_pass) ...@@ -1374,7 +1301,7 @@ scan_prog_file (prog_name, which_pass)
|| hdr.moh_cpu_subtype != OUR_CPU_SUBTYPE || hdr.moh_cpu_subtype != OUR_CPU_SUBTYPE
|| hdr.moh_vendor_type != OUR_VENDOR_TYPE) || hdr.moh_vendor_type != OUR_VENDOR_TYPE)
{ {
fatal ("incompatibilities exist between object file & expected values."); fatal ("incompatibilities between object file & expected values");
} }
#endif #endif
...@@ -1505,7 +1432,7 @@ scan_prog_file (prog_name, which_pass) ...@@ -1505,7 +1432,7 @@ scan_prog_file (prog_name, which_pass)
} }
if (symbol_load_cmds == 0) if (symbol_load_cmds == 0)
fatal ("no symbol table found."); fatal ("no symbol table found");
/* Update the program file now, rewrite header and load commands. At present, /* Update the program file now, rewrite header and load commands. At present,
we assume that there is enough space after the last load command to insert we assume that there is enough space after the last load command to insert
...@@ -1518,10 +1445,15 @@ scan_prog_file (prog_name, which_pass) ...@@ -1518,10 +1445,15 @@ scan_prog_file (prog_name, which_pass)
size_t size; size_t size;
if (cmd_strings == -1) if (cmd_strings == -1)
fatal ("no cmd_strings found."); fatal ("no cmd_strings found");
/* Add __main to initializer list.
If we are building a program instead of a shared library, don't
do anything, since in the current version, you cannot do mallocs
and such in the constructors. */
/* Add __main to initializer list. */ if (main_sym != (symbol_info_t *)0
if (main_sym != (symbol_info_t *)0) && ((hdr.moh_flags & MOH_EXECABLE_F) == 0))
add_func_table (&hdr, load_array, main_sym, FNTC_INITIALIZATION); add_func_table (&hdr, load_array, main_sym, FNTC_INITIALIZATION);
if (debug) if (debug)
...@@ -1583,7 +1515,7 @@ scan_prog_file (prog_name, which_pass) ...@@ -1583,7 +1515,7 @@ scan_prog_file (prog_name, which_pass)
end_file (obj_file); end_file (obj_file);
if (close (prog_fd)) if (close (prog_fd))
fatal_perror ("Can't close %s", prog_name); fatal_perror ("closing %s", prog_name);
if (debug) if (debug)
fprintf (stderr, "\n"); fprintf (stderr, "\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment