This commit was generated by cvs2svn to track changes on a CVS vendor

branch.
This commit is contained in:
Ian Lance Taylor 2000-02-22 15:59:20 +00:00
commit abd8680d6e
20 changed files with 3372 additions and 29 deletions

View file

@ -14,24 +14,53 @@ DESCRIPTION
last component of the pathname ("ls.c" in this case).
BUGS
Presumes a UNIX style path with UNIX style separators.
Presumes a UNIX or DOS/Windows style path with UNIX or DOS/Windows
style separators.
*/
#include "ansidecl.h"
#include "libiberty.h"
#include <ctype.h>
#ifndef DIR_SEPARATOR
#define DIR_SEPARATOR '/'
#endif
#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \
defined (__OS2__)
#define HAVE_DOS_BASED_FILE_SYSTEM
#ifndef DIR_SEPARATOR_2
#define DIR_SEPARATOR_2 '\\'
#endif
#endif
/* Define IS_DIR_SEPARATOR. */
#ifndef DIR_SEPARATOR_2
# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
#else /* DIR_SEPARATOR_2 */
# define IS_DIR_SEPARATOR(ch) \
(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
#endif /* DIR_SEPARATOR_2 */
char *
basename (name)
const char *name;
{
const char *base = name;
const char *base;
while (*name)
#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
/* Skip over the disk name in MSDOS pathnames. */
if (isalpha (name[0]) && name[1] == ':')
name += 2;
#endif
for (base = name; *name; name++)
{
if (*name++ == '/')
if (IS_DIR_SEPARATOR (*name))
{
base = name;
base = name + 1;
}
}
return (char *) base;
}

View file

@ -1,3 +1,6 @@
/* calloc -- allocate memory which has been initialized to zero.
This function is in the public domain. */
#include "ansidecl.h"
#include "libiberty.h"

View file

@ -4,6 +4,7 @@ case "${host}" in
*-*-cxux7*) frag=mh-cxux7 ;;
*-*-freebsd2.1.*) frag=mh-fbsd21 ;;
*-*-freebsd2.2.[012]) frag=mh-fbsd21 ;;
i370-*-opened*) frag=mh-openedition ;;
i[345]86-*-windows*) frag=mh-windows ;;
*-*-beos*) frag=mh-beos ;;
esac
@ -57,4 +58,4 @@ else
fi
frag=xhost-mkfrag
${CONFIG_SHELL} ${libiberty_topdir}/move-if-change temp-frag xhost-mkfrag
${CONFIG_SHELL-/bin/sh} ${libiberty_topdir}/move-if-change temp-frag xhost-mkfrag

View file

@ -0,0 +1,3 @@
HDEFINES = -D_ALL_SOURCE
CC=c89

View file

@ -14,6 +14,9 @@ DESCRIPTION
current directory's path doesn't fit in LEN characters, the result
is NULL and errno is set.
If pathname is a null pointer, getcwd() will obtain size bytes of
space using malloc.
BUGS
Emulated via the getwd() call, which is reasonable for most
systems that do not have getcwd().
@ -48,6 +51,13 @@ getcwd (buf, len)
errno = ERANGE;
return 0;
}
if (!buf) {
buf = (char*)malloc(len);
if (!buf) {
errno = ENOMEM;
return 0;
}
}
strcpy (buf, ourbuf);
}
return buf;

115
libiberty/getpwd.c Normal file
View file

