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>.
This commit is contained in:
Ulrich Drepper 2000-12-16 07:54:18 +00:00
parent bafd15679c
commit 887e7ab6c5
6 changed files with 68 additions and 16 deletions

View File

@ -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.

View File

@ -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

View File

@ -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;
{
(void) APPEND (FUNC_PREFIX, fcvt_r) (value, ndigit, decpt, sign,
FCVT_BUFFER, MAXDIG);
if (FCVT_BUFPTR == NULL)
{
if (APPEND (FUNC_PREFIX, fcvt_r) (value, ndigit, decpt, sign,
FCVT_BUFFER, MAXDIG) != -1)
return FCVT_BUFFER;
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_BUFPTR, FCVT_MAXDIG);
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);

View File

@ -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

View File

@ -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;
}

View File

@ -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, "" }
};