Commits

Anonymous committed aa4d4a9

Importing gcc 3.3.2.

Comments (0)

Files changed (10)

GCC/libiberty/strsignal.c

+/* Extended support for using signal values.
+   Written by Fred Fish.  fnf@cygnus.com
+   This file is in the public domain.  */
+
+#include "ansidecl.h"
+#include "libiberty.h"
+
+#include "config.h"
+
+/* We need to declare sys_siglist, because even if the system provides
+   it we can't assume that it is declared in <signal.h> (for example,
+   SunOS provides sys_siglist, but it does not declare it in any
+   header file).  fHowever, we can't declare sys_siglist portably,
+   because on some systems it is declared with const and on some
+   systems it is declared without const.  If we were using autoconf,
+   we could work out the right declaration.  Until, then we just
+   ignore any declaration in the system header files, and always
+   declare it ourselves.  With luck, this will always work.  */
+#define sys_siglist no_such_symbol
+#define sys_nsig sys_nsig__no_such_symbol
+
+#include <stdio.h>
+#include <signal.h>
+
+/*  Routines imported from standard C runtime libraries. */
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#else
+extern PTR malloc ();
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#else
+extern PTR memset ();
+#endif
+
+/* Undefine the macro we used to hide the definition of sys_siglist
+   found in the system header files.  */
+#undef sys_siglist
+#undef sys_nsig
+
+#ifndef NULL
+#  ifdef __STDC__
+#    define NULL (void *) 0
+#  else
+#    define NULL 0
+#  endif
+#endif
+
+#ifndef MAX
+#  define MAX(a,b) ((a) > (b) ? (a) : (b))
+#endif
+
+static void init_signal_tables PARAMS ((void));
+
+/* Translation table for signal values.
+
+   Note that this table is generally only accessed when it is used at runtime
+   to initialize signal name and message tables that are indexed by signal
+   value.
+
+   Not all of these signals will exist on all systems.  This table is the only
+   thing that should have to be updated as new signal numbers are introduced.
+   It's sort of ugly, but at least its portable. */
+
+struct signal_info
+{
+  const int value;		/* The numeric value from <signal.h> */
+  const char *const name;	/* The equivalent symbolic value */
+#ifndef HAVE_SYS_SIGLIST
+  const char *const msg;	/* Short message about this value */
+#endif
+};
+
+#ifndef HAVE_SYS_SIGLIST
+#   define ENTRY(value, name, msg)	{value, name, msg}
+#else
+#   define ENTRY(value, name, msg)	{value, name}
+#endif
+
+static const struct signal_info signal_table[] =
+{
+#if defined (SIGHUP)
+  ENTRY(SIGHUP, "SIGHUP", "Hangup"),
+#endif
+#if defined (SIGINT)
+  ENTRY(SIGINT, "SIGINT", "Interrupt"),
+#endif
+#if defined (SIGQUIT)
+  ENTRY(SIGQUIT, "SIGQUIT", "Quit"),
+#endif
+#if defined (SIGILL)
+  ENTRY(SIGILL, "SIGILL", "Illegal instruction"),
+#endif
+#if defined (SIGTRAP)
+  ENTRY(SIGTRAP, "SIGTRAP", "Trace/breakpoint trap"),
+#endif
+/* Put SIGIOT before SIGABRT, so that if SIGIOT==SIGABRT then SIGABRT
+   overrides SIGIOT.  SIGABRT is in ANSI and POSIX.1, and SIGIOT isn't. */
+#if defined (SIGIOT)
+  ENTRY(SIGIOT, "SIGIOT", "IOT trap"),
+#endif
+#if defined (SIGABRT)
+  ENTRY(SIGABRT, "SIGABRT", "Aborted"),
+#endif
+#if defined (SIGEMT)
+  ENTRY(SIGEMT, "SIGEMT", "Emulation trap"),
+#endif
+#if defined (SIGFPE)
+  ENTRY(SIGFPE, "SIGFPE", "Arithmetic exception"),
+#endif
+#if defined (SIGKILL)
+  ENTRY(SIGKILL, "SIGKILL", "Killed"),
+#endif
+#if defined (SIGBUS)
+  ENTRY(SIGBUS, "SIGBUS", "Bus error"),
+#endif
+#if defined (SIGSEGV)
+  ENTRY(SIGSEGV, "SIGSEGV", "Segmentation fault"),
+#endif
+#if defined (SIGSYS)
+  ENTRY(SIGSYS, "SIGSYS", "Bad system call"),
+#endif
+#if defined (SIGPIPE)
+  ENTRY(SIGPIPE, "SIGPIPE", "Broken pipe"),
+#endif
+#if defined (SIGALRM)
+  ENTRY(SIGALRM, "SIGALRM", "Alarm clock"),
+#endif
+#if defined (SIGTERM)
+  ENTRY(SIGTERM, "SIGTERM", "Terminated"),
+#endif
+#if defined (SIGUSR1)
+  ENTRY(SIGUSR1, "SIGUSR1", "User defined signal 1"),
+#endif
+#if defined (SIGUSR2)
+  ENTRY(SIGUSR2, "SIGUSR2", "User defined signal 2"),
+#endif
+/* Put SIGCLD before SIGCHLD, so that if SIGCLD==SIGCHLD then SIGCHLD
+   overrides SIGCLD.  SIGCHLD is in POXIX.1 */
+#if defined (SIGCLD)
+  ENTRY(SIGCLD, "SIGCLD", "Child status changed"),
+#endif
+#if defined (SIGCHLD)
+  ENTRY(SIGCHLD, "SIGCHLD", "Child status changed"),
+#endif
+#if defined (SIGPWR)
+  ENTRY(SIGPWR, "SIGPWR", "Power fail/restart"),
+#endif
+#if defined (SIGWINCH)
+  ENTRY(SIGWINCH, "SIGWINCH", "Window size changed"),
+#endif
+#if defined (SIGURG)
+  ENTRY(SIGURG, "SIGURG", "Urgent I/O condition"),
+#endif
+#if defined (SIGIO)
+  /* "I/O pending" has also been suggested, but is misleading since the
+     signal only happens when the process has asked for it, not everytime
+     I/O is pending. */
+  ENTRY(SIGIO, "SIGIO", "I/O possible"),
+#endif
+#if defined (SIGPOLL)
+  ENTRY(SIGPOLL, "SIGPOLL", "Pollable event occurred"),
+#endif
+#if defined (SIGSTOP)
+  ENTRY(SIGSTOP, "SIGSTOP", "Stopped (signal)"),
+#endif
+#if defined (SIGTSTP)
+  ENTRY(SIGTSTP, "SIGTSTP", "Stopped (user)"),
+#endif
+#if defined (SIGCONT)
+  ENTRY(SIGCONT, "SIGCONT", "Continued"),
+#endif
+#if defined (SIGTTIN)
+  ENTRY(SIGTTIN, "SIGTTIN", "Stopped (tty input)"),
+#endif
+#if defined (SIGTTOU)
+  ENTRY(SIGTTOU, "SIGTTOU", "Stopped (tty output)"),
+#endif
+#if defined (SIGVTALRM)
+  ENTRY(SIGVTALRM, "SIGVTALRM", "Virtual timer expired"),
+#endif
+#if defined (SIGPROF)
+  ENTRY(SIGPROF, "SIGPROF", "Profiling timer expired"),
+#endif
+#if defined (SIGXCPU)
+  ENTRY(SIGXCPU, "SIGXCPU", "CPU time limit exceeded"),
+#endif
+#if defined (SIGXFSZ)
+  ENTRY(SIGXFSZ, "SIGXFSZ", "File size limit exceeded"),
+#endif
+#if defined (SIGWIND)
+  ENTRY(SIGWIND, "SIGWIND", "SIGWIND"),
+#endif
+#if defined (SIGPHONE)
+  ENTRY(SIGPHONE, "SIGPHONE", "SIGPHONE"),
+#endif
+#if defined (SIGLOST)
+  ENTRY(SIGLOST, "SIGLOST", "Resource lost"),
+#endif
+#if defined (SIGWAITING)
+  ENTRY(SIGWAITING, "SIGWAITING", "Process's LWPs are blocked"),
+#endif
+#if defined (SIGLWP)
+  ENTRY(SIGLWP, "SIGLWP", "Signal LWP"),
+#endif
+#if defined (SIGDANGER)
+  ENTRY(SIGDANGER, "SIGDANGER", "Swap space dangerously low"),
+#endif
+#if defined (SIGGRANT)
+  ENTRY(SIGGRANT, "SIGGRANT", "Monitor mode granted"),
+#endif
+#if defined (SIGRETRACT)
+  ENTRY(SIGRETRACT, "SIGRETRACT", "Need to relinguish monitor mode"),
+#endif
+#if defined (SIGMSG)
+  ENTRY(SIGMSG, "SIGMSG", "Monitor mode data available"),
+#endif
+#if defined (SIGSOUND)
+  ENTRY(SIGSOUND, "SIGSOUND", "Sound completed"),
+#endif
+#if defined (SIGSAK)
+  ENTRY(SIGSAK, "SIGSAK", "Secure attention"),
+#endif
+  ENTRY(0, NULL, NULL)
+};
+
+/* Translation table allocated and initialized at runtime.  Indexed by the
+   signal value to find the equivalent symbolic value. */
+
+static const char **signal_names;
+static int num_signal_names = 0;
+
+/* Translation table allocated and initialized at runtime, if it does not
+   already exist in the host environment.  Indexed by the signal value to find
+   the descriptive string.
+
+   We don't export it for use in other modules because even though it has the
+   same name, it differs from other implementations in that it is dynamically
+   initialized rather than statically initialized. */
+
+#ifndef HAVE_SYS_SIGLIST
+
+static int sys_nsig;
+static const char **sys_siglist;
+
+#else
+
+#ifdef NSIG
+static int sys_nsig = NSIG;
+#else
+#ifdef _NSIG
+static int sys_nsig = _NSIG;
+#endif
+#endif
+extern const char * const sys_siglist[];
+
+#endif
+
+
+/*
+
+NAME
+
+	init_signal_tables -- initialize the name and message tables
+
+SYNOPSIS
+
+	static void init_signal_tables ();
+
+DESCRIPTION
+
+	Using the signal_table, which is initialized at compile time, generate
+	the signal_names and the sys_siglist (if needed) tables, which are
+	indexed at runtime by a specific signal value.
+
+BUGS
+
+	The initialization of the tables may fail under low memory conditions,
+	in which case we don't do anything particularly useful, but we don't
+	bomb either.  Who knows, it might succeed at a later point if we free
+	some memory in the meantime.  In any case, the other routines know
+	how to deal with lack of a table after trying to initialize it.  This
+	may or may not be considered to be a bug, that we don't specifically
+	warn about this particular failure mode.
+
+*/
+
+static void
+init_signal_tables ()
+{
+  const struct signal_info *eip;
+  int nbytes;
+
+  /* If we haven't already scanned the signal_table once to find the maximum
+     signal value, then go find it now. */
+
+  if (num_signal_names == 0)
+    {
+      for (eip = signal_table; eip -> name != NULL; eip++)
+	{
+	  if (eip -> value >= num_signal_names)
+	    {
+	      num_signal_names = eip -> value + 1;
+	    }
+	}
+    }
+
+  /* Now attempt to allocate the signal_names table, zero it out, and then
+     initialize it from the statically initialized signal_table. */
+
+  if (signal_names == NULL)
+    {
+      nbytes = num_signal_names * sizeof (char *);
+      if ((signal_names = (const char **) malloc (nbytes)) != NULL)
+	{
+	  memset (signal_names, 0, nbytes);
+	  for (eip = signal_table; eip -> name != NULL; eip++)
+	    {
+	      signal_names[eip -> value] = eip -> name;
+	    }
+	}
+    }
+
+#ifndef HAVE_SYS_SIGLIST
+
+  /* Now attempt to allocate the sys_siglist table, zero it out, and then
+     initialize it from the statically initialized signal_table. */
+
+  if (sys_siglist == NULL)
+    {
+      nbytes = num_signal_names * sizeof (char *);
+      if ((sys_siglist = (const char **) malloc (nbytes)) != NULL)
+	{
+	  memset (sys_siglist, 0, nbytes);
+	  sys_nsig = num_signal_names;
+	  for (eip = signal_table; eip -> name != NULL; eip++)
+	    {
+	      sys_siglist[eip -> value] = eip -> msg;
+	    }
+	}
+    }
+
+#endif
+
+}
+
+
+/*
+
+@deftypefn Extension int signo_max (void)
+
+Returns the maximum signal value for which a corresponding symbolic
+name or message is available.  Note that in the case where we use the
+@code{sys_siglist} supplied by the system, it is possible for there to
+be more symbolic names than messages, or vice versa.  In fact, the
+manual page for @code{psignal(3b)} explicitly warns that one should
+check the size of the table (@code{NSIG}) before indexing it, since
+new signal codes may be added to the system before they are added to
+the table.  Thus @code{NSIG} might be smaller than value implied by
+the largest signo value defined in @code{<signal.h>}.
+
+We return the maximum value that can be used to obtain a meaningful
+symbolic name or message.
+
+@end deftypefn
+
+*/
+
+int
+signo_max ()
+{
+  int maxsize;
+
+  if (signal_names == NULL)
+    {
+      init_signal_tables ();
+    }
+  maxsize = MAX (sys_nsig, num_signal_names);
+  return (maxsize - 1);
+}
+
+
+/*
+
+@deftypefn Supplemental {const char *} strsignal (int @var{signo})
+
+Maps an signal number to an signal message string, the contents of
+which are implementation defined.  On systems which have the external
+variable @code{sys_siglist}, these strings will be the same as the
+ones used by @code{psignal()}.
+
+If the supplied signal number is within the valid range of indices for
+the @code{sys_siglist}, but no message is available for the particular
+signal number, then returns the string @samp{Signal @var{num}}, where
+@var{num} is the signal number.
+
+If the supplied signal number is not a valid index into
+@code{sys_siglist}, returns @code{NULL}.
+
+The returned string is only guaranteed to be valid only until the next
+call to @code{strsignal}.
+
+@end deftypefn
+
+*/
+
+#ifndef HAVE_STRSIGNAL
+
+const char *
+strsignal (signo)
+  int signo;
+{
+  const char *msg;
+  static char buf[32];
+
+#ifndef HAVE_SYS_SIGLIST
+
+  if (signal_names == NULL)
+    {
+      init_signal_tables ();
+    }
+
+#endif
+
+  if ((signo < 0) || (signo >= sys_nsig))
+    {
+      /* Out of range, just return NULL */
+      msg = NULL;
+    }
+  else if ((sys_siglist == NULL) || (sys_siglist[signo] == NULL))
+    {
+      /* In range, but no sys_siglist or no entry at this index. */
+      sprintf (buf, "Signal %d", signo);
+      msg = (const char *) buf;
+    }
+  else
+    {
+      /* In range, and a valid message.  Just return the message. */
+      msg = (const char *) sys_siglist[signo];
+    }
+  
+  return (msg);
+}
+
+#endif /* ! HAVE_STRSIGNAL */
+
+/*
+
+@deftypefn Extension {const char*} strsigno (int @var{signo})
+
+Given an signal number, returns a pointer to a string containing the
+symbolic name of that signal number, as found in @code{<signal.h>}.
+
+If the supplied signal number is within the valid range of indices for
+symbolic names, but no name is available for the particular signal
+number, then returns the string @samp{Signal @var{num}}, where
+@var{num} is the signal number.
+
+If the supplied signal number is not within the range of valid
+indices, then returns @code{NULL}.
+
+The contents of the location pointed to are only guaranteed to be
+valid until the next call to @code{strsigno}.
+
+@end deftypefn
+
+*/
+
+const char *
+strsigno (signo)
+  int signo;
+{
+  const char *name;
+  static char buf[32];
+
+  if (signal_names == NULL)
+    {
+      init_signal_tables ();
+    }
+
+  if ((signo < 0) || (signo >= num_signal_names))
+    {
+      /* Out of range, just return NULL */
+      name = NULL;
+    }
+  else if ((signal_names == NULL) || (signal_names[signo] == NULL))
+    {
+      /* In range, but no signal_names or no entry at this index. */
+      sprintf (buf, "Signal %d", signo);
+      name = (const char *) buf;
+    }
+  else
+    {
+      /* In range, and a valid name.  Just return the name. */
+      name = signal_names[signo];
+    }
+
+  return (name);
+}
+
+
+/*
+
+@deftypefn Extension int strtosigno (const char *@var{name})
+
+Given the symbolic name of a signal, map it to a signal number.  If no
+translation is found, returns 0.
+
+@end deftypefn
+
+*/
+
+int
+strtosigno (name)
+     const char *name;
+{
+  int signo = 0;
+
+  if (name != NULL)
+    {
+      if (signal_names == NULL)
+	{
+	  init_signal_tables ();
+	}
+      for (signo = 0; signo < num_signal_names; signo++)
+	{
+	  if ((signal_names[signo] != NULL) &&
+	      (strcmp (name, signal_names[signo]) == 0))
+	    {
+	      break;
+	    }
+	}
+      if (signo == num_signal_names)
+	{
+	  signo = 0;
+	}
+    }
+  return (signo);
+}
+
+
+/*
+
+@deftypefn Supplemental void psignal (unsigned @var{signo}, char *@var{message})
+
+Print @var{message} to the standard error, followed by a colon,
+followed by the description of the signal specified by @var{signo},
+followed by a newline.
+
+@end deftypefn
+
+*/
+
+#ifndef HAVE_PSIGNAL
+
+void
+psignal (signo, message)
+  unsigned signo;
+  char *message;
+{
+  if (signal_names == NULL)
+    {
+      init_signal_tables ();
+    }
+  if ((signo <= 0) || (signo >= sys_nsig))
+    {
+      fprintf (stderr, "%s: unknown signal\n", message);
+    }
+  else
+    {
+      fprintf (stderr, "%s: %s\n", message, sys_siglist[signo]);
+    }
+}
+
+#endif	/* ! HAVE_PSIGNAL */
+
+
+/* A simple little main that does nothing but print all the signal translations
+   if MAIN is defined and this file is compiled and linked. */
+
+#ifdef MAIN
+
+#include <stdio.h>
+
+int
+main ()
+{
+  int signo;
+  int maxsigno;
+  const char *name;
+  const char *msg;
+
+  maxsigno = signo_max ();
+  printf ("%d entries in names table.\n", num_signal_names);
+  printf ("%d entries in messages table.\n", sys_nsig);
+  printf ("%d is max useful index.\n", maxsigno);
+
+  /* Keep printing values until we get to the end of *both* tables, not
+     *either* table.  Note that knowing the maximum useful index does *not*
+     relieve us of the responsibility of testing the return pointer for
+     NULL. */
+
+  for (signo = 0; signo <= maxsigno; signo++)
+    {
+      name = strsigno (signo);
+      name = (name == NULL) ? "<NULL>" : name;
+      msg = strsignal (signo);
+      msg = (msg == NULL) ? "<NULL>" : msg;
+      printf ("%-4d%-18s%s\n", signo, name, msg);
+    }
+
+  return 0;
+}
+
+#endif

