aboutsummaryrefslogtreecommitdiff
path: root/libbb/dirname.c
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2001-08-24 19:51:54 +0000
committerMatt Kraai <kraai@debian.org>2001-08-24 19:51:54 +0000
commitac20ce1924a0eb563acfda6533a80701cd611bfa (patch)
tree5209668fde99a5caa4ed41d8d61c73770fcae646 /libbb/dirname.c
parent2a953aed3831f8705444e720783ad4781904a625 (diff)
downloadbusybox-w32-ac20ce1924a0eb563acfda6533a80701cd611bfa.tar.gz
busybox-w32-ac20ce1924a0eb563acfda6533a80701cd611bfa.tar.bz2
busybox-w32-ac20ce1924a0eb563acfda6533a80701cd611bfa.zip
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 5f839945d..87db1f24f 100644
--- a/libbb/dirname.c
+++ b/libbb/dirname.c
@@ -22,7 +22,8 @@
22#include <string.h> 22#include <string.h>
23#include "libbb.h" 23#include "libbb.h"
24 24
25/* Return a string on the heap containing the directory component of PATH. */ 25/* Return a string containing the path name of the parent
26 * directory of PATH. */
26 27
27char *dirname(const char *path) 28char *dirname(const char *path)
28{ 29{
@@ -43,7 +44,8 @@ char *dirname(const char *path)
43 s--; 44 s--;
44 45
45 if (s < path) 46 if (s < path)
46 return xstrdup ("."); 47 return ".";
47 else 48
48 return xstrndup (path, s - path + 1); 49 s[1] = '\0';
50 return path;
49} 51}