+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.
/* 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.
/* 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
/* 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
#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;
}
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);
/* 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
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
#include <string.h>
-int
+static int
test (const char *input, const char *result)
{
int retval;
/* 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;
}
{ 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, "" }
};