summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libiberty.h55
-rw-r--r--include/obstack.h18
-rw-r--r--include/splay-tree.h9
-rw-r--r--include/symcat.h4
-rw-r--r--libiberty/basename.c39
-rw-r--r--libiberty/calloc.c3
-rw-r--r--libiberty/config.table3
-rw-r--r--libiberty/getcwd.c10
-rw-r--r--libiberty/makefile.vms2
-rw-r--r--libiberty/random.c35
-rw-r--r--libiberty/strtol.c5
-rw-r--r--libiberty/strtoul.c7
-rw-r--r--libiberty/tmpnam.c2
-rw-r--r--libiberty/vmsbuild.com2
-rw-r--r--libiberty/xstrdup.c1
15 files changed, 136 insertions, 59 deletions
diff --git a/include/libiberty.h b/include/libiberty.h
index cf313662ef4..9a536a4a194 100644
--- a/include/libiberty.h
+++ b/include/libiberty.h
@@ -19,7 +19,7 @@ extern "C" {
/* Build an argument vector from a string. Allocates memory using
malloc. Use freeargv to free the vector. */
-extern char **buildargv PARAMS ((char *));
+extern char **buildargv PARAMS ((char *)) ATTRIBUTE_MALLOC;
/* Free a vector returned by buildargv. */
@@ -28,7 +28,7 @@ extern void freeargv PARAMS ((char **));
/* Duplicate an argument vector. Allocates memory using malloc. Use
freeargv to free the vector. */
-extern char **dupargv PARAMS ((char **));
+extern char **dupargv PARAMS ((char **)) ATTRIBUTE_MALLOC;
/* Return the last component of a path name. Note that we can't use a
@@ -36,7 +36,7 @@ extern char **dupargv PARAMS ((char **));
across different systems, sometimes as "char *" and sometimes as
"const char *" */
-#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__)
+#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__)
extern char *basename PARAMS ((const char *));
#else
extern char *basename ();
@@ -45,19 +45,28 @@ extern char *basename ();
/* Concatenate an arbitrary number of strings, up to (char *) NULL.
Allocates memory using xmalloc. */
-extern char *concat PARAMS ((const char *, ...));
+extern char *concat PARAMS ((const char *, ...)) ATTRIBUTE_MALLOC;
/* Check whether two file descriptors refer to the same file. */
extern int fdmatch PARAMS ((int fd1, int fd2));
+/* Get the working directory. The result is cached, so don't call
+ chdir() between calls to getpwd(). */
+
+extern char * getpwd PARAMS ((void));
+
/* Get the amount of time the process has run, in microseconds. */
extern long get_run_time PARAMS ((void));
/* Choose a temporary directory to use for scratch files. */
-extern char *choose_temp_base PARAMS ((void));
+extern char *choose_temp_base PARAMS ((void)) ATTRIBUTE_MALLOC;
+
+/* Return a temporary file name or NULL if unable to create one. */
+
+extern char *make_temp_file PARAMS ((const char *)) ATTRIBUTE_MALLOC;
/* Allocate memory filled with spaces. Allocates using malloc. */
@@ -108,11 +117,7 @@ extern int xatexit PARAMS ((void (*fn) (void)));
/* Exit, calling all the functions registered with xatexit. */
-#ifndef __GNUC__
-extern void xexit PARAMS ((int status));
-#else
-void xexit PARAMS ((int status)) __attribute__ ((noreturn));
-#endif
+extern void xexit PARAMS ((int status)) ATTRIBUTE_NORETURN;
/* Set the program name used by xmalloc. */
@@ -125,24 +130,29 @@ extern void xmalloc_set_program_name PARAMS ((const char *));
#ifdef ANSI_PROTOTYPES
/* Get a definition for size_t. */
#include <stddef.h>
+/* Get a definition for va_list. */
+#include <stdarg.h>
#endif
-extern PTR xmalloc PARAMS ((size_t));
-
-/* Reallocate memory without fail. This works like xmalloc.
+extern PTR xmalloc PARAMS ((size_t)) ATTRIBUTE_MALLOC;
- FIXME: We do not declare the parameter types for the same reason as
- xmalloc. */
+/* Reallocate memory without fail. This works like xmalloc. Note,
+ realloc type functions are not suitable for attribute malloc since
+ they may return the same address across multiple calls. */
extern PTR xrealloc PARAMS ((PTR, size_t));
/* Allocate memory without fail and set it to zero. This works like
xmalloc. */
-extern PTR xcalloc PARAMS ((size_t, size_t));
+extern PTR xcalloc PARAMS ((size_t, size_t)) ATTRIBUTE_MALLOC;
/* Copy a string into a memory buffer without fail. */
-extern char *xstrdup PARAMS ((const char *));
+extern char *xstrdup PARAMS ((const char *)) ATTRIBUTE_MALLOC;
+
+/* Copy an existing memory buffer to a new memory buffer without fail. */
+
+extern PTR xmemdup PARAMS ((const PTR, size_t, size_t)) ATTRIBUTE_MALLOC;
/* hex character manipulation routines */
@@ -172,6 +182,17 @@ extern int pexecute PARAMS ((const char *, char * const *, const char *,
extern int pwait PARAMS ((int, int *, int));
+/* Like sprintf but provides a pointer to malloc'd storage, which must
+ be freed by the caller. */
+
+extern int asprintf PARAMS ((char **, const char *, ...)) ATTRIBUTE_PRINTF_2;
+
+/* Like vsprintf but provides a pointer to malloc'd storage, which
+ must be freed by the caller. */
+
+extern int vasprintf PARAMS ((char **, const char *, va_list))
+ ATTRIBUTE_PRINTF(2,0);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/obstack.h b/include/obstack.h
index 38e96777660..a20ab55967a 100644
--- a/include/obstack.h
+++ b/include/obstack.h
@@ -143,12 +143,16 @@ extern "C" {
#if defined _LIBC || defined HAVE_STRING_H
# include <string.h>
-# define _obstack_memcpy(To, From, N) memcpy ((To), (From), (N))
+# if defined __STDC__ && __STDC__
+# define _obstack_memcpy(To, From, N) memcpy ((To), (From), (N))
+# else
+# define _obstack_memcpy(To, From, N) memcpy ((To), (char *)(From), (N))
+# endif
#else
# ifdef memcpy
-# define _obstack_memcpy(To, From, N) memcpy ((To), (From), (N))
+# define _obstack_memcpy(To, From, N) memcpy ((To), (char *)(From), (N))
# else
-# define _obstack_memcpy(To, From, N) bcopy ((From), (To), (N))
+# define _obstack_memcpy(To, From, N) bcopy ((char *)(From), (To), (N))
# endif
#endif
@@ -385,7 +389,7 @@ __extension__ \
int __len = (length); \
if (__o->next_free + __len > __o->chunk_limit) \
_obstack_newchunk (__o, __len); \
- _obstack_memcpy (__o->next_free, (char *) (where), __len); \
+ _obstack_memcpy (__o->next_free, (where), __len); \
__o->next_free += __len; \
(void) 0; })
@@ -395,7 +399,7 @@ __extension__ \
int __len = (length); \
if (__o->next_free + __len + 1 > __o->chunk_limit) \
_obstack_newchunk (__o, __len + 1); \
- _obstack_memcpy (__o->next_free, (char *) (where), __len); \
+ _obstack_memcpy (__o->next_free, (where), __len); \
__o->next_free += __len; \
*(__o->next_free)++ = 0; \
(void) 0; })
@@ -510,14 +514,14 @@ __extension__ \
( (h)->temp = (length), \
(((h)->next_free + (h)->temp > (h)->chunk_limit) \
? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \
- _obstack_memcpy ((h)->next_free, (char *) (where), (h)->temp), \
+ _obstack_memcpy ((h)->next_free, (where), (h)->temp), \
(h)->next_free += (h)->temp)
# define obstack_grow0(h,where,length) \
( (h)->temp = (length), \
(((h)->next_free + (h)->temp + 1 > (h)->chunk_limit) \
? (_obstack_newchunk ((h), (h)->temp + 1), 0) : 0), \
- _obstack_memcpy ((h)->next_free, (char *) (where), (h)->temp), \
+ _obstack_memcpy ((h)->next_free, (where), (h)->temp), \
(h)->next_free += (h)->temp, \
*((h)->next_free)++ = 0)
diff --git a/include/splay-tree.h b/include/splay-tree.h
index e828fe7e907..6d70c8d9075 100644
--- a/include/splay-tree.h
+++ b/include/splay-tree.h
@@ -44,7 +44,7 @@ typedef unsigned long int splay_tree_key;
typedef unsigned long int splay_tree_value;
/* Forward declaration for a node in the tree. */
-typedef struct splay_tree_node *splay_tree_node;
+typedef struct splay_tree_node_s *splay_tree_node;
/* The type of a function which compares two splay-tree keys. The
function should return values as for qsort. */
@@ -62,7 +62,7 @@ typedef void (*splay_tree_delete_value_fn) PARAMS((splay_tree_value));
typedef int (*splay_tree_foreach_fn) PARAMS((splay_tree_node, void*));
/* The nodes in the splay tree. */
-struct splay_tree_node
+struct splay_tree_node_s
{
/* The key. */
splay_tree_key key;
@@ -76,7 +76,7 @@ struct splay_tree_node
};
/* The splay tree itself. */
-typedef struct splay_tree
+typedef struct splay_tree_s
{
/* The root of the tree. */
splay_tree_node root;
@@ -95,7 +95,8 @@ extern splay_tree splay_tree_new PARAMS((splay_tree_compare_fn,
splay_tree_delete_key_fn,
splay_tree_delete_value_fn));
extern void splay_tree_delete PARAMS((splay_tree));
-extern void splay_tree_insert PARAMS((splay_tree,
+extern splay_tree_node splay_tree_insert
+ PARAMS((splay_tree,
splay_tree_key,
splay_tree_value));
extern splay_tree_node splay_tree_lookup
diff --git a/include/symcat.h b/include/symcat.h
index 01efada2618..3e27162b264 100644
--- a/include/symcat.h
+++ b/include/symcat.h
@@ -1,6 +1,6 @@
/* Symbol concatenation utilities.
- Copyright (C) 1998, Free Software Foundation, Inc.
+ Copyright (C) 1998, 2000 Free Software Foundation, Inc.
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
@@ -28,7 +28,7 @@
#define CONCAT2(a,b) a/**/b
#define CONCAT3(a,b,c) a/**/b/**/c
#define CONCAT4(a,b,c,d) a/**/b/**/c/**/d
-#define STRINGX(s) "?"
+#define STRINGX(s) "s"
#endif
#define XCONCAT2(a,b) CONCAT2(a,b)
diff --git a/libiberty/basename.c b/libiberty/basename.c
index f544c853910..7698f06f8ae 100644
--- a/libiberty/basename.c
+++ b/libiberty/basename.c
@@ -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;
}
+
diff --git a/libiberty/calloc.c b/libiberty/calloc.c
index c8c0a78a7a1..334b18db86a 100644
--- a/libiberty/calloc.c
+++ b/libiberty/calloc.c
@@ -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"
diff --git a/libiberty/config.table b/libiberty/config.table
index 5913b23ad63..4e33746164c 100644
--- a/libiberty/config.table
+++ b/libiberty/config.table
@@ -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
diff --git a/libiberty/getcwd.c b/libiberty/getcwd.c
index 06d55c04f58..47b1c1eec31 100644
--- a/libiberty/getcwd.c
+++ b/libiberty/getcwd.c
@@ -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;
diff --git a/libiberty/makefile.vms b/libiberty/makefile.vms
index b61b51290da..6a7dd45718e 100644
--- a/libiberty/makefile.vms
+++ b/libiberty/makefile.vms
@@ -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])
diff --git a/libiberty/random.c b/libiberty/random.c
index 0a950709fce..ef00da0a5ae 100644
--- a/libiberty/random.c
+++ b/libiberty/random.c
@@ -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.
*/
/*
diff --git a/libiberty/strtol.c b/libiberty/strtol.c
index 37d170660f2..5467cc3e2e9 100644
--- a/libiberty/strtol.c
+++ b/libiberty/strtol.c
@@ -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.
diff --git a/libiberty/strtoul.c b/libiberty/strtoul.c
index ff6f2d6784d..2ec32043e6b 100644
--- a/libiberty/strtoul.c
+++ b/libiberty/strtoul.c
@@ -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;
diff --git a/libiberty/tmpnam.c b/libiberty/tmpnam.c
index c0614677425..8eb77e28c0b 100644
--- a/libiberty/tmpnam.c
+++ b/libiberty/tmpnam.c
@@ -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"
diff --git a/libiberty/vmsbuild.com b/libiberty/vmsbuild.com
index 4fede380bfd..497ea8974f2 100644
--- a/libiberty/vmsbuild.com
+++ b/libiberty/vmsbuild.com
@@ -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 = ""
$!
diff --git a/libiberty/xstrdup.c b/libiberty/xstrdup.c
index e16aba08554..6f846cfea15 100644
--- a/libiberty/xstrdup.c
+++ b/libiberty/xstrdup.c
@@ -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