@ -0,0 +1,115 @@
/* getpwd.c - get the working directory */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <errno.h>
#ifndef errno
extern int errno;
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
/* Prototype these in case the system headers don't provide them. */
extern char *getpwd ();
extern char *getwd ();
#include "libiberty.h"
/* Virtually every UN*X system now in common use (except for pre-4.3-tahoe
BSD systems) now provides getcwd as called for by POSIX. Allow for
the few exceptions to the general rule here. */
#if !defined(HAVE_GETCWD) && defined(HAVE_GETWD)
#define getcwd(buf,len) getwd(buf)
#endif
#ifdef MAXPATHLEN
#define GUESSPATHLEN (MAXPATHLEN + 1)
#else
#define GUESSPATHLEN 100
#endif
#if !(defined (VMS) || (defined(_WIN32) && !defined(__CYGWIN__)))
/* Get the working directory. Use the PWD environment variable if it's
set correctly, since this is faster and gives more uniform answers
to the user. Yield the working directory if successful; otherwise,
yield 0 and set errno. */
char *
getpwd ()
{
static char *pwd;
static int failure_errno;
char *p = pwd;
size_t s;
struct stat dotstat, pwdstat;
if (!p && !(errno = failure_errno))
{
if (! ((p = getenv ("PWD")) != 0
&& *p == '/'
&& stat (p, &pwdstat) == 0
&& stat (".", &dotstat) == 0
&& dotstat.st_ino == pwdstat.st_ino
&& dotstat.st_dev == pwdstat.st_dev))
/* The shortcut didn't work. Try the slow, ``sure'' way. */
for (s = GUESSPATHLEN; ! getcwd (p = xmalloc (s), s); s *= 2)
{
int e = errno;
free (p);
#ifdef ERANGE
if (e != ERANGE)
#endif
{
errno = failure_errno = e;
p = 0;
break;
}
}
/* Cache the result. This assumes that the program does
not invoke chdir between calls to getpwd. */
pwd = p;
}
return p;
}
#else /* VMS || _WIN32 && !__CYGWIN__ */
#ifndef MAXPATHLEN
#define MAXPATHLEN 255
#endif
char *
getpwd ()
{
static char *pwd = 0;
if (!pwd)
pwd = getcwd (xmalloc (MAXPATHLEN + 1), MAXPATHLEN + 1
#ifdef VMS
, 0
#endif
);
return pwd;
}
#endif /* VMS || _WIN32 && !__CYGWIN__ */

330
libiberty/hashtab.c Normal file
View file

