Apply vodz' last_patch52
[oweals/busybox.git] / libbb / dirname.c
index 2e89fc17a11e7c531cad68a6dba6ab89fb879d86..df9a49daa77c9341d360ffe78b3e9d1ce5b24b92 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#include <string.h>
 #include "libbb.h"
 
-/* Return a string on the heap containing the directory component of PATH.  */
+#if defined __UCLIBC__ || __GNU_LIBRARY___ < 5
 
-char *dirname(const char *path)
+/* Return a string containing the path name of the parent
+ * directory of PATH.  */
+
+char *dirname(char *path)
 {
-       const char *s;
+       char *s;
 
        /* Go to the end of the string.  */
        s = path + strlen(path) - 1;
@@ -42,7 +46,10 @@ char *dirname(const char *path)
                s--;
 
        if (s < path)
-               return xstrdup (".");
-       else
-               return strdup_substr (path, 0, s - path + 1);
+               return ".";
+
+       s[1] = '\0';
+       return path;
 }
+
+#endif