[BusyBox] dirname root directory fix

Matt Kraai kraai at alumni.carnegiemellon.edu
Tue Dec 12 21:03:43 UTC 2000


Howdy,

BusyBox dirname currently returns . when passed the root directory / .
The attached patch makes it return / instead, per GNU.

Matt
-------------- next part --------------
Index: dirname.c
===================================================================
RCS file: /var/cvs/busybox/dirname.c,v
retrieving revision 1.8
diff -u -r1.8 dirname.c
--- dirname.c	2000/12/01 02:55:13	1.8
+++ dirname.c	2000/12/12 20:58:02
@@ -32,13 +32,14 @@
 	argv++;
 
 	s=*argv+strlen(*argv)-1;
-	while (s && *s == '/') {
-		*s = '\0';
-		s=*argv+strlen(*argv)-1;
+	while (s != *argv && *s == '/') {
+		*s-- = '\0';
 	}
 	s = strrchr(*argv, '/');
-	if (s && *s)
+	if (s != NULL && s == *argv)
+		s[1] = '\0';
+	else if (s != NULL)
 		*s = '\0';
-	printf("%s\n", (s)? *argv : ".");
+	puts(s ? *argv : ".");
 	return EXIT_SUCCESS;
 }


More information about the busybox mailing list