@ -0,0 +1,330 @@
/* An expandable hash tables datatype.
Copyright (C) 1999 Free Software Foundation, Inc.
Contributed by Vladimir Makarov (vmakarov@cygnus.com).
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. */
/* This package implements basic hash table functionality. It is possible
to search for an entry, create an entry and destroy an entry.
Elements in the table are generic pointers.
The size of the table is not fixed; if the occupancy of the table
grows too high the hash table will be expanded.
The abstract data implementation is based on generalized Algorithm D
from Knuth's book "The art of computer programming". Hash table is
expanded by creation of new hash table and transferring elements from
the old table to the new table. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <stdio.h>
#include "libiberty.h"
#include "hashtab.h"
/* The following variable is used for debugging. Its value is number
of all calls of `find_hash_table_entry' for all hash tables. */
static int all_searches = 0;
/* The following variable is used for debugging. Its value is number
of collisions fixed for time of work with all hash tables. */
static int all_collisions = 0;
/* The following variable is used for debugging. Its value is number
of all table expansions fixed for time of work with all hash
tables. */
static int all_expansions = 0;
/* This macro defines reserved value for empty table entry. */
#define EMPTY_ENTRY NULL
/* This macro defines reserved value for table entry which contained
a deleted element. */
#define DELETED_ENTRY ((void *) 1)
/* The following function returns the nearest prime number which is
greater than given source number. */
static unsigned long
higher_prime_number (number)
unsigned long number;
{
unsigned long i;
for (number = (number / 2) * 2 + 3;; number += 2)
{
for (i = 3; i * i <= number; i += 2)
if (number % i == 0)
break;
if (i * i > number)
return number;
}
}
/* This function creates table with length slightly longer than given
source length. Created hash table is initiated as empty (all the
hash table entries are EMPTY_ENTRY). The function returns the
created hash table. */
hash_table_t
create_hash_table (size, hash_function, eq_function)
size_t size;
unsigned (*hash_function) PARAMS ((hash_table_entry_t));
int (*eq_function) PARAMS ((hash_table_entry_t, hash_table_entry_t));
{
hash_table_t result;
size = higher_prime_number (size);
result = (hash_table_t) xmalloc (sizeof (*result));
result->entries
= (hash_table_entry_t *) xmalloc (size * sizeof (hash_table_entry_t));
result->size = size;
result->hash_function = hash_function;
result->eq_function = eq_function;
result->number_of_elements = 0;
result->number_of_deleted_elements = 0;
result->searches = 0;
result->collisions = 0;
memset (result->entries, 0, size * sizeof (hash_table_entry_t));
return result;
}
/* This function frees all memory allocated for given hash table.
Naturally the hash table must already exist. */
void
delete_hash_table (htab)
hash_table_t htab;
{
free (htab->entries);
free (htab);
}
/* This function clears all entries in the given hash table. */
void
empty_hash_table (htab)
hash_table_t htab;
{
memset (htab->entries, 0, htab->size * sizeof (hash_table_entry_t));
}
/* The following function changes size of memory allocated for the
entries and repeatedly inserts the table elements. The occupancy
of the table after the call will be about 50%. Naturally the hash
table must already exist. Remember also that the place of the
table entries is changed. */
static void
expand_hash_table (htab)
hash_table_t htab;
{
hash_table_t new_htab;
hash_table_entry_t *entry_ptr;
hash_table_entry_t *new_entry_ptr;
new_htab = create_hash_table (htab->number_of_elements * 2,
htab->hash_function, htab->eq_function);
for (entry_ptr = htab->entries; entry_ptr < htab->entries + htab->size;
entry_ptr++)
if (*entry_ptr != EMPTY_ENTRY && *entry_ptr != DELETED_ENTRY)
{
new_entry_ptr = find_hash_table_entry (new_htab, *entry_ptr, 1);
*new_entry_ptr = (*entry_ptr);
}
free (htab->entries);
*htab = (*new_htab);
free (new_htab);
}
/* This function searches for hash table entry which contains element
equal to given value or empty entry in which given value can be
placed (if the element with given value does not exist in the
table). The function works in two regimes. The first regime is
used only for search. The second is used for search and
reservation empty entry for given value. The table is expanded if
occupancy (taking into accout also deleted elements) is more than
75%. Naturally the hash table must already exist. If reservation
flag is TRUE then the element with given value should be inserted
into the table entry before another call of
`find_hash_table_entry'. */
hash_table_entry_t *
find_hash_table_entry (htab, element, reserve)
hash_table_t htab;
hash_table_entry_t element;
int reserve;
{
hash_table_entry_t *entry_ptr;
hash_table_entry_t *first_deleted_entry_ptr;
unsigned index, hash_value, secondary_hash_value;
if (htab->size * 3 <= htab->number_of_elements * 4)
{
all_expansions++;
expand_hash_table (htab);
}
hash_value = (*htab->hash_function) (element);
secondary_hash_value = 1 + hash_value % (htab->size - 2);
index = hash_value % htab->size;
htab->searches++;
all_searches++;
first_deleted_entry_ptr = NULL;
for (;;htab->collisions++, all_collisions++)
{
entry_ptr = htab->entries + index;
if (*entry_ptr == EMPTY_ENTRY)
{
if (reserve)
{
htab->number_of_elements++;
if (first_deleted_entry_ptr != NULL)
{
entry_ptr = first_deleted_entry_ptr;
*entry_ptr = EMPTY_ENTRY;
}
}
break;
}
else if (*entry_ptr != DELETED_ENTRY)
{
if ((*htab->eq_function) (*entry_ptr, element))
break;
}
else if (first_deleted_entry_ptr == NULL)
first_deleted_entry_ptr = entry_ptr;
index += secondary_hash_value;
if (index >= htab->size)
index -= htab->size;
}
return entry_ptr;
}
/* This function deletes element with given value from hash table.
The hash table entry value will be `DELETED_ENTRY' after the
function call. Naturally the hash table must already exist. Hash
table entry for given value should be not empty (or deleted). */
void
remove_element_from_hash_table_entry (htab, element)
hash_table_t htab;
hash_table_entry_t element;
{
hash_table_entry_t *entry_ptr;
entry_ptr = find_hash_table_entry (htab, element, 0);
*entry_ptr = DELETED_ENTRY;
htab->number_of_deleted_elements++;
}
/* This function clears a specified slot in a hash table.
It is useful when you've already done the lookup and don't want to
do it again. */
void
clear_hash_table_slot (htab, slot)
hash_table_t htab;
hash_table_entry_t *slot;
{
if (slot < htab->entries || slot >= htab->entries + htab->size
|| *slot == EMPTY_ENTRY || *slot == DELETED_ENTRY)
abort ();
*slot = DELETED_ENTRY;
htab->number_of_deleted_elements++;
}
/* This function scans over the entire hash table calling
CALLBACK for each live entry. If CALLBACK returns false,
the iteration stops. INFO is passed as CALLBACK's second
argument. */
void
traverse_hash_table (htab, callback, info)
hash_table_t htab;
int (*callback) PARAMS ((hash_table_entry_t, void *));
void *info;
{
hash_table_entry_t *entry_ptr;
for (entry_ptr = htab->entries; entry_ptr < htab->entries + htab->size;
entry_ptr++)
if (*entry_ptr != EMPTY_ENTRY && *entry_ptr != DELETED_ENTRY)
if (!callback (*entry_ptr, info))
break;
}
/* The following function returns current size of given hash table. */
size_t
hash_table_size (htab)
hash_table_t htab;
{
return htab->size;
}
/* The following function returns current number of elements in given
hash table. */
size_t
hash_table_elements_number (htab)
hash_table_t htab;
{
return htab->number_of_elements - htab->number_of_deleted_elements;
}
/* The following function returns number of percents of fixed
collisions during all work with given hash table. */
int
hash_table_collisions (htab)
hash_table_t htab;
{
int searches;
searches = htab->searches;
if (searches == 0)
searches++;
return htab->collisions * 100 / searches;
}
/* The following function returns number of percents of fixed
collisions during all work with all hash tables. */
int
all_hash_table_collisions ()
{
int searches;
searches = all_searches;
if (searches == 0)
searches++;
return all_collisions * 100 / searches;
}

