summary refs log tree commit diff
path: root/misc/efgcvt.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-12-16 07:54:18 +0000
committerUlrich Drepper <drepper@redhat.com>2000-12-16 07:54:18 +0000
commit887e7ab6c5a13398e5986c7054235a135e6429f9 (patch)
tree04556d2595001782246223937c3a43c58d4b9f63 /misc/efgcvt.c
parentbafd15679c55e35440a9fd11069614b43559413c (diff)
downloadglibc-887e7ab6c5a13398e5986c7054235a135e6429f9.tar.gz
glibc-887e7ab6c5a13398e5986c7054235a135e6429f9.tar.xz
glibc-887e7ab6c5a13398e5986c7054235a135e6429f9.zip
Update.
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>.
Diffstat (limited to 'misc/efgcvt.c')
-rw-r--r--misc/efgcvt.c29
1 files changed, 26 insertions, 3 deletions
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);