GCC/libiberty/strstr.c

+/* Simple implementation of strstr for systems without it.
+   This function is in the public domain.  */
+
+/*
+
+@deftypefn Supplemental char* strstr (const char *@var{string}, const char *@var{sub})
+
+This function searches for the substring @var{sub} in the string
+@var{string}, not including the terminating null characters.  A pointer
+to the first occurrence of @var{sub} is returned, or @code{NULL} if the
+substring is absent.  If @var{sub} points to a string with zero
+length, the function returns @var{string}.
+
+@end deftypefn
+
+
+*/
+
+
+/* FIXME:  The above description is ANSI compiliant.  This routine has not
+   been validated to comply with it.  -fnf */
+
+char *
+strstr (s1, s2)
+  char *s1, *s2;
+{
+  register char *p = s1;
+  extern char *strchr ();
+  extern int strncmp ();
+#if __GNUC__==2
+  extern __SIZE_TYPE__ strlen ();
+#endif
+  register int len = strlen (s2);
+
+  for (; (p = strchr (p, *s2)) != 0; p++)
+    {
+      if (strncmp (p, s2, len) == 0)
+	{
+	  return (p);
+	}
+    }
+  return (0);
+}

GCC/libiberty/strtod.c

+/* Implementation of strtod for systems with atof.
+   Copyright (C) 1991, 1995, 2002 Free Software Foundation, Inc.
+
+This file is part of the libiberty library.  This library 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, or (at your option)
+any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU CC; see the file COPYING.  If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+As a special exception, if you link this library with files
+compiled with a GNU compiler to produce an executable, this does not cause
+the resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why
+the executable file might be covered by the GNU General Public License. */
+
+/*
+
+@deftypefn Supplemental double strtod (const char *@var{string}, char **@var{endptr})
+
+This ISO C function converts the initial portion of @var{string} to a
+@code{double}.  If @var{endptr} is not @code{NULL}, a pointer to the
+character after the last character used in the conversion is stored in
+the location referenced by @var{endptr}.  If no conversion is
+performed, zero is returned and the value of @var{string} is stored in
+the location referenced by @var{endptr}.
+
+@end deftypefn
+
+*/
+
+#include "ansidecl.h"
+#include "safe-ctype.h"
+
+extern double atof ();
+
+/* Disclaimer: this is currently just used by CHILL in GDB and therefore
+   has not been tested well.  It may have been tested for nothing except
+   that it compiles.  */
+
+double
+strtod (str, ptr)
+     char *str;
+     char **ptr;
+{
+  char *p;
+
+  if (ptr == (char **)0)
+    return atof (str);
+  
+  p = str;
+  
+  while (ISSPACE (*p))
+    ++p;
+  
+  if (*p == '+' || *p == '-')
+    ++p;
+
+  /* INF or INFINITY.  */
+  if ((p[0] == 'i' || p[0] == 'I')
+      && (p[1] == 'n' || p[1] == 'N')
+      && (p[2] == 'f' || p[2] == 'F'))
+    {
+      if ((p[3] == 'i' || p[3] == 'I')
+	  && (p[4] == 'n' || p[4] == 'N')
+	  && (p[5] == 'i' || p[5] == 'I')
+	  && (p[6] == 't' || p[6] == 'T')
+	  && (p[7] == 'y' || p[7] == 'Y'))
+	{
+	  *ptr = p + 8;
+	  return atof (str);
+	}
+      else
+	{
+	  *ptr = p + 3;
+	  return atof (str);
+	}
+    }
+
+  /* NAN or NAN(foo).  */
+  if ((p[0] == 'n' || p[0] == 'N')
+      && (p[1] == 'a' || p[1] == 'A')
+      && (p[2] == 'n' || p[2] == 'N'))
+    {
+      p += 3;
+      if (*p == '(')
+	{
+	  ++p;
+	  while (*p != '\0' && *p != ')')
+	    ++p;
+	  if (*p == ')')
+	    ++p;
+	}
+      *ptr = p;
+      return atof (str);
+    }
+
+  /* digits, with 0 or 1 periods in it.  */
+  if (ISDIGIT (*p) || *p == '.')
+    {
+      int got_dot = 0;
+      while (ISDIGIT (*p) || (!got_dot && *p == '.'))
+	{
+	  if (*p == '.')
+	    got_dot = 1;
+	  ++p;
+	}
+
+      /* Exponent.  */
+      if (*p == 'e' || *p == 'E')
+	{
+	  int i;
+	  i = 1;
+	  if (p[i] == '+' || p[i] == '-')
+	    ++i;
+	  if (ISDIGIT (p[i]))
+	    {
+	      while (ISDIGIT (p[i]))
+		++i;
+	      *ptr = p + i;
+	      return atof (str);
+	    }
+	}
+      *ptr = p;
+      return atof (str);
+    }
+  /* Didn't find any digits.  Doesn't look like a number.  */
+  *ptr = str;
+  return 0.0;
+}