View file

@ -10,7 +10,7 @@
OBJS=bcopy.obj,bcmp.obj,getopt.obj,obstack.obj,xexit.obj,xmalloc.obj,hex.obj,\
getopt1.obj,cplus-dem.obj,strncasecmp.obj,strcasecmp.obj,strdup.obj,\
concat.obj,getruntime.obj,getpagesize.obj,alloca.obj,xstrerror.obj,\
xstrdup.obj,xatexit.obj,choose-temp.obj,fnmatch.obj,objalloc.obj
xmemdup.obj,xstrdup.obj,xatexit.obj,choose-temp.obj,fnmatch.obj,objalloc.obj
ifeq ($(CC),gcc)
CFLAGS=/include=([],[-.include])

68
libiberty/putenv.c Normal file
View file

@ -0,0 +1,68 @@
/* Copyright (C) 1991, 1994, 1995, 1996 Free Software Foundation, Inc.
This file based on putenv.c in the GNU C Library.
The GNU C Library 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.
The GNU C 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#if defined (_AIX) && !defined (__GNUC__)
#pragma alloca
#endif
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include "ansidecl.h"
#if HAVE_STDLIB_H
# include <stdlib.h>
#endif
#if HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_ALLOCA_H
# include <alloca.h>
#else
# ifndef alloca
# ifdef __GNUC__
# define alloca __builtin_alloca
# else
extern char *alloca ();
# endif /* __GNUC__ */
# endif /* alloca */
#endif /* HAVE_ALLOCA_H */
/* Below this point, it's verbatim code from the glibc-2.0 implementation */
/* Put STRING, which is of the form "NAME=VALUE", in the environment. */
int
putenv (string)
const char *string;
{
const char *const name_end = strchr (string, '=');
if (name_end)
{
char *name = (char *) alloca (name_end - string + 1);
memcpy (name, string, name_end - string);
name[name_end - string] = '\0';
return setenv (name, name_end + 1, 1);
}
unsetenv (string);
return 0;
}

