summaryrefslogtreecommitdiff
path: root/libbb/dirname.c
diff options
context:
space:
mode:
authorMatt Kraai2001-08-24 19:51:54 +0000
committerMatt Kraai2001-08-24 19:51:54 +0000
commitac20ce1924a0eb563acfda6533a80701cd611bfa (patch)
tree5209668fde99a5caa4ed41d8d61c73770fcae646 /libbb/dirname.c
parent2a953aed3831f8705444e720783ad4781904a625 (diff)
downloadbusybox-ac20ce1924a0eb563acfda6533a80701cd611bfa.zip
busybox-ac20ce1924a0eb563acfda6533a80701cd611bfa.tar.gz
Canonicalize dirname(3) behavior.
Diffstat (limited to 'libbb/dirname.c')
-rw-r--r--libbb/dirname.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/libbb/dirname.c b/libbb/dirname.c
index 5f83994..87db1f2 100644
--- a/libbb/dirname.c
+++ b/libbb/dirname.c
@@ -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;
}