GCC/libiberty/strtol.c

+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. [rescinded 22 July 1999]
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+
+@deftypefn Supplemental {long int} strtol (const char *@var{string}, char **@var{endptr}, int @var{base})
+@deftypefnx Supplemental {unsigned long int} strtoul (const char *@var{string}, char **@var{endptr}, int @var{base})
+
+The @code{strtol} function converts the string in @var{string} to a
+long integer value according to the given @var{base}, which must be
+between 2 and 36 inclusive, or be the special value 0.  If @var{base}
+is 0, @code{strtol} will look for the prefixes @code{0} and @code{0x}
+to indicate bases 8 and 16, respectively, else default to base 10.
+When the base is 16 (either explicitly or implicitly), a prefix of
+@code{0x} is allowed.  The handling of @var{endptr} is as that of
+@code{strtod} above.  The @code{strtoul} function is the same, except
+that the converted value is unsigned.
+
+@end deftypefn
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+#include <errno.h>
+#ifdef NEED_DECLARATION_ERRNO
+extern int errno;
+#endif
+#include "safe-ctype.h"
+
+/* FIXME: It'd be nice to configure around these, but the include files are too
+   painful.  These macros should at least be more portable than hardwired hex
+   constants. */
+
+#ifndef ULONG_MAX
+#define	ULONG_MAX	((unsigned long)(~0L))		/* 0xFFFFFFFF */
+#endif
+
+#ifndef LONG_MAX
+#define	LONG_MAX	((long)(ULONG_MAX >> 1))	/* 0x7FFFFFFF */
+#endif
+
+#ifndef LONG_MIN
+#define	LONG_MIN	((long)(~LONG_MAX))		/* 0x80000000 */
+#endif
+
+/*
+ * Convert a string to a long integer.
+ *
+ * Ignores `locale' stuff.  Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+long
+strtol(nptr, endptr, base)
+	const char *nptr;
+	char **endptr;
+	register int base;
+{
+	register const char *s = nptr;
+	register unsigned long acc;
+	register int c;
+	register unsigned long cutoff;
+	register int neg = 0, any, cutlim;
+
+	/*
+	 * Skip white space and pick up leading +/- sign if any.
+	 * If base is 0, allow 0x for hex and 0 for octal, else
+	 * assume decimal; if base is already 16, allow 0x.
+	 */
+	do {
+		c = *s++;
+	} while (ISSPACE(c));
+	if (c == '-') {
+		neg = 1;
+		c = *s++;
+	} else if (c == '+')
+		c = *s++;
+	if ((base == 0 || base == 16) &&
+	    c == '0' && (*s == 'x' || *s == 'X')) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == '0' ? 8 : 10;
+
+	/*
+	 * Compute the cutoff value between legal numbers and illegal
+	 * numbers.  That is the largest legal value, divided by the
+	 * base.  An input number that is greater than this value, if
+	 * followed by a legal input character, is too big.  One that
+	 * is equal to this value may be valid or not; the limit
+	 * between valid and invalid numbers is then based on the last
+	 * digit.  For instance, if the range for longs is
+	 * [-2147483648..2147483647] and the input base is 10,
+	 * cutoff will be set to 214748364 and cutlim to either
+	 * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
+	 * a value > 214748364, or equal but the next digit is > 7 (or 8),
+	 * the number is too big, and we will return a range error.
+	 *
+	 * Set any if any `digits' consumed; make it negative to indicate
+	 * overflow.
+	 */
+	cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
+	cutlim = cutoff % (unsigned long)base;
+	cutoff /= (unsigned long)base;
+	for (acc = 0, any = 0;; c = *s++) {
+		if (ISDIGIT(c))
+			c -= '0';
+		else if (ISALPHA(c))
+			c -= ISUPPER(c) ? 'A' - 10 : 'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
+			any = -1;
+		else {
+			any = 1;
+			acc *= base;
+			acc += c;
+		}
+	}
+	if (any < 0) {
+		acc = neg ? LONG_MIN : LONG_MAX;
+		errno = ERANGE;
+	} else if (neg)
+		acc = -acc;
+	if (endptr != 0)
+		*endptr = (char *) (any ? s - 1 : nptr);
+	return (acc);
+}