View file

@ -2,17 +2,30 @@
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* 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.
*/
/*

163
libiberty/setenv.c Normal file
View file

@ -0,0 +1,163 @@
/* Copyright (C) 1992, 1995, 1996, 1997 Free Software Foundation, Inc.
This file based on setenv.c in the GNU C Library.
The GNU C Library 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.
The GNU C 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include "ansidecl.h"
#include <sys/types.h> /* For `size_t' */
#include <stdio.h> /* For `NULL' */
#include <errno.h>
#if !defined(errno) && !defined(HAVE_ERRNO_DECL)
extern int errno;
#endif
#define __set_errno(ev) ((errno) = (ev))
#if HAVE_STDLIB_H
# include <stdlib.h>
#endif
#if HAVE_STRING_H
# include <string.h>
#endif
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#define __environ environ
#ifndef HAVE_ENVIRON_DECL
extern char **environ;
#endif
/* LOCK and UNLOCK are defined as no-ops. This makes the libiberty
* implementation MT-Unsafe. */
#define LOCK
#define UNLOCK
/* Below this point, it's verbatim code from the glibc-2.0 implementation */
/* If this variable is not a null pointer we allocated the current
environment. */
static char **last_environ;
int
setenv (name, value, replace)
const char *name;
const char *value;
int replace;
{
register char **ep;
register size_t size;
const size_t namelen = strlen (name);
const size_t vallen = strlen (value) + 1;
LOCK;
size = 0;
if (__environ != NULL)
for (ep = __environ; *ep != NULL; ++ep)
if (!strncmp (*ep, name, namelen) && (*ep)[namelen] == '=')
break;
else
++size;
if (__environ == NULL || *ep == NULL)
{
char **new_environ;
if (__environ == last_environ && __environ != NULL)
/* We allocated this space; we can extend it. */
new_environ = (char **) realloc (last_environ,
(size + 2) * sizeof (char *));
else
new_environ = (char **) malloc ((size + 2) * sizeof (char *));
if (new_environ == NULL)
{
UNLOCK;
return -1;
}
new_environ[size] = malloc (namelen + 1 + vallen);
if (new_environ[size] == NULL)
{
free ((char *) new_environ);
__set_errno (ENOMEM);
UNLOCK;
return -1;
}
if (__environ != last_environ)
memcpy ((char *) new_environ, (char *) __environ,
size * sizeof (char *));
memcpy (new_environ[size], name, namelen);
new_environ[size][namelen] = '=';
memcpy (&new_environ[size][namelen + 1], value, vallen);
new_environ[size + 1] = NULL;
last_environ = __environ = new_environ;
}
else if (replace)
{
size_t len = strlen (*ep);
if (len + 1 < namelen + 1 + vallen)
{
/* The existing string is too short; malloc a new one. */
char *new = malloc (namelen + 1 + vallen);
if (new == NULL)
{
UNLOCK;
return -1;
}
*ep = new;
}
memcpy (*ep, name, namelen);
(*ep)[namelen] = '=';
memcpy (&(*ep)[namelen + 1], value, vallen);
}
UNLOCK;
return 0;
}
void
unsetenv (name)
const char *name;
{
const size_t len = strlen (name);
char **ep;
LOCK;
for (ep = __environ; *ep; ++ep)
if (!strncmp (*ep, name, len) && (*ep)[len] == '=')
{
/* Found it. Remove this pointer by moving later ones back. */
char **dp = ep;
do
dp[0] = dp[1];
while (*dp++);
/* Continue the loop in case NAME appears again. */
}
UNLOCK;
}

