Canonicalize dirname(3) behavior.

This commit is contained in:
Matt Kraai
2001-08-24 19:51:54 +00:00
parent 2a953aed38
commit ac20ce1924
5 changed files with 25 additions and 13 deletions

View File

@@ -22,7 +22,8 @@
#include <string.h>
#include "libbb.h"
/* Return a string on the heap containing the directory component of PATH. */
/* Return a string containing the path name of the parent
* directory of PATH. */
char *dirname(const char *path)
{
@@ -43,7 +44,8 @@ char *dirname(const char *path)
s--;
if (s < path)
return xstrdup (".");
else
return xstrndup (path, s - path + 1);
return ".";
s[1] = '\0';
return path;
}