GCC/libiberty/vmsbuild.com

+$! libiberty/vmsbuild.com -- build liberty.olb for VMS host, VMS target
+$!
+$ CC	= "gcc /noVerbose/Debug/Incl=([],[-.include])"
+$ LIBR	= "library /Obj"
+$ LINK	= "link"
+$ DELETE= "delete /noConfirm"
+$ SEARCH= "search /Exact"
+$ ECHO	= "write sys$output"
+$ ABORT	= "exit %x002C"
+$!
+$ LIB_NAME = "liberty.olb"	!this is what we're going to construct
+$ WORK_LIB = "new-lib.olb"	!used to guard against an incomplete build
+$
+$! manually copied from Makefile.in
+$ REQUIRED_OFILES = "argv.o basename.o choose-temp.o concat.o cplus-dem.o "-
+	+ "fdmatch.o fnmatch.o getopt.o getopt1.o getruntime.o hex.o "-
+	+ "floatformat.o objalloc.o obstack.o spaces.o strerror.o strsignal.o "-
+	+ "xatexit.o xexit.o xmalloc.o xmemdup.o xstrdup.o xstrerror.o"
+$! anything not caught by link+search of dummy.* should be added here
+$ EXTRA_OFILES = ""
+$!
+$! move to the directory which contains this command procedure
+$ old_dir = f$environ("DEFAULT")
+$ new_dir = f$parse("_._;",f$environ("PROCEDURE")) - "_._;"
+$ set default 'new_dir'
+$
+$ ECHO "Starting libiberty build..."
+$ create config.h
+/* libiberty config.h for VMS */
+#define NEED_sys_siglist
+#define NEED_strsignal
+#define NEED_psignal
+#define NEED_basename
+$ LIBR 'WORK_LIB' /Create
+$
+$! first pass: compile "required" modules
+$ ofiles = REQUIRED_OFILES + " " + EXTRA_OFILES
+$ pass = 1
+$ gosub do_ofiles
+$
+$! second pass: process dummy.c, using the first pass' results
+$ ECHO " now checking run-time library for missing functionality"
+$ if f$search("dummy.obj").nes."" then  DELETE dummy.obj;*
+$ define/noLog sys$error _NL:	!can't use /User_Mode here due to gcc
+$ define/noLog sys$output _NL:	! driver's use of multiple image activation
+$ on error then continue
+$ 'CC' dummy.c
+$ deassign sys$error   !restore, more or less
+$ deassign sys$output
+$ if f$search("dummy.obj").eqs."" then  goto pass2_failure1
+$! link dummy.obj, capturing full linker feedback in dummy.map
+$ oldmsg = f$environ("MESSAGE")
+$ set message /Facility/Severity/Identification/Text
+$ define/User sys$output _NL:
+$ define/User sys$error _NL:
+$ LINK/Map=dummy.map/noExe dummy.obj,'WORK_LIB'/Libr,-
+	gnu_cc:[000000]gcclib.olb/Libr,sys$library:vaxcrtl.olb/Libr
+$ set message 'oldmsg'
+$ if f$search("dummy.map").eqs."" then  goto pass2_failure2
+$ DELETE dummy.obj;*
+$ SEARCH dummy.map "%LINK-I-UDFSYM" /Output=dummy.list
+$ DELETE dummy.map;*
+$ ECHO " check completed"
+$! we now have a file with one entry per line of unresolvable symbols
+$ ofiles = ""
+$ if f$trnlnm("IFILE$").nes."" then  close/noLog ifile$
+$	open/Read ifile$ dummy.list
+$iloop: read/End=idone ifile$ iline
+$	iline = f$edit(iline,"COMPRESS,TRIM,LOWERCASE")
+$	ofiles = ofiles + " " + f$element(1," ",iline) + ".o"
+$	goto iloop
+$idone: close ifile$
+$ DELETE dummy.list;*
+$ on error then ABORT
+$
+$! third pass: compile "missing" modules collected in pass 2
+$ pass = 3
+$ gosub do_ofiles
+$
+$! finish up
+$ LIBR 'WORK_LIB' /Compress /Output='LIB_NAME'	!new-lib.olb -> liberty.olb
+$ DELETE 'WORK_LIB';*
+$
+$! all done
+$ ECHO "Completed libiberty build."
+$ type sys$input:
+
+  You many wish to do
+  $ COPY LIBERTY.OLB GNU_CC:[000000]
+  so that this run-time library resides in the same location as gcc's
+  support library.  When building gas, be sure to leave the original
+  copy of liberty.olb here so that gas's build procedure can find it.
+
+$ set default 'old_dir'
+$ exit
+$
+$!
+$! compile each element of the space-delimited list 'ofiles'
+$!
+$do_ofiles:
+$ ofiles = f$edit(ofiles,"COMPRESS,TRIM")
+$ i = 0
+$oloop:
+$ f = f$element(i," ",ofiles)
+$ if f.eqs." " then  goto odone
+$ f = f - ".o"	!strip dummy suffix
+$ ECHO "  ''f'"
+$ skip_f = 0
+$ if pass.eq.3 .and. f$search("''f'.c").eqs."" then  gosub chk_deffunc
+$ if .not.skip_f
+$ then
+$   'CC' 'f'.c
+$   LIBR 'WORK_LIB' 'f'.obj /Insert
+$   DELETE 'f'.obj;*
+$ endif
+$ i = i + 1
+$ goto oloop
+$odone:
+$ return
+$
+$!
+$! check functions.def for a DEFFUNC() entry corresponding to missing file 'f'.c
+$!
+$chk_deffunc:
+$ define/User sys$output _NL:
+$ define/User sys$error _NL:
+$ SEARCH functions.def "DEFFUNC","''f'" /Match=AND
+$ if (($status.and.%x7FFFFFFF) .eq. 1)
+$ then
+$   skip_f = 1
+$   open/Append config_h config.h
+$   write config_h "#define NEED_''f'"
+$   close config_h
+$ endif
+$ return
+$
+$!
+$pass2_failure1:
+$! if we reach here, dummy.c failed to compile and we're really stuck
+$ type sys$input:
+
+  Cannot compile the library contents checker (dummy.c + functions.def),
+  so cannot continue!
+
+$! attempt the compile again, without suppressing diagnostic messages this time
+$ on error then ABORT +0*f$verify(v)
+$ v = f$verify(1)
+$ 'CC' dummy.c
+$ ABORT +0*f$verify(v)	!'f$verify(0)'
+$!
+$pass2_failure2:
+$! should never reach here..
+$ type sys$input:
+
+  Cannot link the library contents checker (dummy.obj), so cannot continue!
+
+$! attempt the link again, without suppressing diagnostic messages this time
+$ on error then ABORT +0*f$verify(v)
+$ v = f$verify(1)
+$ LINK/Map=dummy.map/noExe dummy.obj,'WORK_LIB'/Libr,-
+	gnu_cc:[000000]gcclib.olb/Libr,sys$library:vaxcrtl.olb/Libr
+$ ABORT +0*f$verify(v)	!'f$verify(0)'
+$
+$! not reached
+$ exit

