summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog20
-rw-r--r--misc/dirname.c21
-rw-r--r--misc/efgcvt.c29
-rw-r--r--misc/qefgcvt.c3
-rw-r--r--misc/tst-dirname.c8
-rw-r--r--misc/tst-efgcvt.c1
6 files changed, 67 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index e1a6eefca7..546bc94f26 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2000-12-13 Jakub Jelinek <jakub@redhat.com>
+
+ * misc/efgcvt.c (FCVT_MAXDIG): Define.
+ (FCVT_BUFPTR): New variable.
+ (fcvt): If fcvt_r returns -1 on the static short buffer,
+ try to malloc a sufficiently large one and retry.
+ (free_mem): New function.
+ * misc/qefgcvt.c (FCVT_MAXDIG): Define.
+ * misc/tst-efgcvt.c (fcvt_tests): Add new test.
+
+2000-12-15 Ulrich Drepper <drepper@redhat.com>
+
+ * misc/dirname.c (dirname): Fix search for second to last slash.
+
+2000-12-13 Andreas Jaeger <aj@suse.de>
+
+ * misc/tst-dirname.c (main): Fix typo in test to really use
+ the examples from Unix98.
+ Reported by Michael Kerrisk <mtk16@ext.canterbury.ac.nz>.
+
2000-12-09 H.J. Lu <hjl@gnu.org>
* sysdeps/ia64/fpu/s_fabs.S: New file.
diff --git a/misc/dirname.c b/misc/dirname.c
index 26c5a8b1ee..8be25e51b8 100644
--- a/misc/dirname.c
+++ b/misc/dirname.c
@@ -1,5 +1,5 @@
/* dirname - return directory part of PATH.
- Copyright (C) 1996 Free Software Foundation, Inc.
+ Copyright (C) 1996, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
@@ -31,17 +31,20 @@ dirname (char *path)
/* Find last '/'. */
last_slash = path != NULL ? strrchr (path, '/') : NULL;
- if (last_slash == path)
- /* The last slash is the first character in the string. We have to
- return "/". */
- ++last_slash;
- else if (last_slash != NULL && last_slash[1] == '\0')
+ if (last_slash != NULL && last_slash != path && last_slash[1] == '\0')
/* The '/' is the last character, we have to look further. */
- last_slash = memchr (path, last_slash - path, '/');
+ last_slash = __memrchr (path, '/', last_slash - path);
if (last_slash != NULL)
- /* Terminate the path. */
- last_slash[0] = '\0';
+ {
+ /* Terminate the path. */
+ if (last_slash == path)
+ /* The last slash is the first character in the string. We have to
+ return "/". */
+ ++last_slash;
+
+ last_slash[0] = '\0';
+ }
else
/* This assignment is ill-designed but the XPG specs require to
return a string containing "." in any case no directory part is
diff --git a/misc/efgcvt.c b/misc/efgcvt.c
index 37b4bc0163..5196c10565 100644
--- a/misc/efgcvt.c
+++ b/misc/efgcvt.c
@@ -31,6 +31,7 @@
/* Actually we have to write (DBL_DIG + log10 (DBL_MAX_10_EXP)) but we
don't have log10 available in the preprocessor. */
# define MAXDIG (NDIGIT_MAX + 3)
+# define FCVT_MAXDIG (DBL_MAX_10_EXP + MAXDIG)
# if DBL_MANT_DIG == 53
# define NDIGIT_MAX 17
# elif DBL_MANT_DIG == 24
@@ -50,22 +51,34 @@
#define FCVT_BUFFER APPEND (FUNC_PREFIX, fcvt_buffer)
+#define FCVT_BUFPTR APPEND (FUNC_PREFIX, fcvt_bufptr)
#define ECVT_BUFFER APPEND (FUNC_PREFIX, ecvt_buffer)
static char FCVT_BUFFER[MAXDIG];
static char ECVT_BUFFER[MAXDIG];
-
+static char *FCVT_BUFPTR;
char *
APPEND (FUNC_PREFIX, fcvt) (value, ndigit, decpt, sign)
FLOAT_TYPE value;
int ndigit, *decpt, *sign;
{
+ if (FCVT_BUFPTR == NULL)
+ {
+ if (APPEND (FUNC_PREFIX, fcvt_r) (value, ndigit, decpt, sign,
+ FCVT_BUFFER, MAXDIG) != -1)
+ return FCVT_BUFFER;
+
+ FCVT_BUFPTR = (char *) malloc (FCVT_MAXDIG);
+ if (FCVT_BUFPTR == NULL)
+ return FCVT_BUFFER;
+ }
+
(void) APPEND (FUNC_PREFIX, fcvt_r) (value, ndigit, decpt, sign,
- FCVT_BUFFER, MAXDIG);
+ FCVT_BUFPTR, FCVT_MAXDIG);
- return FCVT_BUFFER;
+ return FCVT_BUFPTR;
}
@@ -89,3 +102,13 @@ APPEND (FUNC_PREFIX, gcvt) (value, ndigit, buf)
sprintf (buf, "%.*" FLOAT_FMT_FLAG "g", MIN (ndigit, NDIGIT_MAX), value);
return buf;
}
+
+/* Free all resources if necessary. */
+static void __attribute__ ((unused))
+free_mem (void)
+{
+ if (FCVT_BUFPTR != NULL)
+ free (FCVT_BUFPTR);
+}
+
+text_set_element (__libc_subfreeres, free_mem);
diff --git a/misc/qefgcvt.c b/misc/qefgcvt.c
index 63fc764121..2c5d636083 100644
--- a/misc/qefgcvt.c
+++ b/misc/qefgcvt.c
@@ -1,5 +1,5 @@
/* Compatibility functions for floating point formatting, long double version.
- Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1999, 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
@@ -26,6 +26,7 @@
we don't have log10 available in the preprocessor. Since we cannot
assume anything on the used `long double' format be generous. */
#define MAXDIG (NDIGIT_MAX + 12)
+#define FCVT_MAXDIG (LDBL_MAX_10_EXP + MAXDIG)
#if LDBL_MANT_DIG == 64
# define NDIGIT_MAX 21
#elif LDBL_MANT_DIG == 53
diff --git a/misc/tst-dirname.c b/misc/tst-dirname.c
index fd24488f4f..e688bd3a42 100644
--- a/misc/tst-dirname.c
+++ b/misc/tst-dirname.c
@@ -24,7 +24,7 @@
#include <string.h>
-int
+static int
test (const char *input, const char *result)
{
int retval;
@@ -45,11 +45,15 @@ main (void)
/* These are the examples given in XPG4.2. */
result |= test ("/usr/lib", "/usr");
- result |= test ("/usr", "/");
+ result |= test ("/usr/", "/");
result |= test ("usr", ".");
result |= test ("/", "/");
result |= test (".", ".");
result |= test ("..", ".");
+ /* Some more tests. */
+ result |= test ("/usr/lib/", "/usr");
+ result |= test ("/usr", "/");
+
return result != 0;
}
diff --git a/misc/tst-efgcvt.c b/misc/tst-efgcvt.c
index 6eaa8be9f5..f2edb9d912 100644
--- a/misc/tst-efgcvt.c
+++ b/misc/tst-efgcvt.c
@@ -81,6 +81,7 @@ static testcase fcvt_tests[] =
{ 100.01, -4, 3, "100" },
{ 123.01, -4, 3, "100" },
{ 126.71, -4, 3, "100" },
+ { 322.5, 16, 3, "3225000000000000000" },
/* -1.0 is end marker. */
{ -1.0, 0, 0, "" }
};