summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorGreg McGary <greg@mcgary.org>1997-04-18 06:43:35 +0000
committerGreg McGary <greg@mcgary.org>1997-04-18 06:43:35 +0000
commit3720d4b7a1b0ce0903450271aa3d93388e9d8781 (patch)
tree12200295d735bf3d1bcaaf8d2065547d41cea3b2 /lib
parent916418ea1284e6aa64f50eba077e48ced5944acc (diff)
downloadidutils-r3_1.tar.gz
idutils-r3_1.tar.bz2
idutils-r3_1.zip
imported from id-utils-3.1r3_1
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am32
-rw-r--r--lib/Makefile.in193
-rw-r--r--lib/basename.c42
-rw-r--r--lib/dirname.c9
-rw-r--r--lib/error.c6
-rw-r--r--lib/obstack.c48
-rw-r--r--lib/obstack.h97
-rw-r--r--lib/strndup.c10
-rw-r--r--lib/xmalloc.h38
9 files changed, 250 insertions, 225 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 520f05e..4d67679 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,28 +1,22 @@
## Process this file with automake to create Makefile.in
-AUTOMAKE_OPTIONS = ansi2knr
+noinst_LIBRARIES = sys
-noinst_LIBRARIES = idu
+EXTRA_DIST = alloca.c basename.c dirname.c error.c fnmatch.c getopt.c \
+ getopt1.c memcpy.c memset.c obstack.c regex.c rx.c \
+ strcasecmp.c strcspn.c strdup.c strndup.c strpbrk.c strspn.c \
+ strstr.c strtok.c
-EXTRA_DIST = alloca.c error.c getopt.c getopt1.c regex.c rx.c \
- strcasecmp.c strdup.c strndup.c strtok.c \
- obstack.c basename.c dirname.c fnmatch.c \
- ansi2knr.1 ansi2knr.c
+sys_SOURCES = xgetcwd.c xmalloc.c
-idu_SOURCES = misc.c scanners.c idfile.c filenames.c bitops.c token.c \
- idwalk.c hash.c dynvec.c xmalloc.c xgetcwd.c
-
-idudir = $(prefix)/share
-idu_DATA = language.map
-
-noinst_HEADERS = alloc.h bitops.h error.h filenames.h getopt.h idarg.h \
- idfile.h misc.h regex.h rx.h scanners.h strxtra.h \
- token.h system.h hash.h obstack.h pathmax.h dynvec.h \
- xmalloc.h fnmatch.h ansidecl.h
+noinst_HEADERS = ansidecl.h error.h fnmatch.h getopt.h obstack.h \
+ pathmax.h regex.h rx.h xalloca.h xdirent.h xfnmatch.h \
+ xmalloc.h xobstack.h xstddef.h xstdlib.h xstring.h xsysstat.h \
+ xunistd.h
+
INCLUDES = -I. -I$(srcdir) \
- -I../lib -I$(top_srcdir)/lib \
-I../intl -I$(top_srcdir)/intl \
-I.. -I$(top_srcdir)
-DEFS = -DLOCALEDIR=\"$(localedir)\" -DLANGUAGE_MAP=\"$(idudir)/language.map\" @DEFS@
-idu_LIBADD = @REGEXOBJ@ @LIBOBJS@ @ALLOCA@
+DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
+sys_LIBADD = @REGEXOBJ@ @LIBOBJS@ @ALLOCA@
diff --git a/lib/Makefile.in b/lib/Makefile.in
index ef55b85..2e51ac8 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -38,37 +38,30 @@ INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
-AUTOMAKE_OPTIONS = ansi2knr
+noinst_LIBRARIES = sys
-noinst_LIBRARIES = idu
+EXTRA_DIST = alloca.c basename.c dirname.c error.c fnmatch.c getopt.c \
+ getopt1.c memcpy.c memset.c obstack.c regex.c rx.c \
+ strcasecmp.c strcspn.c strdup.c strndup.c strpbrk.c strspn.c \
+ strstr.c strtok.c
-EXTRA_DIST = alloca.c error.c getopt.c getopt1.c regex.c rx.c \
- strcasecmp.c strdup.c strndup.c strtok.c \
- obstack.c basename.c dirname.c fnmatch.c \
- ansi2knr.1 ansi2knr.c
+sys_SOURCES = xgetcwd.c xmalloc.c
-idu_SOURCES = misc.c scanners.c idfile.c filenames.c bitops.c token.c \
- idwalk.c hash.c dynvec.c xmalloc.c xgetcwd.c
-
-idudir = $(prefix)/share
-idu_DATA = language.map
-
-noinst_HEADERS = alloc.h bitops.h error.h filenames.h getopt.h idarg.h \
- idfile.h misc.h regex.h rx.h scanners.h strxtra.h \
- token.h system.h hash.h obstack.h pathmax.h dynvec.h \
- xmalloc.h fnmatch.h ansidecl.h
+noinst_HEADERS = ansidecl.h error.h fnmatch.h getopt.h obstack.h \
+ pathmax.h regex.h rx.h xalloca.h xdirent.h xfnmatch.h \
+ xmalloc.h xobstack.h xstddef.h xstdlib.h xstring.h xsysstat.h \
+ xunistd.h
INCLUDES = -I. -I$(srcdir) \
- -I../lib -I$(top_srcdir)/lib \
-I../intl -I$(top_srcdir)/intl \
-I.. -I$(top_srcdir)
-DEFS = -DLOCALEDIR=\"$(localedir)\" -DLANGUAGE_MAP=\"$(idudir)/language.map\" @DEFS@
-idu_LIBADD = @REGEXOBJ@ @LIBOBJS@ @ALLOCA@
+DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
+sys_LIBADD = @REGEXOBJ@ @LIBOBJS@ @ALLOCA@
mkinstalldirs = $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = ../config.h
LIBRARIES = $(noinst_LIBRARIES)
-noinst_LIBFILES = libidu.a
+noinst_LIBFILES = libsys.a
CC = @CC@
LEX = @LEX@
@@ -80,17 +73,11 @@ LIBS = @LIBS@
COMPILE = $(CC) -c $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
LINK = $(CC) $(LDFLAGS) -o $@
-
-ANSI2KNR = @ANSI2KNR@
-o = .@U@o
-idu_OBJECTS = misc$o scanners$o idfile$o filenames$o bitops$o token$o \
-idwalk$o hash$o dynvec$o xmalloc$o xgetcwd$o
-EXTRA_idu_SOURCES =
-LIBFILES = libidu.a
+sys_OBJECTS = xgetcwd.o xmalloc.o
+EXTRA_sys_SOURCES =
+LIBFILES = libsys.a
AR = ar
RANLIB = @RANLIB@
-DATA = $(idu_DATA)
-
HEADERS = $(noinst_HEADERS)
DIST_COMMON = Makefile.am Makefile.in
@@ -105,8 +92,8 @@ DEP_DISTFILES = $(DIST_COMMON) $(SOURCES) $(BUILT_SOURCES) $(HEADERS) \
$(TEXINFOS) $(INFO_DEPS) $(MANS) $(EXTRA_DIST) $(DATA)
TAR = tar
-SOURCES = $(idu_SOURCES)
-OBJECTS = $(idu_OBJECTS)
+SOURCES = $(sys_SOURCES)
+OBJECTS = $(sys_OBJECTS)
default: all
@@ -138,57 +125,12 @@ distclean-compile:
rm -f *.tab.c
maintainer-clean-compile:
+$(sys_OBJECTS): ../config.h
-.c._c:
- $(ANSI2KNR) $< > $*.tmp && mv $*.tmp $@
-
-._c._o:
- @echo $(COMPILE) $<
- @rm -f _$*.c
- @ln $< _$*.c && $(COMPILE) _$*.c && mv _$*.o $@ && rm _$*.c
-
-.c._o:
- $(ANSI2KNR) $< > $*.tmp && mv $*.tmp $*._c
- @echo $(COMPILE) $*._c
- @rm -f _$*.c
- @ln $*._c _$*.c && $(COMPILE) _$*.c && mv _$*.o $@ && rm _$*.c
-
-ansi2knr: ansi2knr.o
- $(LINK) ansi2knr.o $(LIBS)
-
-$(OBJECTS): $(ANSI2KNR)
-ansi2knr.o: $(CONFIG_HEADER)
-
-mostlyclean-kr:
- rm -f *._o *._c _*.c _*.o
-
-clean-kr:
-
-distclean-kr:
- rm -f ansi2knr
-
-maintainer-clean-kr:
-$(idu_OBJECTS): ../config.h
-
-libidu.a: $(idu_OBJECTS) $(idu_LIBADD)
- rm -f libidu.a
- $(AR) cru libidu.a $(idu_OBJECTS) $(idu_LIBADD)
- $(RANLIB) libidu.a
-
-install-iduDATA: $(idu_DATA)
- $(mkinstalldirs) $(idudir)
- list="$(idu_DATA)"; for p in $$list; do \
- if test -f $(srcdir)/$$p; then \
- $(INSTALL_DATA) $(srcdir)/$$p $(idudir)/$$p; \
- else if test -f $$p; then \
- $(INSTALL_DATA) $$p $(idudir)/$$p; \
- fi; fi; \
- done
-
-uninstall-iduDATA:
- list="$(idu_DATA)"; for p in $$list; do \
- rm -f $(idudir)/$$p; \
- done
+libsys.a: $(sys_OBJECTS) $(sys_LIBADD)
+ rm -f libsys.a
+ $(AR) cru libsys.a $(sys_OBJECTS) $(sys_LIBADD)
+ $(RANLIB) libsys.a
ID: $(HEADERS) $(SOURCES)
here=`pwd` && cd $(srcdir) && mkid -f$$here/ID $(SOURCES) $(HEADERS)
@@ -215,41 +157,24 @@ distdir: $(DEP_DISTFILES)
|| ln $(srcdir)/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $(srcdir)/$$file $(distdir)/$$file; \
done
-alloca.o: alloca.c
-basename.o: basename.c
-bitops.o: bitops.c bitops.h
-dirname.o: dirname.c strxtra.h
-dynvec.o: dynvec.c dynvec.h alloc.h
-error.o: error.c
-filenames$o: filenames.c system.h \
- strxtra.h filenames.h misc.h \
- error.h
-fnmatch.o: fnmatch.c
-getopt.o: getopt.c
-getopt1.o: getopt1.c getopt.h
-hash.o: hash.c hash.h alloc.h \
- error.h
-idfile.o: idfile.c alloc.h idfile.h \
- hash.h strxtra.h error.h
-idwalk$o: idwalk.c system.h idfile.h \
- hash.h error.h alloc.h \
- dynvec.h strxtra.h scanners.h \
- pathmax.h
-memcpy.o: memcpy.c
-memset.o: memset.c
-misc.o: misc.c system.h strxtra.h \
- misc.h
-scanners$o: scanners.c system.h error.h \
- strxtra.h token.h alloc.h \
- scanners.h
-strcasecmp.o: strcasecmp.c
-strdup.o: strdup.c
-strerror.o: strerror.c
-strndup$o: strndup.c
-strtok.o: strtok.c
-token.o: token.c token.h
-xgetcwd.o: xgetcwd.c pathmax.h
-xmalloc.o: xmalloc.c error.h
+alloca.o: ../lib/alloca.c
+basename.o: ../lib/basename.c ../lib/xstring.h
+dirname.o: ../lib/dirname.c ../lib/xstring.h
+error.o: ../lib/error.c
+fnmatch.o: ../lib/fnmatch.c
+getopt.o: ../lib/getopt.c
+getopt1.o: ../lib/getopt1.c ../lib/getopt.h
+memcpy.o: ../lib/memcpy.c
+memset.o: ../lib/memset.c
+strcspn.o: ../lib/strcspn.c
+strdup.o: ../lib/strdup.c
+strndup.o: ../lib/strndup.c ../lib/xstring.h ../lib/xmalloc.h
+strpbrk.o: ../lib/strpbrk.c
+strspn.o: ../lib/strspn.c
+strstr.o: ../lib/strstr.c
+strtok.o: ../lib/strtok.c
+xgetcwd.o: ../lib/xgetcwd.c ../lib/pathmax.h
+xmalloc.o: ../lib/xmalloc.c ../lib/error.h
info:
@@ -261,19 +186,18 @@ installcheck:
install-exec:
-install-data: install-iduDATA
+install-data:
install: install-exec install-data all
@:
-uninstall: uninstall-iduDATA
+uninstall:
-all: $(LIBFILES) $(DATA) $(HEADERS) Makefile
+all: $(LIBFILES) $(HEADERS) Makefile
install-strip:
$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install
installdirs:
- $(mkinstalldirs) $(idudir)
mostlyclean-generic:
@@ -290,35 +214,32 @@ maintainer-clean-generic:
test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES)
test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
mostlyclean: mostlyclean-noinstLIBRARIES mostlyclean-compile \
- mostlyclean-kr mostlyclean-tags mostlyclean-generic
+ mostlyclean-tags mostlyclean-generic
-clean: clean-noinstLIBRARIES clean-compile clean-kr clean-tags \
- clean-generic mostlyclean
+clean: clean-noinstLIBRARIES clean-compile clean-tags clean-generic \
+ mostlyclean
-distclean: distclean-noinstLIBRARIES distclean-compile distclean-kr \
- distclean-tags distclean-generic clean
+distclean: distclean-noinstLIBRARIES distclean-compile distclean-tags \
+ distclean-generic clean
rm -f config.status
maintainer-clean: maintainer-clean-noinstLIBRARIES \
- maintainer-clean-compile maintainer-clean-kr \
- maintainer-clean-tags maintainer-clean-generic \
- distclean
+ maintainer-clean-compile maintainer-clean-tags \
+ maintainer-clean-generic distclean
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
.PHONY: default mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \
clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \
mostlyclean-compile distclean-compile clean-compile \
-maintainer-clean-compile mostlyclean-kr distclean-kr clean-kr \
-maintainer-clean-kr uninstall-iduDATA install-iduDATA tags \
-mostlyclean-tags distclean-tags clean-tags maintainer-clean-tags \
-distdir info dvi check installcheck install-exec install-data install \
-uninstall all installdirs mostlyclean-generic distclean-generic \
-clean-generic maintainer-clean-generic clean mostlyclean distclean \
-maintainer-clean
+maintainer-clean-compile tags mostlyclean-tags distclean-tags \
+clean-tags maintainer-clean-tags distdir info dvi check installcheck \
+install-exec install-data install uninstall all installdirs \
+mostlyclean-generic distclean-generic clean-generic \
+maintainer-clean-generic clean mostlyclean distclean maintainer-clean
.SUFFIXES:
-.SUFFIXES: .c .o ._c ._o
+.SUFFIXES: .c .o
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
diff --git a/lib/basename.c b/lib/basename.c
index e474866..22d3edd 100644
--- a/lib/basename.c
+++ b/lib/basename.c
@@ -1,32 +1,34 @@
/* basename.c -- return the last element in a path
- Copyright (C) 1994 Free Software Foundation, Inc.
- This file is part of the Linux C Library.
-
-The Linux 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 Linux 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., 675 Mass Ave,
-Cambridge, MA 02139, USA. */
+ Copyright (C) 1996 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
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program 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 this program; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <ansidecl.h>
-#include <string.h>
+#include "xstring.h"
/* Return NAME with any leading path stripped off. */
-CONST char *
+char *
DEFUN(basename, (name), CONST char *name)
{
char *base;
base = strrchr (name, '/');
- return base ? base + 1 : name;
+ return base ? base + 1 : (char *) name;
}
diff --git a/lib/dirname.c b/lib/dirname.c
index 09f82aa..17439e8 100644
--- a/lib/dirname.c
+++ b/lib/dirname.c
@@ -16,14 +16,15 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
-#include <ansidecl.h>
-#include <string.h>
+#ifdef HAVE_CONFIG_H
#include <config.h>
-#include "strxtra.h"
+#endif
+#include <ansidecl.h>
+#include "xstring.h"
/* Return NAME with any leading path stripped off. */
-CONST char *
+char *
DEFUN(dirname, (name), CONST char *name)
{
char *base;
diff --git a/lib/error.c b/lib/error.c
index 797b697..42e2c6c 100644
--- a/lib/error.c
+++ b/lib/error.c
@@ -17,11 +17,14 @@
/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
+#define sys_errlist sidestep_sys_errlist_declaration
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
+#include <errno.h>
#if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC
# if __STDC__
@@ -68,9 +71,8 @@ static char *
private_strerror (errnum)
int errnum;
{
-#if !HAVE_DECL_SYS_ERRLIST
+#undef sys_errlist
extern char *sys_errlist[];
-#endif
extern int sys_nerr;
if (errnum > 0 && errnum <= sys_nerr)
diff --git a/lib/obstack.c b/lib/obstack.c
index f0df0d7..a5ffe9f 100644
--- a/lib/obstack.c
+++ b/lib/obstack.c
@@ -1,5 +1,5 @@
/* obstack.c - subroutines used implicitly by object stack macros
- Copyright (C) 1988, 89, 90, 91, 92, 93, 94 Free Software Foundation, Inc.
+ Copyright (C) 1988,89,90,91,92,93,94,96 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
@@ -17,29 +17,33 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "obstack.h"
-/* This is just to get __GNU_LIBRARY__ defined. */
-#include <stdio.h>
+/* NOTE BEFORE MODIFYING THIS FILE: This version number must be
+ incremented whenever callers compiled using an old obstack.h can no
+ longer properly call the functions in this obstack.c. */
+#define OBSTACK_INTERFACE_VERSION 1
/* Comment out all this code if we are using the GNU C Library, and are not
- actually compiling the library itself. This code is part of the GNU C
- Library, but also included in many other GNU distributions. Compiling
+ actually compiling the library itself, and the installed library
+ supports the same library interface we do. This code is part of the GNU
+ C Library, but also included in many other GNU distributions. Compiling
and linking in this code is a waste when using the GNU C library
(especially if it is a shared library). Rather than having every GNU
- program understand `configure --with-gnu-libc' and omit the object files,
- it is simpler to just do this in the source for each such file. */
+ program understand `configure --with-gnu-libc' and omit the object
+ files, it is simpler to just do this in the source for each such file. */
+
+#include <stdio.h> /* Random thing to get __GNU_LIBRARY__. */
+#if !defined (_LIBC) && defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
+#include <gnu-versions.h>
+#if _GNU_OBSTACK_INTERFACE_VERSION == OBSTACK_INTERFACE_VERSION
+#define ELIDE_CODE
+#endif
+#endif
+
-/* CYGNUS LOCAL. No, don't comment the code out. We will be using
- ../include/obstack.h, which was changed relatively recently in a
- way that is not binary compatible. Until we feel confident that
- nobody is using the old obstack.c code, force the use of this code.
- This issue will arise anytime a change is made which is not binary
- compatible.
-#if defined (_LIBC) || !defined (__GNU_LIBRARY__)
-*/
-#if 1
+#ifndef ELIDE_CODE
-#if __STDC__
+#if defined (__STDC__) && __STDC__
#define POINTER void *
#else
#define POINTER char *
@@ -77,14 +81,14 @@ struct obstack *_obstack;
#define CALL_CHUNKFUN(h, size) \
(((h) -> use_extra_arg) \
? (*(h)->chunkfun) ((h)->extra_arg, (size)) \
- : (*(h)->chunkfun) ((size)))
+ : (*(struct _obstack_chunk *(*) ()) (h)->chunkfun) ((size)))
#define CALL_FREEFUN(h, old_chunk) \
do { \
if ((h) -> use_extra_arg) \
(*(h)->freefun) ((h)->extra_arg, (old_chunk)); \
else \
- (*(h)->freefun) ((old_chunk)); \
+ (*(void (*) ()) (h)->freefun) ((old_chunk)); \
} while (0)
@@ -275,7 +279,7 @@ _obstack_newchunk (h, length)
This is here for debugging.
If you use it in a program, you are probably losing. */
-#if __STDC__
+#if defined (__STDC__) && __STDC__
/* Suppress -Wmissing-prototypes warning. We don't want to declare this in
obstack.h because it is just for debugging. */
int _obstack_allocated_p (struct obstack *h, POINTER obj);
@@ -382,7 +386,7 @@ obstack_free (h, obj)
/* Now define the functional versions of the obstack macros.
Define them to simply use the corresponding macros to do the job. */
-#if __STDC__
+#if defined (__STDC__) && __STDC__
/* These function definitions do not work with non-ANSI preprocessors;
they won't pass through the macro names in parentheses. */
@@ -490,4 +494,4 @@ POINTER (obstack_copy0) (obstack, pointer, length)
#endif /* 0 */
-#endif /* _LIBC or not __GNU_LIBRARY__. */
+#endif /* !ELIDE_CODE */
diff --git a/lib/obstack.h b/lib/obstack.h
index 40793ca..886d59d 100644
--- a/lib/obstack.h
+++ b/lib/obstack.h
@@ -1,5 +1,5 @@
/* obstack.h - object stack macros
- Copyright (C) 1988, 89, 90, 91, 92, 93, 94 Free Software Foundation, Inc.
+ Copyright (C) 1988,89,90,91,92,93,94,96 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
@@ -107,6 +107,30 @@ Summary:
because on word-addressable machines a simple cast to int
may ignore the byte-within-word field of the pointer. */
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#if HAVE_STRING_H || STDC_HEADERS
+#include <string.h>
+
+#ifndef bcmp
+#define bcmp(s1, s2, n) memcmp ((s1), (s2), (n))
+#endif
+
+#ifndef bcopy
+#define bcopy(s, d, n) memcpy ((d), (s), (n))
+#endif
+
+#ifndef bzero
+#define bzero(s, n) memset ((s), 0, (n))
+#endif
+
+#else /* HAVE_STRING_H || STDC_HEADERS */
+#include <strings.h>
+#endif /* not (HAVE_STRING_H || STDC_HEADERS) */
+
+
#ifndef __PTR_TO_INT
#define __PTR_TO_INT(P) ((P) - (char *)0)
#endif
@@ -119,7 +143,7 @@ Summary:
but in traditional C it is usually long. If we are in ANSI C and
don't already have ptrdiff_t get it. */
-#if __STDC__ && ! defined (offsetof)
+#if defined (__STDC__) && __STDC__ && ! defined (offsetof)
#if defined (__GNUC__) && defined (IN_GCC)
/* On Next machine, the system's stddef.h screws up if included
after we have defined just ptrdiff_t, so include all of stddef.h.
@@ -138,7 +162,7 @@ Summary:
# define ptrdiff_t off_t
#endif
-#if __STDC__
+#if defined (__STDC__) && __STDC__
#define PTR_INT_TYPE ptrdiff_t
#else
#define PTR_INT_TYPE long
@@ -160,9 +184,18 @@ struct obstack /* control current object in current chunk */
char *chunk_limit; /* address of char after current chunk */
PTR_INT_TYPE temp; /* Temporary for some macros. */
int alignment_mask; /* Mask of alignment for each object. */
+#if defined (__STDC__) && __STDC__
+ /* These prototypes vary based on `use_extra_arg', and we use
+ casts to the prototypeless function type in all assignments,
+ but having prototypes here quiets -Wstrict-prototypes. */
+ struct _obstack_chunk *(*chunkfun) (void *, long);
+ void (*freefun) (void *, struct _obstack_chunk *);
+ void *extra_arg; /* first arg for chunk alloc/dealloc funcs */
+#else
struct _obstack_chunk *(*chunkfun) (); /* User's fcn to allocate a chunk. */
void (*freefun) (); /* User's function to free a chunk. */
char *extra_arg; /* first arg for chunk alloc/dealloc funcs */
+#endif
unsigned use_extra_arg:1; /* chunk alloc/dealloc funcs take extra arg */
unsigned maybe_empty_object:1;/* There is a possibility that the current
chunk contains a zero-length object. This
@@ -173,13 +206,14 @@ struct obstack /* control current object in current chunk */
/* Declare the external functions we use; they are in obstack.c. */
-#if __STDC__
+#if defined (__STDC__) && __STDC__
extern void _obstack_newchunk (struct obstack *, int);
extern void _obstack_free (struct obstack *, void *);
extern int _obstack_begin (struct obstack *, int, int,
- void *(*) (), void (*) ());
+ void *(*) (long), void (*) (void *));
extern int _obstack_begin_1 (struct obstack *, int, int,
- void *(*) (), void (*) (), void *);
+ void *(*) (void *, long),
+ void (*) (void *, void *), void *);
#else
extern void _obstack_newchunk ();
extern void _obstack_free ();
@@ -187,7 +221,7 @@ extern int _obstack_begin ();
extern int _obstack_begin_1 ();
#endif
-#if __STDC__
+#if defined (__STDC__) && __STDC__
/* Do the function-declarations after the structs
but before defining the macros. */
@@ -248,6 +282,34 @@ int obstack_chunk_size (struct obstack *obstack);
#define obstack_alignment_mask(h) ((h)->alignment_mask)
+/* To prevent prototype warnings provide complete argument list in
+ standard C version. */
+#if defined (__STDC__) && __STDC__
+
+#define obstack_init(h) \
+ _obstack_begin ((h), 0, 0, \
+ (void *(*) (long)) obstack_chunk_alloc, (void (*) (void *)) obstack_chunk_free)
+
+#define obstack_begin(h, size) \
+ _obstack_begin ((h), (size), 0, \
+ (void *(*) (long)) obstack_chunk_alloc, (void (*) (void *)) obstack_chunk_free)
+
+#define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \
+ _obstack_begin ((h), (size), (alignment), \
+ (void *(*) (long)) (chunkfun), (void (*) (void *)) (freefun))
+
+#define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \
+ _obstack_begin_1 ((h), (size), (alignment), \
+ (void *(*) (long)) (chunkfun), (void (*) (void *)) (freefun), (arg))
+
+#define obstack_chunkfun(h, newchunkfun) \
+ ((h) -> chunkfun = (struct _obstack_chunk *(*)(long)) (newchunkfun))
+
+#define obstack_freefun(h, newfreefun) \
+ ((h) -> freefun = (void (*)(void *)) (newfreefun))
+
+#else
+
#define obstack_init(h) \
_obstack_begin ((h), 0, 0, \
(void *(*) ()) obstack_chunk_alloc, (void (*) ()) obstack_chunk_free)
@@ -270,12 +332,17 @@ int obstack_chunk_size (struct obstack *obstack);
#define obstack_freefun(h, newfreefun) \
((h) -> freefun = (void (*)()) (newfreefun))
+#endif
+
#define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = achar)
#define obstack_blank_fast(h,n) ((h)->next_free += (n))
-#if defined (__GNUC__) && __STDC__
-#if __GNUC__ < 2
+#if defined (__GNUC__) && defined (__STDC__) && __STDC__
+/* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and
+ does not implement __extension__. But that compiler doesn't define
+ __GNUC_MINOR__. */
+#if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__)
#define __extension__
#endif
@@ -303,7 +370,7 @@ __extension__ \
_obstack_newchunk (__o, __len); \
if (!__o->alloc_failed) \
{ \
- bcopy (where, __o->next_free, __len); \
+ bcopy ((char *) (where), __o->next_free, __len); \
__o->next_free += __len; \
} \
(void) 0; })
@@ -316,7 +383,7 @@ __extension__ \
_obstack_newchunk (__o, __len + 1); \
if (!__o->alloc_failed) \
{ \
- bcopy (where, __o->next_free, __len); \
+ bcopy ((char *) (where), __o->next_free, __len); \
__o->next_free += __len; \
*(__o->next_free)++ = 0; \
} \
@@ -334,7 +401,7 @@ __extension__ \
/* These assume that the obstack alignment is good enough for pointers or ints,
and that the data added so far to the current object
shares that much alignment. */
-
+
#define obstack_ptr_grow(OBSTACK,datum) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
@@ -434,7 +501,7 @@ __extension__ \
(((h)->next_free + (h)->temp > (h)->chunk_limit) \
? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \
((h)->alloc_failed ? 0 : \
- (bcopy (where, (h)->next_free, (h)->temp), \
+ (bcopy ((char *) (where), (h)->next_free, (h)->temp), \
(h)->next_free += (h)->temp)))
#define obstack_grow0(h,where,length) \
@@ -442,7 +509,7 @@ __extension__ \
(((h)->next_free + (h)->temp + 1 > (h)->chunk_limit) \
? (_obstack_newchunk ((h), (h)->temp + 1), 0) : 0), \
((h)->alloc_failed ? 0 : \
- (bcopy (where, (h)->next_free, (h)->temp), \
+ (bcopy ((char *) (where), (h)->next_free, (h)->temp), \
(h)->next_free += (h)->temp, \
*((h)->next_free)++ = 0)))
@@ -498,7 +565,7 @@ __extension__ \
(h)->object_base = (h)->next_free, \
__INT_TO_PTR ((h)->temp)))
-#if __STDC__
+#if defined (__STDC__) && __STDC__
#define obstack_free(h,obj) \
( (h)->temp = (char *)(obj) - (char *) (h)->chunk, \
(((h)->temp > 0 && (h)->temp < (h)->chunk_limit - (char *) (h)->chunk)\
diff --git a/lib/strndup.c b/lib/strndup.c
index 556215d..1694d73 100644
--- a/lib/strndup.c
+++ b/lib/strndup.c
@@ -15,22 +15,22 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
+#include <config.h>
#include <ansidecl.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
+#include "xstring.h"
+#include "xmalloc.h"
/* Duplicate S, returning an identical malloc'd string. */
char *
-DEFUN(strndup, (s, n), CONST char *s AND size_t n)
+DEFUN(strndup, (s, n), const char *s AND size_t n)
{
char *new = malloc(n + 1);
if (new == NULL)
return NULL;
- memcpy (new, (PTR) s, n);
+ memcpy (new, s, n);
new[n] = '\0';
return new;
diff --git a/lib/xmalloc.h b/lib/xmalloc.h
index 622b31b..8273276 100644
--- a/lib/xmalloc.h
+++ b/lib/xmalloc.h
@@ -1,12 +1,46 @@
+/* xmalloc.h -- malloc declarations wrapper
+ Copyright (C) 1996 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
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
#ifndef _xmalloc_h_
#define _xmalloc_h_ 1
#include <sys/types.h>
-#ifdef HAVE_CONFIG_H
-#include <config.h>
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+#if defined STDC_HEADERS || defined _LIBC || defined HAVE_STDLIB_H
+# include <stdlib.h>
#endif
+#if HAVE_MALLOC_H
+# include <malloc.h>
+#else
+void free ();
+#endif
+
void *xmalloc __P((size_t n));
void *xrealloc __P((void *p, size_t n));
+#include "xstring.h"
+
+#define CALLOC(t, n) ((t *) calloc (sizeof (t), (n)))
+#define MALLOC(t, n) ((t *) xmalloc (sizeof (t) * (n)))
+#define REALLOC(o, t, n) ((t *) xrealloc ((o), sizeof (t) * (n)))
+#define CLONE(o, t, n) ((t *) memcpy (MALLOC (t, (n)), (o), sizeof (t) * (n)))
+
#endif /* _xmalloc_h_ */