GCC/libiberty/waitpid.c

+/*
+
+@deftypefn Supplemental int waitpid (int @var{pid}, int *@var{status}, int)
+
+This is a wrapper around the @code{wait} function.  Any ``special''
+values of @var{pid} depend on your implementation of @code{wait}, as
+does the return value.  The third argument is unused in @libib{}.
+
+@end deftypefn
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* On some systems (such as WindISS), you must include <sys/types.h>
+   to get the definition of "pid_t" before you include <sys/wait.h>.  */
+#include <sys/types.h>
+
+#ifdef HAVE_SYS_WAIT_H
+#include <sys/wait.h>
+#endif
+
+pid_t
+waitpid (pid, stat_loc, options)
+     pid_t pid;
+     int *stat_loc, options;
+{
+  for (;;)
+    {
+      int wpid = wait(stat_loc);
+      if (wpid == pid || wpid == -1)
+	return wpid;
+    }
+}

GCC/libiberty/xatexit.c

+/*
+ * Copyright (c) 1990 Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ */
+
+
+/*
+
+@deftypefun int xatexit (void (*@var{fn}) (void))
+
+Behaves as the standard @code{atexit} function, but with no limit on
+the number of registered functions.  Returns 0 on success, or @minus{}1 on
+failure.  If you use @code{xatexit} to register functions, you must use
+@code{xexit} to terminate your program.
+
+@end deftypefun
+
+*/
+
+/* Adapted from newlib/libc/stdlib/{,at}exit.[ch].
+   If you use xatexit, you must call xexit instead of exit.  */
+
+#include "ansidecl.h"
+#include "libiberty.h"
+
+#include <stdio.h>
+
+#ifdef __STDC__
+#include <stddef.h>
+#else
+#define size_t unsigned long
+#endif
+
+#if VMS
+#include <stdlib.h>
+#include <unixlib.h>
+#else
+/* For systems with larger pointers than ints, this must be declared.  */
+PTR malloc PARAMS ((size_t));
+#endif
+
+static void xatexit_cleanup PARAMS ((void));
+
+/* Pointer to function run by xexit.  */
+extern void (*_xexit_cleanup) PARAMS ((void));
+
+#define	XATEXIT_SIZE 32
+
+struct xatexit {
+	struct	xatexit *next;		/* next in list */
+	int	ind;			/* next index in this table */
+	void	(*fns[XATEXIT_SIZE]) PARAMS ((void));	/* the table itself */
+};
+
+/* Allocate one struct statically to guarantee that we can register
+   at least a few handlers.  */
+static struct xatexit xatexit_first;
+
+/* Points to head of LIFO stack.  */
+static struct xatexit *xatexit_head = &xatexit_first;
+
+/* Register function FN to be run by xexit.
+   Return 0 if successful, -1 if not.  */
+
+int
+xatexit (fn)
+     void (*fn) PARAMS ((void));
+{
+  register struct xatexit *p;
+
+  /* Tell xexit to call xatexit_cleanup.  */
+  if (!_xexit_cleanup)
+    _xexit_cleanup = xatexit_cleanup;
+
+  p = xatexit_head;
+  if (p->ind >= XATEXIT_SIZE)
+    {
+      if ((p = (struct xatexit *) malloc (sizeof *p)) == NULL)
+	return -1;
+      p->ind = 0;
+      p->next = xatexit_head;
+      xatexit_head = p;
+    }
+  p->fns[p->ind++] = fn;
+  return 0;
+}
+
+/* Call any cleanup functions.  */
+
+static void
+xatexit_cleanup ()
+{
+  register struct xatexit *p;
+  register int n;
+
+  for (p = xatexit_head; p; p = p->next)
+    for (n = p->ind; --n >= 0;)
+      (*p->fns[n]) ();
+}

