summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2001-01-04 16:39:09 +0000
committerBruno Haible <bruno@clisp.org>2001-01-04 16:39:09 +0000
commiteaf396d26252324da43cfc02edef4163af4c8f5a (patch)
tree9d1f659f740b89cf95cfe11728fc06b8844ffacb
parentb5b46b39517187905714bc8d00363e5af9f207ca (diff)
downloadexternal_gettext-eaf396d26252324da43cfc02edef4163af4c8f5a.zip
external_gettext-eaf396d26252324da43cfc02edef4163af4c8f5a.tar.gz
external_gettext-eaf396d26252324da43cfc02edef4163af4c8f5a.tar.bz2
Update the lib directory with new files from glibc-2.2, fetish utils etc.
-rw-r--r--Admin/plans2
-rw-r--r--lib/ChangeLog58
-rw-r--r--lib/basename.c41
-rw-r--r--lib/error.c12
-rw-r--r--lib/fstrcmp.h4
-rw-r--r--lib/getline.c15
-rw-r--r--lib/getline.h7
-rw-r--r--lib/getopt.c69
-rw-r--r--lib/getopt.h93
-rw-r--r--lib/hash.c103
-rw-r--r--lib/hash.h27
-rw-r--r--lib/memmove.c122
-rw-r--r--lib/memset.c101
-rw-r--r--lib/obstack.c28
-rw-r--r--lib/obstack.h27
-rw-r--r--lib/pathmax.h47
-rw-r--r--lib/printf-parse.h21
-rw-r--r--lib/printf-prs.c93
-rw-r--r--lib/printf.h4
-rw-r--r--lib/strstr.c4
-rw-r--r--lib/strtol.c242
-rw-r--r--lib/vasprintf.c2
-rw-r--r--lib/xgetcwd.c48
-rw-r--r--lib/xmalloc.c24
-rw-r--r--lib/xstrdup.c13
-rw-r--r--src/ChangeLog5
-rw-r--r--src/msgfmt.c7
27 files changed, 672 insertions, 547 deletions
diff --git a/Admin/plans b/Admin/plans
index 1826065..a2476c2 100644
--- a/Admin/plans
+++ b/Admin/plans
@@ -1,7 +1,5 @@
Things we plan to do. Comments welcome.
-- Update lib/ with some files from fetish utils.
-
- Update other files from libtool-1.3.5 and autoconf-2.13.
- For gcc: Making the .pot files is maintainer mode; otherwise building
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 8ce8ff7..4bee6c6 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,10 +1,66 @@
2000-12-30 Bruno Haible <haible@clisp.cons.org>
+ * basename.c: Update from current fileutils version, keeping the
+ function name as `basename' or `gnu_basename'.
+
+ * error.c: Update from glibc-2.2 version.
+
+ * fstrcmp.h: extern declaration.
+
+ * getline.h: Comment out declarations on glibc2 systems.
+ * getline.c: Make getstr() static, to avoid conflict with libncurses.
+
+ * getopt.h: Update from glibc-2.2 version.
+ * getopt.c: Likewise.
+
+ * hash.h: Update from glibc-2.2 version. Don't assume keys are NUL
+ terminated.
+ (insert_entry, find_entry): Change argument type from 'const char*' to
+ 'const void*'.
+ (iterate_table): Add keylen argument.
+ * hash.c: Update from glibc-2.2 version. Don't assume keys are NUL
+ terminated.
+ (xcalloc): New declaration.
+ (struct hash_entry): Add keylen field.
+ (init_hash): Use xcalloc instead of xmalloc.
+ (insert_entry_2): Add keylen argument. Use xcalloc instead of xmalloc.
+ (iterate_table): Add keylen argument.
+ (lookup): Compare using memcmp, not strncmp.
+ (lookup_2): Add keylen argument. Compare using memcmp, not strcmp.
+
+ * memmove.c: Revert to gettext-0.10.35 version, independent of glibc.
+ * memset.c: Likewise.
+
+ * obstack.h: Update from glibc-2.2 version. Add a few consts.
+ * obstack.c: Update from glibc-2.2 version.
+
+ * pathmax.h: Update from current fileutils version.
+
+ * printf-prs.c: Revert to old, not multibyte aware version. Since the
+ messages in the catalog can be in any encoding, use of the current
+ locale's encoding is wrong here.
+ * printf-parse.h (find_spec): Likewise.
+
+ * strtol.c: Update from glibc-2.2 version.
+
+ * strstr.c (strstr): Add an empty statement after 'shloop' label.
+
* vasprintf.c: Include stdlib.h if it exists.
(int_vasprintf): Increase buffer size for float/double values with
- positive exponent only.
+ positive exponent only. Recognize new ISO C99 length modifiers 'j',
+ 't', 'z'.
(main): Add more tests.
+ * xgetcwd.c (xgetcwd): If the required pathname length is smaller
+ than 1024, return a memory chunk of least possible size, instead
+ of size PATH_MAX + 2. In the loop, increment the size proportionally.
+ Use free/xmalloc instead of xrealloc to avoid copying for very long
+ paths.
+
+ * xmalloc.c: Use NULL where appropriate.
+
+ * xstrdup.c (xstrdup): Change argument type to 'const char *'.
+
1999-12-27 Geoff Keating <geoffk@cygnus.com>
* vasprintf.c (int_vasprintf): Don't re-read the format character
diff --git a/lib/basename.c b/lib/basename.c
index 52ecb51..db7d658 100644
--- a/lib/basename.c
+++ b/lib/basename.c
@@ -1,5 +1,5 @@
/* Return the name-within-directory of a file name.
- Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
NOTE: The canonical source of this file is maintained with the GNU C Library.
Bugs can be reported to bug-glibc@prep.ai.mit.edu.
@@ -23,7 +23,15 @@
# include <config.h>
#endif
-#include <string.h>
+#include <assert.h>
+
+#ifndef FILESYSTEM_PREFIX_LEN
+# define FILESYSTEM_PREFIX_LEN(Filename) 0
+#endif
+
+#ifndef ISSLASH
+# define ISSLASH(C) ((C) == '/')
+#endif
#ifndef _LIBC
/* We cannot generally use the name `basename' since XPG defines an unusable
@@ -31,11 +39,32 @@
# define basename gnu_basename
#endif
+/* In general, we can't use the builtin `basename' function if available,
+ since it has different meanings in different environments.
+ In some environments the builtin `basename' modifies its argument.
+ If NAME is all slashes, be sure to return `/'. */
char *
-basename (filename)
- const char *filename;
+basename (char const *name)
{
- char *p = strrchr (filename, '/');
- return p ? p + 1 : (char *) filename;
+ char const *base = name += FILESYSTEM_PREFIX_LEN (name);
+ int all_slashes = 1;
+ char const *p;
+
+ for (p = name; *p; p++)
+ {
+ if (ISSLASH (*p))
+ base = p + 1;
+ else
+ all_slashes = 0;
+ }
+
+ /* If NAME is all slashes, arrange to return `/'. */
+ if (*base == '\0' && ISSLASH (*name) && all_slashes)
+ --base;
+
+ /* Make sure the last byte is not a slash. */
+ assert (all_slashes || !ISSLASH (*(p - 1)));
+
+ return (char *) base;
}
diff --git a/lib/error.c b/lib/error.c
index 140fa77..43c0df2 100644
--- a/lib/error.c
+++ b/lib/error.c
@@ -1,5 +1,5 @@
/* Error handler for noninteractive utilities
- Copyright (C) 1990,91,92,93,94,95,96,97,98 Free Software Foundation, Inc.
+ Copyright (C) 1990-1998, 2000 Free Software Foundation, Inc.
NOTE: The canonical source of this file is maintained with the GNU C Library.
@@ -27,6 +27,7 @@
#endif
#include <stdio.h>
+#include <libintl.h>
#if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC
# if __STDC__
@@ -77,6 +78,11 @@ unsigned int error_message_count;
# define error __error
# define error_at_line __error_at_line
+# ifdef USE_IN_LIBIO
+# include <libio/iolibio.h>
+# define fflush(s) _IO_fflush (s)
+# endif
+
#else /* not _LIBC */
/* The calling program should define program_name and set it to the
@@ -151,7 +157,7 @@ error (status, errnum, message, va_alist)
++error_message_count;
if (errnum)
{
-#if defined HAVE_STRERROR_R || defined _LIBC
+#if defined HAVE_STRERROR_R || _LIBC
char errbuf[1024];
fprintf (stderr, ": %s", __strerror_r (errnum, errbuf, sizeof errbuf));
#else
@@ -226,7 +232,7 @@ error_at_line (status, errnum, file_name, line_number, message, va_alist)
++error_message_count;
if (errnum)
{
-#if defined HAVE_STRERROR_R || defined _LIBC
+#if defined HAVE_STRERROR_R || _LIBC
char errbuf[1024];
fprintf (stderr, ": %s", __strerror_r (errnum, errbuf, sizeof errbuf));
#else
diff --git a/lib/fstrcmp.h b/lib/fstrcmp.h
index 0404717..422f650 100644
--- a/lib/fstrcmp.h
+++ b/lib/fstrcmp.h
@@ -1,5 +1,5 @@
/* GNU gettext - internationalization aids
- Copyright (C) 1995 Free Software Foundation, Inc.
+ Copyright (C) 1995, 2000 Free Software Foundation, Inc.
This file was written by Peter Miller <pmiller@agso.gov.au>
@@ -20,6 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifndef _FSTRCMP_H
#define _FSTRCMP_H
-double fstrcmp PARAMS ((const char *__s1, const char *__s2));
+extern double fstrcmp PARAMS ((const char *__s1, const char *__s2));
#endif
diff --git a/lib/getline.c b/lib/getline.c
index ba05abb..4bbdfe9 100644
--- a/lib/getline.c
+++ b/lib/getline.c
@@ -24,7 +24,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* The `getdelim' function is only declared if the following symbol
is defined. */
-#define _GNU_SOURCE 1
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+#endif
#include <stdio.h>
#include <sys/types.h>
@@ -39,16 +41,16 @@ getline (lineptr, n, stream)
return getdelim (lineptr, n, '\n', stream);
}
-
#else /* ! have getdelim */
# define NDEBUG
# include <assert.h>
-# if STDC_HEADERS
+# if HAVE_STDLIB_H
# include <stdlib.h>
# else
-char *malloc (), *realloc ();
+extern char *malloc ();
+extern char *realloc ();
# endif
/* Always add at least this many bytes when extending the buffer. */
@@ -58,9 +60,10 @@ char *malloc (), *realloc ();
+ OFFSET (and null-terminate it). *LINEPTR is a pointer returned from
malloc (or NULL), pointing to *N characters of space. It is realloc'd
as necessary. Return the number of characters read (not including the
- null terminator), or -1 on error or EOF. */
+ null terminator), or -1 on error or EOF.
+ NOTE: There is another getstr() function declared in <curses.h>. */
-int
+static int
getstr (lineptr, n, stream, terminator, offset)
char **lineptr;
size_t *n;
diff --git a/lib/getline.h b/lib/getline.h
index cc6466d..a2aa231 100644
--- a/lib/getline.h
+++ b/lib/getline.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995 Free Software Foundation, Inc.
+/* Copyright (C) 1995, 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
@@ -27,10 +27,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
# endif
# endif
+/* glibc2 has these functions declared in <stdio.h>. Avoid redeclarations. */
+# if __GLIBC__ < 2
+
int
getline PARAMS ((char **_lineptr, size_t *_n, FILE *_stream));
int
getdelim PARAMS ((char **_lineptr, size_t *_n, int _delimiter, FILE *_stream));
+# endif
+
#endif /* not GETLINE_H_ */
diff --git a/lib/getopt.c b/lib/getopt.c
index 7da985f..bdcc8f3 100644
--- a/lib/getopt.c
+++ b/lib/getopt.c
@@ -3,7 +3,7 @@
"Keep this file name-space clean" means, talk to drepper@gnu.org
before changing it!
- Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98
+ Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000
Free Software Foundation, Inc.
NOTE: The canonical source of this file is maintained with the GNU C Library.
@@ -80,11 +80,12 @@
#endif
#ifndef _
-/* This is for other GNU distributions with internationalized messages.
- When compiling libc, the _ macro is predefined. */
-# ifdef HAVE_LIBINTL_H
+/* This is for other GNU distributions with internationalized messages. */
+# if defined HAVE_LIBINTL_H || defined _LIBC
# include <libintl.h>
-# define _(msgid) gettext (msgid)
+# ifndef _
+# define _(msgid) gettext (msgid)
+# endif
# else
# define _(msgid) (msgid)
# endif
@@ -520,6 +521,13 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
int *longind;
int long_only;
{
+ int print_errors = opterr;
+ if (optstring[0] == ':')
+ print_errors = 0;
+
+ if (argc < 1)
+ return -1;
+
optarg = NULL;
if (optind == 0 || !__getopt_initialized)
@@ -669,14 +677,17 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
pfound = p;
indfound = option_index;
}
- else
+ else if (long_only
+ || pfound->has_arg != p->has_arg
+ || pfound->flag != p->flag
+ || pfound->val != p->val)
/* Second or later nonexact match found. */
ambig = 1;
}
if (ambig && !exact)
{
- if (opterr)
+ if (print_errors)
fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
argv[0], argv[optind]);
nextchar += strlen (nextchar);
@@ -697,17 +708,19 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
optarg = nameend + 1;
else
{
- if (opterr)
- if (argv[optind - 1][1] == '-')
- /* --option */
- fprintf (stderr,
- _("%s: option `--%s' doesn't allow an argument\n"),
- argv[0], pfound->name);
- else
- /* +option or -option */
- fprintf (stderr,
- _("%s: option `%c%s' doesn't allow an argument\n"),
- argv[0], argv[optind - 1][0], pfound->name);
+ if (print_errors)
+ {
+ if (argv[optind - 1][1] == '-')
+ /* --option */
+ fprintf (stderr,
+ _("%s: option `--%s' doesn't allow an argument\n"),
+ argv[0], pfound->name);
+ else
+ /* +option or -option */
+ fprintf (stderr,
+ _("%s: option `%c%s' doesn't allow an argument\n"),
+ argv[0], argv[optind - 1][0], pfound->name);
+ }
nextchar += strlen (nextchar);
@@ -721,7 +734,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
optarg = argv[optind++];
else
{
- if (opterr)
+ if (print_errors)
fprintf (stderr,
_("%s: option `%s' requires an argument\n"),
argv[0], argv[optind - 1]);
@@ -748,7 +761,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
if (!long_only || argv[optind][1] == '-'
|| my_index (optstring, *nextchar) == NULL)
{
- if (opterr)
+ if (print_errors)
{
if (argv[optind][1] == '-')
/* --option */
@@ -778,7 +791,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
if (temp == NULL || c == ':')
{
- if (opterr)
+ if (print_errors)
{
if (posixly_correct)
/* 1003.2 specifies the format of this message. */
@@ -812,7 +825,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
}
else if (optind == argc)
{
- if (opterr)
+ if (print_errors)
{
/* 1003.2 specifies the format of this message. */
fprintf (stderr, _("%s: option requires an argument -- %c\n"),
@@ -861,7 +874,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
}
if (ambig && !exact)
{
- if (opterr)
+ if (print_errors)
fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
argv[0], argv[optind]);
nextchar += strlen (nextchar);
@@ -879,7 +892,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
optarg = nameend + 1;
else
{
- if (opterr)
+ if (print_errors)
fprintf (stderr, _("\
%s: option `-W %s' doesn't allow an argument\n"),
argv[0], pfound->name);
@@ -894,7 +907,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
optarg = argv[optind++];
else
{
- if (opterr)
+ if (print_errors)
fprintf (stderr,
_("%s: option `%s' requires an argument\n"),
argv[0], argv[optind - 1]);
@@ -941,12 +954,12 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
}
else if (optind == argc)
{
- if (opterr)
+ if (print_errors)
{
/* 1003.2 specifies the format of this message. */
fprintf (stderr,
- _("%s: option requires an argument -- %c\n"),
- argv[0], c);
+ _("%s: option requires an argument -- %c\n"),
+ argv[0], c);
}
optopt = c;
if (optstring[0] == ':')
diff --git a/lib/getopt.h b/lib/getopt.h
index c4adc30..542e2d9 100644
--- a/lib/getopt.h
+++ b/lib/getopt.h
@@ -1,5 +1,5 @@
/* Declarations for getopt.
- Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc.
+ Copyright (C) 1989,90,91,92,93,94,96,97,98,99 Free Software Foundation, Inc.
NOTE: The canonical source of this file is maintained with the GNU C Library.
Bugs can be reported to bug-glibc@prep.ai.mit.edu.
@@ -20,7 +20,21 @@
USA. */
#ifndef _GETOPT_H
-#define _GETOPT_H 1
+
+#ifndef __need_getopt
+# define _GETOPT_H 1
+#endif
+
+/* If __GNU_LIBRARY__ is not already defined, either we are being used
+ standalone, or this is the first header included in the source file.
+ If we are being used with glibc, we need to include <features.h>, but
+ that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
+ not defined, include <ctype.h>, which will pull in <features.h> for us
+ if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
+ doesn't flood the namespace with stuff the way some other headers do.) */
+#if !defined __GNU_LIBRARY__
+# include <ctype.h>
+#endif
#ifdef __cplusplus
extern "C" {
@@ -57,6 +71,7 @@ extern int opterr;
extern int optopt;
+#ifndef __need_getopt
/* Describe the long-named options requested by the application.
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
of `struct option' terminated by an element containing a name which is
@@ -80,11 +95,11 @@ extern int optopt;
struct option
{
-#if defined (__STDC__) && __STDC__
+# if defined __STDC__ && __STDC__
const char *name;
-#else
+# else
char *name;
-#endif
+# endif
/* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */
int has_arg;
@@ -94,40 +109,74 @@ struct option
/* Names for the values of the `has_arg' field of `struct option'. */
-#define no_argument 0
-#define required_argument 1
-#define optional_argument 2
+# define no_argument 0
+# define required_argument 1
+# define optional_argument 2
+#endif /* need getopt */
+
+
+/* Get definitions and prototypes for functions to process the
+ arguments in ARGV (ARGC of them, minus the program name) for
+ options given in OPTS.
-#if defined (__STDC__) && __STDC__
-#ifdef __GNU_LIBRARY__
+ Return the option character from OPTS just read. Return -1 when
+ there are no more options. For unrecognized options, or options
+ missing arguments, `optopt' is set to the option letter, and '?' is
+ returned.
+
+ The OPTS string is a list of characters which are recognized option
+ letters, optionally followed by colons, specifying that that letter
+ takes an argument, to be placed in `optarg'.
+
+ If a letter in OPTS is followed by two colons, its argument is
+ optional. This behavior is specific to the GNU `getopt'.
+
+ The argument `--' causes premature termination of argument
+ scanning, explicitly telling `getopt' that there are no more
+ options.
+
+ If OPTS begins with `--', then non-option arguments are treated as
+ arguments to the option '\0'. This behavior is specific to the GNU
+ `getopt'. */
+
+#if defined __STDC__ && __STDC__
+# ifdef __GNU_LIBRARY__
/* Many other libraries have conflicting prototypes for getopt, with
differences in the consts, in stdlib.h. To avoid compilation
errors, only prototype getopt for the GNU C library. */
-extern int getopt (int argc, char *const *argv, const char *shortopts);
-#else /* not __GNU_LIBRARY__ */
+extern int getopt (int __argc, char *const *__argv, const char *__shortopts);
+# else /* not __GNU_LIBRARY__ */
extern int getopt ();
-#endif /* __GNU_LIBRARY__ */
-extern int getopt_long (int argc, char *const *argv, const char *shortopts,
- const struct option *longopts, int *longind);
-extern int getopt_long_only (int argc, char *const *argv,
- const char *shortopts,
- const struct option *longopts, int *longind);
+# endif /* __GNU_LIBRARY__ */
+
+# ifndef __need_getopt
+extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts,
+ const struct option *__longopts, int *__longind);
+extern int getopt_long_only (int __argc, char *const *__argv,
+ const char *__shortopts,
+ const struct option *__longopts, int *__longind);
/* Internal only. Users should not call this directly. */
-extern int _getopt_internal (int argc, char *const *argv,
- const char *shortopts,
- const struct option *longopts, int *longind,
- int long_only);
+extern int _getopt_internal (int __argc, char *const *__argv,
+ const char *__shortopts,
+ const struct option *__longopts, int *__longind,
+ int __long_only);
+# endif
#else /* not __STDC__ */
extern int getopt ();
+# ifndef __need_getopt
extern int getopt_long ();
extern int getopt_long_only ();
extern int _getopt_internal ();
+# endif
#endif /* __STDC__ */
#ifdef __cplusplus
}
#endif
+/* Make sure we later can get all the definitions and declarations. */
+#undef __need_getopt
+
#endif /* getopt.h */
diff --git a/lib/hash.c b/lib/hash.c
index dcf223c..d848d6e 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -1,5 +1,5 @@
/* hash - implement simple hashing table with string based keys.
- Copyright (C) 1994, 1995 Free Software Foundation, Inc.
+ Copyright (C) 1994, 1995, 2000 Free Software Foundation, Inc.
Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, October 1994.
This program is free software; you can redistribute it and/or modify
@@ -64,33 +64,38 @@
# define bcopy(S, D, N) memcpy ((D), (S), (N))
#endif
-void *xmalloc PARAMS ((size_t __n));
+extern void *xmalloc PARAMS ((size_t __n));
+extern void *xcalloc PARAMS ((size_t __n, size_t __m));
typedef struct hash_entry
{
unsigned long used;
- const char *key;
+ const void *key;
+ size_t keylen;
void *data;
struct hash_entry *next;
}
hash_entry;
/* Prototypes for local functions. */
-static void insert_entry_2 PARAMS ((hash_table *htab, const char *key,
- unsigned long hval, size_t idx,
+static void insert_entry_2 PARAMS ((hash_table *htab,
+ const void *key, size_t keylen,
+ unsigned long int hval, size_t idx,
void *data));
-static size_t lookup PARAMS ((hash_table *htab, const char *key, size_t keylen,
- unsigned long hval));
-static size_t lookup_2 PARAMS ((hash_table *htab, const char *key,
- unsigned long hval));
-static unsigned long compute_hashval PARAMS ((const char *key, size_t keylen));
-static int is_prime PARAMS ((unsigned long candidate));
+static size_t lookup PARAMS ((hash_table *htab,
+ const void *key, size_t keylen,
+ unsigned long int hval));
+static size_t lookup_2 PARAMS ((hash_table *htab,
+ const void *key, size_t keylen,
+ unsigned long int hval));
+static unsigned long compute_hashval PARAMS ((const void *key, size_t keylen));
+static int is_prime PARAMS ((unsigned long int candidate));
int
init_hash (htab, init_size)
hash_table *htab;
- unsigned long init_size;
+ unsigned long int init_size;
{
/* We need the size to be a prime. */
init_size = next_prime (init_size);
@@ -99,11 +104,10 @@ init_hash (htab, init_size)
htab->size = init_size;
htab->filled = 0;
htab->first = NULL;
- htab->table = (void *) xmalloc ((init_size + 1) * sizeof (hash_entry));
+ htab->table = (void *) xcalloc (init_size + 1, sizeof (hash_entry));
if (htab->table == NULL)
return -1;
- memset (htab->table, '\0', (init_size + 1) * sizeof (hash_entry));
obstack_init (&htab->mem_pool);
return 0;
@@ -123,11 +127,11 @@ delete_hash (htab)
int
insert_entry (htab, key, keylen, data)
hash_table *htab;
- const char *key;
+ const void *key;
size_t keylen;
void *data;
{
- unsigned long hval = compute_hashval (key, keylen);
+ unsigned long int hval = compute_hashval (key, keylen);
hash_entry *table = (hash_entry *) htab->table;
size_t idx = lookup (htab, key, keylen, hval);
@@ -138,16 +142,17 @@ insert_entry (htab, key, keylen, data)
{
/* An empty bucket has been found. */
insert_entry_2 (htab, obstack_copy0 (&htab->mem_pool, key, keylen),
- hval, idx, data);
+ keylen, hval, idx, data);
return 0;
}
}
static void
-insert_entry_2 (htab, key, hval, idx, data)
+insert_entry_2 (htab, key, keylen, hval, idx, data)
hash_table *htab;
- const char *key;
- unsigned long hval;
+ const void *key;
+ size_t keylen;
+ unsigned long int hval;
size_t idx;
void *data;
{
@@ -155,6 +160,7 @@ insert_entry_2 (htab, key, hval, idx, data)
table[idx].used = hval;
table[idx].key = key;
+ table[idx].keylen = keylen;
table[idx].data = data;
/* List the new value in the list. */
@@ -174,19 +180,19 @@ insert_entry_2 (htab, key, hval, idx, data)
if (100 * htab->filled > 90 * htab->size)
{
/* Table is filled more than 90%. Resize the table. */
- unsigned long old_size = htab->size;
+ unsigned long int old_size = htab->size;
htab->size = next_prime (htab->size * 2);
htab->filled = 0;
htab->first = NULL;
- htab->table = (void *) xmalloc ((1 + htab->size)
- * sizeof (hash_entry));
- memset (htab->table, '\0', (1 + htab->size) * sizeof (hash_entry));
+ htab->table = (void *) xcalloc (1 + htab->size, sizeof (hash_entry));
for (idx = 1; idx <= old_size; ++idx)
if (table[idx].used)
- insert_entry_2 (htab, table[idx].key, table[idx].used,
- lookup_2 (htab, table[idx].key, table[idx].used),
+ insert_entry_2 (htab, table[idx].key, table[idx].keylen,
+ table[idx].used,
+ lookup_2 (htab, table[idx].key, table[idx].keylen,
+ table[idx].used),
table[idx].data);
free (table);
@@ -197,7 +203,7 @@ insert_entry_2 (htab, key, hval, idx, data)
int
find_entry (htab, key, keylen, result)
hash_table *htab;
- const char *key;
+ const void *key;
size_t keylen;
void **result;
{
@@ -213,10 +219,11 @@ find_entry (htab, key, keylen, result)
int
-iterate_table (htab, ptr, key, data)
+iterate_table (htab, ptr, key, keylen, data)
hash_table *htab;
void **ptr;
const void **key;
+ size_t *keylen;
void **data;
{
if (*ptr == NULL)
@@ -233,6 +240,7 @@ iterate_table (htab, ptr, key, data)
}
*key = ((hash_entry *) *ptr)->key;
+ *keylen = ((hash_entry *) *ptr)->keylen;
*data = ((hash_entry *) *ptr)->data;
return 0;
}
@@ -241,7 +249,7 @@ iterate_table (htab, ptr, key, data)
static size_t
lookup (htab, key, keylen, hval)
hash_table *htab;
- const char *key;
+ const void *key;
size_t keylen;
unsigned long hval;
{
@@ -256,8 +264,8 @@ lookup (htab, key, keylen, hval)
if (table[idx].used)
{
- if (table[idx].used == hval && table[idx].key[keylen] == '\0'
- && strncmp (key, table[idx].key, keylen) == 0)
+ if (table[idx].used == hval && table[idx].keylen == keylen
+ && memcmp (key, table[idx].key, keylen) == 0)
return idx;
/* Second hash function as suggested in [Knuth]. */
@@ -271,8 +279,8 @@ lookup (htab, key, keylen, hval)
idx -= hash;
/* If entry is found use it. */
- if (table[idx].used == hval && table[idx].key[keylen] == '\0'
- && strncmp (key, table[idx].key, keylen) == 0)
+ if (table[idx].used == hval && table[idx].keylen == keylen
+ && memcmp (key, table[idx].key, keylen) == 0)
return idx;
}
while (table[idx].used);
@@ -286,12 +294,13 @@ lookup (htab, key, keylen, hval)
[Knuth] The Art of Computer Programming, part3 (6.4) */
static size_t
-lookup_2 (htab, key, hval)
+lookup_2 (htab, key, keylen, hval)
hash_table *htab;
- const char *key;
- unsigned long hval;
+ const void *key;
+ size_t keylen;
+ unsigned long int hval;
{
- unsigned long hash;
+ unsigned long int hash;
size_t idx;
hash_entry *table = (hash_entry *) htab->table;
@@ -302,7 +311,8 @@ lookup_2 (htab, key, hval)
if (table[idx].used)
{
- if (table[idx].used == hval && strcmp (key, table[idx].key) == 0)
+ if (table[idx].used == hval && table[idx].keylen == keylen
+ && memcmp (table[idx].key, key, keylen) == 0)
return idx;
/* Second hash function as suggested in [Knuth]. */
@@ -316,7 +326,8 @@ lookup_2 (htab, key, hval)
idx -= hash;
/* If entry is found use it. */
- if (table[idx].used == hval && strcmp (key, table[idx].key) == 0)
+ if (table[idx].used == hval && table[idx].keylen == keylen
+ && memcmp (table[idx].key, key, keylen) == 0)
return idx;
}
while (table[idx].used);
@@ -327,11 +338,11 @@ lookup_2 (htab, key, hval)
static unsigned long
compute_hashval (key, keylen)
- const char *key;
+ const void *key;
size_t keylen;
{
size_t cnt;
- unsigned long hval, g;
+ unsigned long int hval, g;
/* Compute the hash value for the given string. The algorithm
is taken from [Aho,Sethi,Ullman]. */
@@ -340,7 +351,7 @@ compute_hashval (key, keylen)
while (cnt < keylen)
{
hval <<= 4;
- hval += key[cnt++];
+ hval += ((char *) key)[cnt++];
g = hval & ((unsigned long) 0xf << (LONGBITS - 4));
if (g != 0)
{
@@ -354,7 +365,7 @@ compute_hashval (key, keylen)
unsigned long
next_prime (seed)
- unsigned long seed;
+ unsigned long int seed;
{
/* Make it definitely odd. */
seed |= 1;
@@ -368,11 +379,11 @@ next_prime (seed)
static int
is_prime (candidate)
- unsigned long candidate;
+ unsigned long int candidate;
{
/* No even number and none less than 10 will be passed here. */
- unsigned long divn = 3;
- unsigned long sq = divn * divn;
+ unsigned long int divn = 3;
+ unsigned long int sq = divn * divn;
while (sq < candidate && candidate % divn != 0)
{
diff --git a/lib/hash.h b/lib/hash.h
index 238d6ca..c6ce3e0 100644
--- a/lib/hash.h
+++ b/lib/hash.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995 Free Software Foundation, Inc.
+/* Copyright (C) 1995, 2000 Free Software Foundation, Inc.
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
@@ -22,8 +22,8 @@
typedef struct hash_table
{
- unsigned long size;
- unsigned long filled;
+ unsigned long int size;
+ unsigned long int filled;
void *first;
void *table;
struct obstack mem_pool;
@@ -38,16 +38,19 @@ hash_table;
# endif
# endif
-int init_hash PARAMS ((hash_table *htab, unsigned long init_size));
-int delete_hash PARAMS ((hash_table *htab));
-int insert_entry PARAMS ((hash_table *htab, const char *key, size_t keylen,
- void *data));
-int find_entry PARAMS ((hash_table *htab, const char *key, size_t keylen,
- void **result));
+extern int init_hash PARAMS ((hash_table *htab, unsigned long int init_size));
+extern int delete_hash PARAMS ((hash_table *htab));
+extern int insert_entry PARAMS ((hash_table *htab,
+ const void *key, size_t keylen,
+ void *data));
+extern int find_entry PARAMS ((hash_table *htab,
+ const void *key, size_t keylen,
+ void **result));
-int iterate_table PARAMS ((hash_table *htab, void **ptr,
- const void **key, void **data));
+extern int iterate_table PARAMS ((hash_table *htab, void **ptr,
+ const void **key, size_t *keylen,
+ void **data));
-unsigned long next_prime PARAMS ((unsigned long seed));
+extern unsigned long int next_prime PARAMS ((unsigned long int seed));
#endif /* not _HASH_H */
diff --git a/lib/memmove.c b/lib/memmove.c
index 4115aa3..ea38e8d 100644
--- a/lib/memmove.c
+++ b/lib/memmove.c
@@ -1,108 +1,28 @@
-/* Copy memory to memory until the specified number of bytes
- has been copied. Overlap is handled correctly.
- Copyright (C) 1991, 1995, 1996, 1997 Free Software Foundation, Inc.
- Contributed by Torbjorn Granlund (tege@sics.se).
+/* memmove.c -- copy memory.
+ Copy LENGTH bytes from SOURCE to DEST. Does not null-terminate.
+ In the public domain.
+ By David MacKenzie <djm@gnu.ai.mit.edu>. */
- 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. */
-
-#include <string.h>
-#include <memcopy.h>
-#include <pagecopy.h>
-
-/* All this is so that bcopy.c can #include
- this file after defining some things. */
-#ifndef a1
-#define a1 dest /* First arg is DEST. */
-#define a1const
-#define a2 src /* Second arg is SRC. */
-#define a2const const
-#undef memmove
-#endif
-#if !defined(RETURN) || !defined(rettype)
-#define RETURN(s) return (s) /* Return DEST. */
-#define rettype void *
+#if HAVE_CONFIG_H
+# include <config.h>
#endif
-
-rettype
-memmove (a1, a2, len)
- a1const void *a1;
- a2const void *a2;
- size_t len;
+void *
+memmove (dest, source, length)
+ char *dest;
+ const char *source;
+ unsigned length;
{
- unsigned long int dstp = (long int) dest;
- unsigned long int srcp = (long int) src;
-
- /* This test makes the forward copying code be used whenever possible.
- Reduces the working set. */
- if (dstp - srcp >= len) /* *Unsigned* compare! */
- {
- /* Copy from the beginning to the end. */
-
- /* If there not too few bytes to copy, use word copy. */
- if (len >= OP_T_THRES)
- {
- /* Copy just a few bytes to make DSTP aligned. */
- len -= (-dstp) % OPSIZ;
- BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ);
-
- /* Copy whole pages from SRCP to DSTP by virtual address
- manipulation, as much as possible. */
-
- PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len);
-
- /* Copy from SRCP to DSTP taking advantage of the known
- alignment of DSTP. Number of bytes remaining is put
- in the third argument, i.e. in LEN. This number may
- vary from machine to machine. */
-
- WORD_COPY_FWD (dstp, srcp, len, len);
-
- /* Fall out and copy the tail. */
- }
-
- /* There are just a few bytes to copy. Use byte memory operations. */
- BYTE_COPY_FWD (dstp, srcp, len);
- }
- else
+ char *d0 = dest;
+ if (source < dest)
+ /* Moving from low mem to hi mem; start at end. */
+ for (source += length, dest += length; length; --length)
+ *--dest = *--source;
+ else if (source != dest)
{
- /* Copy from the end to the beginning. */
- srcp += len;
- dstp += len;
-
- /* If there not too few bytes to copy, use word copy. */
- if (len >= OP_T_THRES)
- {
- /* Copy just a few bytes to make DSTP aligned. */
- len -= dstp % OPSIZ;
- BYTE_COPY_BWD (dstp, srcp, dstp % OPSIZ);
-
- /* Copy from SRCP to DSTP taking advantage of the known
- alignment of DSTP. Number of bytes remaining is put
- in the third argument, i.e. in LEN. This number may
- vary from machine to machine. */
-
- WORD_COPY_BWD (dstp, srcp, len, len);
-
- /* Fall out and copy the tail. */
- }
-
- /* There are just a few bytes to copy. Use byte memory operations. */
- BYTE_COPY_BWD (dstp, srcp, len);
+ /* Moving from hi mem to low mem; start at beginning. */
+ for (; length; --length)
+ *dest++ = *source++;
}
-
- RETURN (dest);
+ return (void *) d0;
}
diff --git a/lib/memset.c b/lib/memset.c
index 239dc21..a0db560 100644
--- a/lib/memset.c
+++ b/lib/memset.c
@@ -1,90 +1,29 @@
-/* Copyright (C) 1991, 1997 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
+/* memset.c -- set an area of memory to a given value
+ Copyright (C) 1991 Free Software Foundation, Inc.
- 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.
+ 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.
- The GNU C Library is distributed in the hope that it will be useful,
+ 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
- Library General Public License for more details.
+ 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 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. */
+ 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. */
-#include <string.h>
-#include <memcopy.h>
-
-#undef memset
-
-void *
-memset (dstpp, c, len)
- void *dstpp;
+char *
+memset (str, c, len)
+ char *str;
int c;
- size_t len;
+ unsigned len;
{
- long int dstp = (long int) dstpp;
-
- if (len >= 8)
- {
- size_t xlen;
- op_t cccc;
-
- cccc = (unsigned char) c;
- cccc |= cccc << 8;
- cccc |= cccc << 16;
- if (OPSIZ > 4)
- /* Do the shift in two steps to avoid warning if long has 32 bits. */
- cccc |= (cccc << 16) << 16;
-
- /* There are at least some bytes to set.
- No need to test for LEN == 0 in this alignment loop. */
- while (dstp % OPSIZ != 0)
- {
- ((byte *) dstp)[0] = c;
- dstp += 1;
- len -= 1;
- }
-
- /* Write 8 `op_t' per iteration until less than 8 `op_t' remain. */
- xlen = len / (OPSIZ * 8);
- while (xlen > 0)
- {
- ((op_t *) dstp)[0] = cccc;
- ((op_t *) dstp)[1] = cccc;
- ((op_t *) dstp)[2] = cccc;
- ((op_t *) dstp)[3] = cccc;
- ((op_t *) dstp)[4] = cccc;
- ((op_t *) dstp)[5] = cccc;
- ((op_t *) dstp)[6] = cccc;
- ((op_t *) dstp)[7] = cccc;
- dstp += 8 * OPSIZ;
- xlen -= 1;
- }
- len %= OPSIZ * 8;
-
- /* Write 1 `op_t' per iteration until less than OPSIZ bytes remain. */
- xlen = len / OPSIZ;
- while (xlen > 0)
- {
- ((op_t *) dstp)[0] = cccc;
- dstp += OPSIZ;
- xlen -= 1;
- }
- len %= OPSIZ;
- }
-
- /* Write the last few bytes. */
- while (len > 0)
- {
- ((byte *) dstp)[0] = c;
- dstp += 1;
- len -= 1;
- }
+ register char *st = str;
- return dstpp;
+ while (len-- > 0)
+ *st++ = c;
+ return str;
}
diff --git a/lib/obstack.c b/lib/obstack.c
index e5b5d4f..68303b3 100644
--- a/lib/obstack.c
+++ b/lib/obstack.c
@@ -79,7 +79,9 @@ union fooround {long x; double d;};
/* The functions allocating more room by calling `obstack_chunk_alloc'
jump to the handler pointed to by `obstack_alloc_failed_handler'.
- This variable by default points to the internal function
+ This can be set to a user defined function which should either
+ abort gracefully or use longjump - but shouldn't return. This
+ variable by default points to the internal function
`print_and_abort'. */
#if defined (__STDC__) && __STDC__
static void print_and_abort (void);
@@ -143,9 +145,8 @@ struct obstack *_obstack;
CHUNKFUN is the function to use to allocate chunks,
and FREEFUN the function to free them.
- Return nonzero if successful, zero if out of memory.
- To recover from an out of memory error,
- free up some memory, then call this again. */
+ Return nonzero if successful, calls obstack_alloc_failed_handler if
+ allocation fails. */
int
_obstack_begin (h, size, alignment, chunkfun, freefun)
@@ -282,9 +283,10 @@ _obstack_newchunk (h, length)
register long obj_size = h->next_free - h->object_base;
register long i;
long already;
+ char *object_base;
/* Compute size for new chunk. */
- new_size = (obj_size + length) + (obj_size >> 3) + 100;
+ new_size = (obj_size + length) + (obj_size >> 3) + h->alignment_mask + 100;
if (new_size < h->chunk_size)
new_size = h->chunk_size;
@@ -296,6 +298,11 @@ _obstack_newchunk (h, length)
new_chunk->prev = old_chunk;
new_chunk->limit = h->chunk_limit = (char *) new_chunk + new_size;
+ /* Compute an aligned object_base in the new chunk */
+ object_base =
+ __INT_TO_PTR ((__PTR_TO_INT (new_chunk->contents) + h->alignment_mask)
+ & ~ (h->alignment_mask));
+
/* Move the existing object to the new chunk.
Word at a time is fast and is safe if the object
is sufficiently aligned. */
@@ -303,7 +310,7 @@ _obstack_newchunk (h, length)
{
for (i = obj_size / sizeof (COPYING_UNIT) - 1;
i >= 0; i--)
- ((COPYING_UNIT *)new_chunk->contents)[i]
+ ((COPYING_UNIT *)object_base)[i]
= ((COPYING_UNIT *)h->object_base)[i];
/* We used to copy the odd few remaining bytes as one extra COPYING_UNIT,
but that can cross a page boundary on a machine
@@ -314,7 +321,7 @@ _obstack_newchunk (h, length)
already = 0;
/* Copy remaining bytes one by one. */
for (i = already; i < obj_size; i++)
- new_chunk->contents[i] = h->object_base[i];
+ object_base[i] = h->object_base[i];
/* If the object just copied was the only data in OLD_CHUNK,
free that chunk and remove it from the chain.
@@ -325,7 +332,7 @@ _obstack_newchunk (h, length)
CALL_FREEFUN (h, old_chunk);
}
- h->object_base = new_chunk->contents;
+ h->object_base = object_base;
h->next_free = h->object_base + obj_size;
/* The new chunk certainly contains no empty object yet. */
h->maybe_empty_object = 0;
@@ -451,7 +458,7 @@ _obstack_memory_used (h)
/* Define the error handler. */
#ifndef _
-# ifdef HAVE_LIBINTL_H
+# if defined HAVE_LIBINTL_H || defined _LIBC
# include <libintl.h>
# ifndef _
# define _(Str) gettext (Str)
@@ -464,7 +471,8 @@ _obstack_memory_used (h)
static void
print_and_abort ()
{
- fputs (_("memory exhausted\n"), stderr);
+ fputs (_("memory exhausted"), stderr);
+ fputc ('\n', stderr);
exit (obstack_exit_failure);
}
diff --git a/lib/obstack.h b/lib/obstack.h
index 144998c..ca5658b 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,96,97,98 Free Software Foundation, Inc.
+ Copyright (C) 1988-1999, 2000 Free Software Foundation, Inc.
NOTE: The canonical source of this file is maintained with the GNU C Library.
@@ -218,18 +218,18 @@ void obstack_init (struct obstack *obstack);
void * obstack_alloc (struct obstack *obstack, int size);
-void * obstack_copy (struct obstack *obstack, void *address, int size);
-void * obstack_copy0 (struct obstack *obstack, void *address, int size);
+void * obstack_copy (struct obstack *obstack, const void *address, int size);
+void * obstack_copy0 (struct obstack *obstack, const void *address, int size);
void obstack_free (struct obstack *obstack, void *block);
void obstack_blank (struct obstack *obstack, int size);
-void obstack_grow (struct obstack *obstack, void *data, int size);
-void obstack_grow0 (struct obstack *obstack, void *data, int size);
+void obstack_grow (struct obstack *obstack, const void *data, int size);
+void obstack_grow0 (struct obstack *obstack, const void *data, int size);
void obstack_1grow (struct obstack *obstack, int data_char);
-void obstack_ptr_grow (struct obstack *obstack, void *data);
+void obstack_ptr_grow (struct obstack *obstack, const void *data);
void obstack_int_grow (struct obstack *obstack, int data);
void * obstack_finish (struct obstack *obstack);
@@ -239,7 +239,7 @@ int obstack_object_size (struct obstack *obstack);
int obstack_room (struct obstack *obstack);
void obstack_make_room (struct obstack *obstack, int size);
void obstack_1grow_fast (struct obstack *obstack, int data_char);
-void obstack_ptr_grow_fast (struct obstack *obstack, void *data);
+void obstack_ptr_grow_fast (struct obstack *obstack, const void *data);
void obstack_int_grow_fast (struct obstack *obstack, int data);
void obstack_blank_fast (struct obstack *obstack, int size);
@@ -255,8 +255,9 @@ int obstack_memory_used (struct obstack *obstack);
so we do not declare them. */
/* Error handler called when `obstack_chunk_alloc' failed to allocate
- more memory. This can be set to a user defined function. The
- default action is to print a message and abort. */
+ more memory. This can be set to a user defined function which
+ should either abort gracefully or use longjump - but shouldn't
+ return. The default action is to print a message and abort. */
#if defined __STDC__ && __STDC__
extern void (*obstack_alloc_failed_handler) (void);
#else
@@ -385,7 +386,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, (const char *) (where), __len); \
__o->next_free += __len; \
(void) 0; })
@@ -395,7 +396,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, (const char *) (where), __len); \
__o->next_free += __len; \
*(__o->next_free)++ = 0; \
(void) 0; })
@@ -417,7 +418,7 @@ __extension__ \
({ struct obstack *__o = (OBSTACK); \
if (__o->next_free + sizeof (void *) > __o->chunk_limit) \
_obstack_newchunk (__o, sizeof (void *)); \
- *((void **)__o->next_free)++ = ((void *)datum); \
+ *((void **)__o->next_free)++ = ((const void *)datum); \
(void) 0; })
# define obstack_int_grow(OBSTACK,datum) \
@@ -481,7 +482,7 @@ __extension__ \
({ struct obstack *__o = (OBSTACK); \
void *__obj = (OBJ); \
if (__obj > (void *)__o->chunk && __obj < (void *)__o->chunk_limit) \
- __o->next_free = __o->object_base = __obj; \
+ __o->next_free = __o->object_base = (char *)__obj; \
else (obstack_free) (__o, __obj); })
#else /* not __GNUC__ or not __STDC__ */
diff --git a/lib/pathmax.h b/lib/pathmax.h
index 74f5792..19d4304 100644
--- a/lib/pathmax.h
+++ b/lib/pathmax.h
@@ -1,5 +1,5 @@
/* Define PATH_MAX somehow. Requires sys/types.h.
- Copyright (C) 1992 Free Software Foundation, Inc.
+ Copyright (C) 1992, 1999 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
@@ -16,38 +16,39 @@
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifndef _PATHMAX_H
-#define _PATHMAX_H
+# define _PATHMAX_H
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
+# ifdef HAVE_UNISTD_H
+# include <unistd.h>
+# endif
/* Non-POSIX BSD systems might have gcc's limits.h, which doesn't define
PATH_MAX but might cause redefinition warnings when sys/param.h is
later included (as on MORE/BSD 4.3). */
-#if defined(_POSIX_VERSION) || (defined(HAVE_LIMITS_H) && !defined(__GNUC__))
-#include <limits.h>
-#endif
+# if defined(_POSIX_VERSION) || (defined(HAVE_LIMITS_H) && !defined(__GNUC__))
+# include <limits.h>
+# endif
-#ifndef _POSIX_PATH_MAX
-#define _POSIX_PATH_MAX 255
-#endif
+# ifndef _POSIX_PATH_MAX
+# define _POSIX_PATH_MAX 255
+# endif
-#if !defined(PATH_MAX) && defined(_PC_PATH_MAX)
-#define PATH_MAX (pathconf ("/", _PC_PATH_MAX) < 1 ? 1024 : pathconf ("/", _PC_PATH_MAX))
-#endif
+# if !defined(PATH_MAX) && defined(_PC_PATH_MAX)
+# define PATH_MAX (pathconf ("/", _PC_PATH_MAX) < 1 ? 1024 \
+ : pathconf ("/", _PC_PATH_MAX))
+# endif
/* Don't include sys/param.h if it already has been. */
-#if defined(HAVE_SYS_PARAM_H) && !defined(PATH_MAX) && !defined(MAXPATHLEN)
-#include <sys/param.h>
-#endif
+# if defined(HAVE_SYS_PARAM_H) && !defined(PATH_MAX) && !defined(MAXPATHLEN)
+# include <sys/param.h>
+# endif
-#if !defined(PATH_MAX) && defined(MAXPATHLEN)
-#define PATH_MAX MAXPATHLEN
-#endif
+# if !defined(PATH_MAX) && defined(MAXPATHLEN)
+# define PATH_MAX MAXPATHLEN
+# endif
-#ifndef PATH_MAX
-#define PATH_MAX _POSIX_PATH_MAX
-#endif
+# ifndef PATH_MAX
+# define PATH_MAX _POSIX_PATH_MAX
+# endif
#endif /* _PATHMAX_H */
diff --git a/lib/printf-parse.h b/lib/printf-parse.h
index d8ab2b7..1225824 100644
--- a/lib/printf-parse.h
+++ b/lib/printf-parse.h
@@ -20,11 +20,11 @@
#include <ctype.h>
#include <printf.h>
-#if STDC_HEADERS
+#if HAVE_STDDEF_H
# include <stddef.h>
#endif
-#if STDC_HEADERS || HAVE_STRING_H
+#if HAVE_STRING_H
# include <string.h>
#else
# include <strings.h>
@@ -38,10 +38,6 @@
# define long_double double
#endif
-#ifndef MB_CUR_MAX
-# define MB_CUR_MAX (sizeof (long))
-#endif
-
#define NDEBUG 1
#include <assert.h>
@@ -137,18 +133,7 @@ find_spec (format)
const char *format;
{
while (*format != '\0' && *format != '%')
- {
- int len;
-
-#ifdef HAVE_MBLEN
- if (isascii (*format) || (len = mblen (format, MB_CUR_MAX)) <= 0)
- ++format;
- else
- format += len;
-#else
- ++format;
-#endif
- }
+ ++format;
return format;
}
diff --git a/lib/printf-prs.c b/lib/printf-prs.c
index 19869ca..fad5e0b 100644
--- a/lib/printf-prs.c
+++ b/lib/printf-prs.c
@@ -1,71 +1,27 @@
-/* Copyright (C) 1991, 1992, 1995, 1996, 1999 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
+/* Copyright (C) 1991, 1992, 1995, 1996 Free Software Foundation, Inc.
- 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.
+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.
- 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.
+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 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. */
+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. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
#include <stdio.h>
#include <printf.h>
-#include <stdlib.h>
-#include <string.h>
-#include <wchar.h>
-#include <sys/param.h>
-
-#ifndef COMPILE_WPRINTF
-# define CHAR_T char
-# define UCHAR_T unsigned char
-# define INT_T int
-# define L_(Str) Str
-# define ISDIGIT(Ch) isdigit (Ch)
-# define ISASCII(Ch) isascii (Ch)
-# define MBRLEN(Cp, L, St) mbrlen (Cp, L, St)
-
-# ifdef USE_IN_LIBIO
-# define PUT(F, S, N) _IO_sputn (F, S, N)
-# define PAD(Padchar) \
- if (width > 0) \
- done += _IO_padn (s, Padchar, width)
-# else
-# define PUTC(C, F) putc (C, F)
-ssize_t __printf_pad __P ((FILE *, char pad, size_t n));
-# define PAD(Padchar) \
- if (width > 0) \
- { if (__printf_pad (s, Padchar, width) == -1) \
- return -1; else done += width; }
-# endif
-#else
-# define vfprintf vfwprintf
-# define CHAR_T wchar_t
-# define UCHAR_T uwchar_t
-# define INT_T wint_t
-# define L_(Str) L##Str
-# define ISDIGIT(Ch) iswdigit (Ch)
-
-# ifdef USE_IN_LIBIO
-# define PUT(F, S, N) _IO_sputn (F, S, N)
-# define PAD(Padchar) \
- if (width > 0) \
- done += _IO_wpadn (s, Padchar, width)
-# else
-# define PUTC(C, F) wputc (C, F)
-ssize_t __wprintf_pad __P ((FILE *, wchar_t pad, size_t n));
-# define PAD(Padchar) \
- if (width > 0) \
- { if (__wprintf_pad (s, Padchar, width) == -1) \
- return -1; else done += width; }
-# endif
+#if HAVE_STDLIB_H
+# include <stdlib.h>
#endif
#include "printf-parse.h"
@@ -80,16 +36,15 @@ parse_printf_format (fmt, n, argtypes)
size_t nargs; /* Number of arguments. */
size_t max_ref_arg; /* Highest index used in a positional arg. */
struct printf_spec spec;
- mbstate_t mbstate;
nargs = 0;
max_ref_arg = 0;
/* Search for format specifications. */
- for (fmt = find_spec (fmt, &mbstate); *fmt != '\0'; fmt = spec.next_fmt)
+ for (fmt = find_spec (fmt); *fmt != '\0'; fmt = spec.next_fmt)
{
/* Parse this spec. */
- nargs += parse_one_spec (fmt, nargs, &spec, &max_ref_arg, &mbstate);
+ nargs += parse_one_spec (fmt, nargs, &spec, &max_ref_arg);
/* If the width is determined by an argument this is an int. */
if (spec.width_arg != -1 && (size_t) spec.width_arg < n)
@@ -108,10 +63,16 @@ parse_printf_format (fmt, n, argtypes)
argtypes[spec.data_arg] = spec.data_arg_type;
break;
default:
+ /* We don't handle this here. Beside GNU libc no other
+ libc provides printf function registration. But while
+ having this feature it also provides this function, so
+ that using *this* file is not needed. */
+#if 0
/* We have more than one argument for this format spec. We must
- call the arginfo function again to determine all the types. */
+ call the arginfo function again to determine all the types. */
(void) (*__printf_arginfo_table[spec.info.spec])
(&spec.info, n - spec.data_arg, &argtypes[spec.data_arg]);
+#endif
break;
}
}
diff --git a/lib/printf.h b/lib/printf.h
index 03b0035..22b9623 100644
--- a/lib/printf.h
+++ b/lib/printf.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992, 1993, 1995 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 1993, 1995, 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
@@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include <stdio.h>
#include <sys/types.h>
-#ifdef STDC_HEADERS
+#if HAVE_STDDEF_H
# include <stddef.h>
#endif
diff --git a/lib/strstr.c b/lib/strstr.c
index 03d6c8e..3eb2f22 100644
--- a/lib/strstr.c
+++ b/lib/strstr.c
@@ -1,5 +1,5 @@
/* Return the offset of one string within another.
- Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1994, 1996, 1997, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -82,7 +82,7 @@ strstr (phaystack, pneedle)
a = *++haystack;
if (a == '\0')
goto ret0;
-shloop: }
+shloop:; }
while (a != b);
jin: a = *++haystack;
diff --git a/lib/strtol.c b/lib/strtol.c
index d49f1c6..8f97b25 100644
--- a/lib/strtol.c
+++ b/lib/strtol.c
@@ -1,5 +1,5 @@
/* Convert string representation of a number into an integer value.
- Copyright (C) 1991, 92, 94, 95, 96, 97, 98 Free Software Foundation, Inc.
+ Copyright (C) 1991,92,94,95,96,97,98,99,2000 Free Software Foundation, Inc.
NOTE: The canonical source of this file is maintained with the GNU C Library.
Bugs can be reported to bug-glibc@prep.ai.mit.edu.
@@ -130,27 +130,27 @@ extern int errno;
operating on `long long int's. */
#ifdef QUAD
# define LONG long long
-# undef LONG_MIN
-# define LONG_MIN LONG_LONG_MIN
-# undef LONG_MAX
-# define LONG_MAX LONG_LONG_MAX
-# undef ULONG_MAX
-# define ULONG_MAX ULONG_LONG_MAX
+# define STRTOL_LONG_MIN LONG_LONG_MIN
+# define STRTOL_LONG_MAX LONG_LONG_MAX
+# define STRTOL_ULONG_MAX ULONG_LONG_MAX
# if __GNUC__ == 2 && __GNUC_MINOR__ < 7
/* Work around gcc bug with using this constant. */
static const unsigned long long int maxquad = ULONG_LONG_MAX;
-# undef ULONG_MAX
-# define ULONG_MAX maxquad
+# undef STRTOL_ULONG_MAX
+# define STRTOL_ULONG_MAX maxquad
# endif
#else
# define LONG long
-#ifndef ULONG_MAX
-# define ULONG_MAX ((unsigned long) ~(unsigned long) 0)
-#endif
-#ifndef LONG_MAX
-# define LONG_MAX ((long int) (ULONG_MAX >> 1))
-#endif
+# ifndef ULONG_MAX
+# define ULONG_MAX ((unsigned long) ~(unsigned long) 0)
+# endif
+# ifndef LONG_MAX
+# define LONG_MAX ((long int) (ULONG_MAX >> 1))
+# endif
+# define STRTOL_LONG_MIN LONG_MIN
+# define STRTOL_LONG_MAX LONG_MAX
+# define STRTOL_ULONG_MAX ULONG_MAX
#endif
@@ -245,13 +245,21 @@ INTERNAL (strtol) (nptr, endptr, base, group LOCALE_PARAM)
register UCHAR_TYPE c;
const STRING_TYPE *save, *end;
int overflow;
+#if defined USE_NUMBER_GROUPING && !defined USE_WIDE_CHAR
+ int cnt;
+#endif
#ifdef USE_NUMBER_GROUPING
# ifdef USE_IN_EXTENDED_LOCALE_MODEL
struct locale_data *current = loc->__locales[LC_NUMERIC];
# endif
/* The thousands character of the current locale. */
+# ifdef USE_WIDE_CHAR
wchar_t thousands = L'\0';
+# else
+ const char *thousands = NULL;
+ size_t thousands_len = 0;
+# endif
/* The numeric grouping specification of the current locale,
in the format described in <locale.h>. */
const char *grouping;
@@ -264,13 +272,23 @@ INTERNAL (strtol) (nptr, endptr, base, group LOCALE_PARAM)
else
{
/* Figure out the thousands separator character. */
-# if defined _LIBC || defined _HAVE_BTOWC
- thousands = __btowc (*_NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP));
- if (thousands == WEOF)
- thousands = L'\0';
-# endif
+# ifdef USE_WIDE_CHAR
+# ifdef _LIBC
+ thousands = _NL_CURRENT_WORD (LC_NUMERIC,
+ _NL_NUMERIC_THOUSANDS_SEP_WC);
+# endif
if (thousands == L'\0')
grouping = NULL;
+# else
+# ifdef _LIBC
+ thousands = _NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP);
+# endif
+ if (*thousands == '\0')
+ {
+ thousands = NULL;
+ grouping = NULL;
+ }
+# endif
}
}
else
@@ -308,7 +326,7 @@ INTERNAL (strtol) (nptr, endptr, base, group LOCALE_PARAM)
/* Recognize number prefix and if BASE is zero, figure it out ourselves. */
if (*s == L_('0'))
{
- if (TOUPPER (s[1]) == L_('X'))
+ if ((base == 0 || base == 16) && TOUPPER (s[1]) == L_('X'))
{
s += 2;
base = 16;
@@ -323,50 +341,152 @@ INTERNAL (strtol) (nptr, endptr, base, group LOCALE_PARAM)
save = s;
#ifdef USE_NUMBER_GROUPING
- if (group)
+ if (base != 10)
+ grouping = NULL;
+
+ if (grouping)
{
+# ifndef USE_WIDE_CHAR
+ thousands_len = strlen (thousands);
+# endif
+
/* Find the end of the digit string and check its grouping. */
end = s;
- for (c = *end; c != L_('\0'); c = *++end)
- if ((wchar_t) c != thousands
- && ((wchar_t) c < L_('0') || (wchar_t) c > L_('9'))
- && (!ISALPHA (c) || (int) (TOUPPER (c) - L_('A') + 10) >= base))
- break;
- if (*s == thousands)
- end = s;
- else
- end = correctly_grouped_prefix (s, end, thousands, grouping);
+ if (
+# ifdef USE_WIDE_CHAR
+ *s != thousands
+# else
+ ({ for (cnt = 0; cnt < thousands_len; ++cnt)
+ if (thousands[cnt] != end[cnt])
+ break;
+ cnt < thousands_len; })
+# endif
+ )
+ {
+ for (c = *end; c != L_('\0'); c = *++end)
+ if (((wchar_t) c < L_('0') || (wchar_t) c > L_('9'))
+# ifdef USE_WIDE_CHAR
+ && c != thousands
+# else
+ && ({ for (cnt = 0; cnt < thousands_len; ++cnt)
+ if (thousands[cnt] != end[cnt])
+ break;
+ cnt < thousands_len; })
+# endif
+ && (!ISALPHA (c)
+ || (int) (TOUPPER (c) - L_('A') + 10) >= base))
+ break;
+
+ end = correctly_grouped_prefix (s, end, thousands, grouping);
+ }
}
else
#endif
end = NULL;
- cutoff = ULONG_MAX / (unsigned LONG int) base;
- cutlim = ULONG_MAX % (unsigned LONG int) base;
+ cutoff = STRTOL_ULONG_MAX / (unsigned LONG int) base;
+ cutlim = STRTOL_ULONG_MAX % (unsigned LONG int) base;
overflow = 0;
i = 0;
- for (c = *s; c != L_('\0'); c = *++s)
+ c = *s;
+ if (sizeof (long int) != sizeof (LONG int))
{
- if (s == end)
- break;
- if (c >= L_('0') && c <= L_('9'))
- c -= L_('0');
- else if (ISALPHA (c))
- c = TOUPPER (c) - L_('A') + 10;
- else
- break;
- if ((int) c >= base)
- break;
- /* Check for overflow. */
- if (i > cutoff || (i == cutoff && c > cutlim))
- overflow = 1;
- else
+ unsigned long int j = 0;
+ unsigned long int jmax = ULONG_MAX / base;
+
+ for (;c != L_('\0'); c = *++s)
{
- i *= (unsigned LONG int) base;
- i += c;
+ if (s == end)
+ break;
+ if (c >= L_('0') && c <= L_('9'))
+ c -= L_('0');
+#ifdef USE_NUMBER_GROUPING
+# ifdef USE_WIDE_CHAR
+ else if (grouping && c == thousands)
+ continue;
+# else
+ else if (thousands_len)
+ {
+ for (cnt = 0; cnt < thousands_len; ++cnt)
+ if (thousands[cnt] != s[cnt])
+ break;
+ if (cnt == thousands_len)
+ {
+ s += thousands_len - 1;
+ continue;
+ }
+ if (ISALPHA (c))
+ c = TOUPPER (c) - L_('A') + 10;
+ else
+ break;
+ }
+# endif
+#endif
+ else if (ISALPHA (c))
+ c = TOUPPER (c) - L_('A') + 10;
+ else
+ break;
+ if ((int) c >= base)
+ break;
+ /* Note that we never can have an overflow. */
+ else if (j >= jmax)
+ {
+ /* We have an overflow. Now use the long representation. */
+ i = (unsigned LONG int) j;
+ goto use_long;
+ }
+ else
+ j = j * (unsigned long int) base + c;
}
+
+ i = (unsigned LONG int) j;
}
+ else
+ for (;c != L_('\0'); c = *++s)
+ {
+ if (s == end)
+ break;
+ if (c >= L_('0') && c <= L_('9'))
+ c -= L_('0');
+#ifdef USE_NUMBER_GROUPING
+# ifdef USE_WIDE_CHAR
+ else if (grouping && c == thousands)
+ continue;
+# else
+ else if (thousands_len)
+ {
+ for (cnt = 0; cnt < thousands_len; ++cnt)
+ if (thousands[cnt] != s[cnt])
+ break;
+ if (cnt == thousands_len)
+ {
+ s += thousands_len - 1;
+ continue;
+ }
+ if (ISALPHA (c))
+ c = TOUPPER (c) - L_('A') + 10;
+ else
+ break;
+ }
+# endif
+#endif
+ else if (ISALPHA (c))
+ c = TOUPPER (c) - L_('A') + 10;
+ else
+ break;
+ if ((int) c >= base)
+ break;
+ /* Check for overflow. */
+ if (i > cutoff || (i == cutoff && c > cutlim))
+ overflow = 1;
+ else
+ {
+ use_long:
+ i *= (unsigned LONG int) base;
+ i += c;
+ }
+ }
/* Check if anything actually happened. */
if (s == save)
@@ -382,8 +502,8 @@ INTERNAL (strtol) (nptr, endptr, base, group LOCALE_PARAM)
`unsigned LONG int', but outside the range of `LONG int'. */
if (overflow == 0
&& i > (negative
- ? -((unsigned LONG int) (LONG_MIN + 1)) + 1
- : (unsigned LONG int) LONG_MAX))
+ ? -((unsigned LONG int) (STRTOL_LONG_MIN + 1)) + 1
+ : (unsigned LONG int) STRTOL_LONG_MAX))
overflow = 1;
#endif
@@ -391,9 +511,9 @@ INTERNAL (strtol) (nptr, endptr, base, group LOCALE_PARAM)
{
__set_errno (ERANGE);
#if UNSIGNED
- return ULONG_MAX;
+ return STRTOL_ULONG_MAX;
#else
- return negative ? LONG_MIN : LONG_MAX;
+ return negative ? STRTOL_LONG_MIN : STRTOL_LONG_MAX;
#endif
}
@@ -406,12 +526,14 @@ noconv:
hexadecimal digits. This is no error case. We return 0 and
ENDPTR points to the `x`. */
if (endptr != NULL)
- if (save - nptr >= 2 && TOUPPER (save[-1]) == L_('X')
- && save[-2] == L_('0'))
- *endptr = (STRING_TYPE *) &save[-1];
- else
- /* There was no number to convert. */
- *endptr = (STRING_TYPE *) nptr;
+ {
+ if (save - nptr >= 2 && TOUPPER (save[-1]) == L_('X')
+ && save[-2] == L_('0'))
+ *endptr = (STRING_TYPE *) &save[-1];
+ else
+ /* There was no number to convert. */
+ *endptr = (STRING_TYPE *) nptr;
+ }
return 0L;
}
diff --git a/lib/vasprintf.c b/lib/vasprintf.c
index 5ec0282..5f35951 100644
--- a/lib/vasprintf.c
+++ b/lib/vasprintf.c
@@ -80,7 +80,7 @@ int_vasprintf (result, format, args)
else
total_width += strtoul (p, &p, 10);
}
- while (strchr ("hlL", *p))
+ while (strchr ("hlLjtz", *p))
++p;
/* Should be big enough for any format specifier except %s
and floats. */
diff --git a/lib/xgetcwd.c b/lib/xgetcwd.c
index 7ab2204..896be5d 100644
--- a/lib/xgetcwd.c
+++ b/lib/xgetcwd.c
@@ -1,5 +1,5 @@
/* xgetcwd.c -- return current directory with unlimited length
- Copyright (C) 1992, 1996 Free Software Foundation, Inc.
+ Copyright (C) 1992, 1996, 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
@@ -37,12 +37,9 @@ char *getwd ();
# define getcwd(Buf, Max) getwd (Buf)
#endif
-/* Amount to increase buffer size by in each try. */
-#define PATH_INCR 32
-
-char *xmalloc ();
-char *xrealloc ();
-void free ();
+extern void *xmalloc ();
+extern char *xstrdup ();
+extern void free ();
/* Return the current directory, newly allocated, arbitrarily long.
Return NULL and set errno on error. */
@@ -50,30 +47,39 @@ void free ();
char *
xgetcwd ()
{
- char *cwd;
char *ret;
unsigned path_max;
+ char buf[1024];
errno = 0;
+ ret = getcwd (buf, sizeof (buf));
+ if (ret != NULL)
+ return xstrdup (buf);
+ if (errno != ERANGE)
+ return NULL;
+
path_max = (unsigned) PATH_MAX;
path_max += 2; /* The getcwd docs say to do this. */
- cwd = xmalloc (path_max);
-
- errno = 0;
- while ((ret = getcwd (cwd, path_max)) == NULL && errno == ERANGE)
+ for (;;)
{
- path_max += PATH_INCR;
- cwd = xrealloc (cwd, path_max);
+ char *cwd = (char *) xmalloc (path_max);
+
errno = 0;
- }
+ ret = getcwd (cwd, path_max);
+ if (ret != NULL)
+ return ret;
+ if (errno != ERANGE)
+ {
+ int save_errno = errno;
+ free (cwd);
+ errno = save_errno;
+ return NULL;
+ }
- if (ret == NULL)
- {
- int save_errno = errno;
free (cwd);
- errno = save_errno;
- return NULL;
+
+ path_max += path_max / 16;
+ path_max += 32;
}
- return cwd;
}
diff --git a/lib/xmalloc.c b/lib/xmalloc.c
index 8217c99..5b4d128 100644
--- a/lib/xmalloc.c
+++ b/lib/xmalloc.c
@@ -1,5 +1,5 @@
/* xmalloc.c -- malloc with out of memory checking
- Copyright (C) 1990, 91, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
+ Copyright (C) 1990-1996, 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
@@ -27,7 +27,7 @@
#include <sys/types.h>
-#if STDC_HEADERS
+#if HAVE_STDLIB_H
# include <stdlib.h>
#else
VOID *calloc ();
@@ -50,8 +50,12 @@ void free ();
# define EXIT_FAILURE 1
#endif
+#ifndef NULL
+# define NULL ((VOID *) 0)
+#endif
+
/* Prototypes for functions defined here. */
-#if defined (__STDC__) && __STDC__
+#if defined (__GNUC__) || (defined (__STDC__) && __STDC__)
static VOID *fixup_null_alloc (size_t n);
VOID *xmalloc (size_t n);
VOID *xcalloc (size_t n, size_t s);
@@ -64,9 +68,9 @@ VOID *xrealloc (VOID *p, size_t n);
int xmalloc_exit_failure = EXIT_FAILURE;
#if __STDC__ && (HAVE_VPRINTF || HAVE_DOPRNT)
-void error (int, int, const char *, ...);
+extern void error (int, int, const char *, ...);
#else
-void error ();
+extern void error ();
#endif
static VOID *
@@ -78,7 +82,7 @@ fixup_null_alloc (n)
p = 0;
if (n == 0)
p = malloc ((size_t) 1);
- if (p == 0)
+ if (p == NULL)
error (xmalloc_exit_failure, 0, _("Memory exhausted"));
return p;
}
@@ -92,7 +96,7 @@ xmalloc (n)
VOID *p;
p = malloc (n);
- if (p == 0)
+ if (p == NULL)
p = fixup_null_alloc (n);
return p;
}
@@ -106,7 +110,7 @@ xcalloc (n, s)
VOID *p;
p = calloc (n, s);
- if (p == 0)
+ if (p == NULL)
p = fixup_null_alloc (n);
return p;
}
@@ -120,10 +124,10 @@ xrealloc (p, n)
VOID *p;
size_t n;
{
- if (p == 0)
+ if (p == NULL)
return xmalloc (n);
p = realloc (p, n);
- if (p == 0)
+ if (p == NULL)
p = fixup_null_alloc (n);
return p;
}
diff --git a/lib/xstrdup.c b/lib/xstrdup.c
index d5bcaf3..d71f7ae 100644
--- a/lib/xstrdup.c
+++ b/lib/xstrdup.c
@@ -1,5 +1,5 @@
/* xstrdup.c -- copy a string with out of memory checking
- Copyright (C) 1990, 1996 Free Software Foundation, Inc.
+ Copyright (C) 1990, 1996, 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
@@ -19,24 +19,23 @@
# include <config.h>
#endif
-#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
+#if HAVE_STRING_H
# include <string.h>
#else
# include <strings.h>
#endif
-#if defined (__STDC__) && __STDC__
-char *xmalloc (size_t);
-char *xstrdup (char *string);
+#if defined (__GNUC__) || (defined (__STDC__) && __STDC__)
+extern char *xmalloc (size_t);
#else
-char *xmalloc ();
+extern char *xmalloc ();
#endif
/* Return a newly allocated copy of STRING. */
char *
xstrdup (string)
- char *string;
+ const char *string;
{
return strcpy (xmalloc (strlen (string) + 1), string);
}
diff --git a/src/ChangeLog b/src/ChangeLog
index a1288ca..6f15476 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2000-12-30 Bruno Haible <haible@clisp.cons.org>
+
+ * msgfmt.c (write_table): Pass additional argument &id_len to
+ iterate_table.
+
2000-09-13 Bruno Haible <haible@clisp.cons.org>
Look into #define bodies.
diff --git a/src/msgfmt.c b/src/msgfmt.c
index 6230ebe..d535ed5 100644
--- a/src/msgfmt.c
+++ b/src/msgfmt.c
@@ -728,7 +728,8 @@ write_table (output_file, tab)
struct id_str_pair *msg_arr;
void *ptr;
size_t cnt;
- char *id;
+ const void *id;
+ size_t id_len;
struct msgstr_def *entry;
struct string_desc sd;
@@ -755,10 +756,10 @@ write_table (output_file, tab)
/* Read values from hashing table into array. */
for (cnt = 0, ptr = NULL;
- iterate_table (tab, &ptr, (const void **) &id, (void **) &entry) >= 0;
+ iterate_table (tab, &ptr, &id, &id_len, (void **) &entry) >= 0;
++cnt)
{
- msg_arr[cnt].id = id;
+ msg_arr[cnt].id = (char *) id;
msg_arr[cnt].str = entry->msgstr;
}