about summary refs log tree commit diff
path: root/misc/dirname.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/dirname.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/dirname.c')
-rw-r--r--misc/dirname.c21
1 files changed, 12 insertions, 9 deletions
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