Fix the bug that would make `du /' omit the `/' on the last line.
authorJim Meyering <jim@meyering.net>
Wed, 9 Jul 2003 10:00:42 +0000 (10:00 +0000)
committerJim Meyering <jim@meyering.net>
Wed, 9 Jul 2003 10:00:42 +0000 (10:00 +0000)
E.g., `du --exclude '[^/]*' -x /' would print only "4\t\n" for me.

(ftw_dir): Don't clobber the leading `/'.
Reported by Chris Lesniewski as http://bugs.debian.org/200542.

lib/ftw.c

index 16b8bfb..5d26b4a 100644 (file)
--- a/lib/ftw.c
+++ b/lib/ftw.c
@@ -605,8 +605,9 @@ ftw_dir (struct ftw_data *data, struct FTW_STAT *st)
       __set_errno (save_err);
     }
 
-  /* Prepare the return, revert the `struct FTW' information.  */
-  data->dirbuf[data->ftw.base - 1] = '\0';
+  /* Prepare the return, revert the `struct FTW' information.
+     If ftw.base is 1, be careful to preserve the `/'.  */
+  data->dirbuf[data->ftw.base == 1 ? 1 : data->ftw.base - 1] = '\0';
   --data->ftw.level;
   data->ftw.base = previous_base;