]> git.saurik.com Git - apple/file_cmds.git/blobdiff - rm/rm.c
file_cmds-264.50.1.tar.gz
[apple/file_cmds.git] / rm / rm.c
diff --git a/rm/rm.c b/rm/rm.c
index e215ec88f283eefe2ebb622d5011f49e04ce7683..ec13b2a4f50f05ac787ddcb42cf655b00b00743a 100644 (file)
--- a/rm/rm.c
+++ b/rm/rm.c
@@ -31,8 +31,9 @@
  * SUCH DAMAGE.
  */
 
+#include <sys/cdefs.h>
 #ifndef lint
-static const char copyright[] =
+__used static const char copyright[] =
 "@(#) Copyright (c) 1990, 1993, 1994\n\
        The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
@@ -41,7 +42,7 @@ static const char copyright[] =
 #if 0
 static char sccsid[] = "@(#)rm.c       8.5 (Berkeley) 4/18/94";
 #else
-static const char rcsid[] =
+__used static const char rcsid[] =
   "$FreeBSD: src/bin/rm/rm.c,v 1.33 2001/06/13 15:01:25 ru Exp $";
 #endif
 #endif /* not lint */
@@ -529,10 +530,24 @@ checkdot(argv)
 
        complained = 0;
        for (t = argv; *t;) {
-               if ((p = strrchr(*t, '/')) != NULL)
-                       ++p;
-               else
+               size_t len = strlen(*t);
+               char truncated[len];
+
+               if ((p = strrchr(*t, '/')) != NULL) {
+                       if (p[1] == '\0') { // trailing / -- treat as if not present
+                               strlcpy(truncated, *t, len);
+                               p = strrchr(truncated, '/');
+                               if (p) {
+                                       ++p;
+                               } else {
+                                       p = truncated;
+                               }
+                       } else {
+                               ++p;
+                       }
+               } else {
                        p = *t;
+               }
                if (ISDOT(p)) {
                        if (!complained++)
                                warnx("\".\" and \"..\" may not be removed");