View file

@ -10,10 +10,7 @@
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 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.

View file

@ -10,10 +10,7 @@
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 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.
@ -91,7 +88,7 @@ strtoul(nptr, endptr, base)
break;
if (c >= base)
break;
if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
any = -1;
else {
any = 1;

View file

@ -0,0 +1,75 @@
#
# Makefile
# Copyright (C) 1999
# Free Software Foundation
#
# 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.
#
# This file was written by Tom Tromey <tromey@cygnus.com>.
#
# Makefile for libiberty/testsuite directory
#
srcdir = @srcdir@
VPATH = @srcdir@
SHELL = @SHELL@
CC = @CC@
CFLAGS = @CFLAGS@
LIBCFLAGS = $(CFLAGS)
# Multilib support variables.
MULTISRCTOP =
INCDIR=$(srcdir)/../$(MULTISRCTOP)../include
all:
check: @CHECK@
# Run some tests of the demangler.
check-cplus-dem: test-filter $(srcdir)/demangle-expected
$(SHELL) $(srcdir)/regress-demangle $(srcdir)/demangle-expected
# Note that we just hard-code prepends_underscore to 0. This doesn't
# matter since any particular test can override the default if need
# be.
TEST_COMPILE = $(CC) @DEFS@ $(LIBCFLAGS) -I.. -I$(INCDIR) $(HDEFINES)
test-filter: $(srcdir)/../cplus-dem.c
echo 'int prepends_underscore = 0;' > test-us.c
$(TEST_COMPILE) -o test-filter -DMAIN -DVERSION='"none"' @DEFS@ \
$(srcdir)/../cplus-dem.c test-us.c -L.. -liberty
# Standard (either GNU or Cygnus) rules we don't use.
info install-info clean-info dvi install etags tags installcheck:
# The standard clean rules.
mostlyclean:
rm -f test-us.c test-filter
clean: mostlyclean
distclean: clean
rm -f Makefile
maintainer-clean realclean: distclean
Makefile: $(srcdir)/Makefile.in ../config.status
CONFIG_FILES=testsuite/Makefile CONFIG_HEADERS= \
cd .. && $(SHELL) ./config.status

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,28 @@
#! /bin/sh
# Run a regression test for the demangler.
# Usage: regress-demangle TEST-FILE
failures=0
count=0
sed -e '/^#/ d' "$1" | (
while read type; do
read mangled
read demangled
x="`echo $mangled | ./test-filter $type`"
count=`expr $count + 1`
if test "x$x" != "x$demangled"; then
failures=`expr $failures + 1`
echo "FAIL: $type $mangled"
fi
done
if test $failures -eq 0; then
echo "All $count tests passed"
else
echo "$failures of $count tests failed"
fi
test $failures -eq 0
)

View file

@ -1,7 +1,7 @@
#include <stdio.h>
#ifndef L_tmpnam
#define L_tmpname 100
#define L_tmpnam 100
#endif
#ifndef P_tmpdir
#define P_tmpdir "/usr/tmp"

View file

@ -15,7 +15,7 @@ $! 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 xstrdup.o xstrerror.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 = ""
$!

22
libiberty/xmemdup.c Normal file
View file

@ -0,0 +1,22 @@
/* xmemdup.c -- Duplicate a memory buffer, using xcalloc.
This trivial function is in the public domain.
Jeff Garzik, September 1999. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "ansidecl.h"
#include "libiberty.h"
#include <sys/types.h> /* For size_t. */
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;
}

View file

@ -2,6 +2,7 @@
This trivial function is in the public domain.
Ian Lance Taylor, Cygnus Support, December 1995. */
#include <sys/types.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif