changeset 2783:aae08c7b0250

(dir_name): Assert that there are no trailing slashes.
author Jim Meyering <jim@meyering.net>
date Sat, 29 Jul 2000 08:10:46 +0000
parents f9406fb86c7f
children f2f0ccf4abab
files lib/dirname.c
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lib/dirname.c
+++ b/lib/dirname.c
@@ -32,6 +32,7 @@
 #  define strrchr rindex
 # endif
 #endif
+#include <assert.h>
 
 #ifndef ISSLASH
 # define ISSLASH(C) ((C) == '/')
@@ -52,6 +53,13 @@
   int length;			/* Length of result, not including NUL.  */
 
   slash = strrchr (path, '/');
+
+  /* Make sure there are no trailing slashes.  */
+  assert (slash == NULL	   /* There are no slashes in PATH.  */
+	  || slash[1] != 0 /* There is a non-NUL byte after the last slash.  */
+	  || path == slash /* PATH is just `/'.  */
+	  );
+
   if (slash == 0)
     {
       /* File is in the current directory.  */