GCC/libiberty/xexit.c

+/* xexit.c -- Run any exit handlers, then exit.
+   Copyright (C) 1994, 95, 1997 Free Software Foundation, Inc.
+
+This file is part of the libiberty library.
+Libiberty is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+Libiberty is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with libiberty; see the file COPYING.LIB.  If not, write
+to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+/*
+
+@deftypefn Replacement void xexit (int @var{code})
+
+Terminates the program.  If any functions have been registered with
+the @code{xatexit} replacement function, they will be called first.
+Termination is handled via the system's normal @code{exit} call.
+
+@end deftypefn
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#include "libiberty.h"
+
+
+/* This variable is set by xatexit if it is called.  This way, xmalloc
+   doesn't drag xatexit into the link.  */
+void (*_xexit_cleanup) PARAMS ((void));
+
+void
+xexit (code)
+     int code;
+{
+  if (_xexit_cleanup != NULL)
+    (*_xexit_cleanup) ();
+  exit (code);
+}

GCC/libiberty/xmemdup.c

+/* xmemdup.c -- Duplicate a memory buffer, using xcalloc.
+   This trivial function is in the public domain.
+   Jeff Garzik, September 1999.  */
+
+/*
+
+@deftypefn Replacement void* xmemdup (void *@var{input}, size_t @var{copy_size}, size_t @var{alloc_size})
+
+Duplicates a region of memory without fail.  First, @var{alloc_size} bytes
+are allocated, then @var{copy_size} bytes from @var{input} are copied into
+it, and the new memory is returned.  If fewer bytes are copied than were
+allocated, the remaining memory is zeroed.
+
+@end deftypefn
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "ansidecl.h"
+#include "libiberty.h"
+
+#include <sys/types.h> /* For size_t. */
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+PTR
+xmemdup (input, copy_size, alloc_size)
+  const PTR input;
+  size_t copy_size;
+  size_t alloc_size;
+{
+  PTR output = xcalloc (1, alloc_size);
+  memcpy (output, input, copy_size);
+  return output;
+}

GCC/libiberty/xstrdup.c

+/* xstrdup.c -- Duplicate a string in memory, using xmalloc.
+   This trivial function is in the public domain.
+   Ian Lance Taylor, Cygnus Support, December 1995.  */
+
+/*
+
+@deftypefn Replacement char* xstrdup (const char *@var{s})
+
+Duplicates a character string without fail, using @code{xmalloc} to
+obtain memory.
+
+@end deftypefn
+
+*/
+
+#include <sys/types.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#include "ansidecl.h"
+#include "libiberty.h"
+
+char *
+xstrdup (s)
+  const char *s;
+{
+  register size_t len = strlen (s) + 1;
+  register char *ret = xmalloc (len);
+  memcpy (ret, s, len);
+  return ret;
+}