bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

New option for du (-0 or --print0)


From: Olivier Delhomme
Subject: New option for du (-0 or --print0)
Date: Sat, 8 Nov 2003 23:10:42 +0100

TODO list says :

du: add option to use \0 as line terminator rather than \n so that
  tools like xdiskusage that parse du output don't choke on file names
  with embedded newlines.


I added that option (-0 --print0)

ChangeLog :

        * src/du.c
          Added option -0 --print0 which replaces the '\n' line terminator
          with '\0' so that parsing du output with special charaters is 
          more easy. 

Here is the patch :

--- coreutils/src/du.c  2003-10-31 21:48:55.000000000 +0100
+++ coreutils-m/src/du.c        2003-11-08 22:44:20.000000000 +0100
@@ -102,6 +102,9 @@
 /* Nonzero indicates that du should exit with EXIT_FAILURE upon completion.  */
 int G_fail;
 
+/* End of line character */
+static char eolc ='\n';
+
 #define IS_DIR_TYPE(Type)      \
   ((Type) == FTS_DP            \
    || (Type) == FTS_DNR)
@@ -137,6 +140,7 @@
   {"separate-dirs", no_argument, NULL, 'S'},
   {"summarize", no_argument, NULL, 's'},
   {"total", no_argument, NULL, 'c'},
+  {"print0", no_argument, NULL, '0'},
   {GETOPT_HELP_OPTION_DECL},
   {GETOPT_VERSION_OPTION_DECL},
   {NULL, 0, NULL, 0}
@@ -159,6 +163,7 @@
 Mandatory arguments to long options are mandatory for short options too.\n\
 "), stdout);
       fputs (_("\
+  -0, --print0          use \\0 as line terminator instead of \\n \n\
   -a, --all             write counts for all files, not just directories\n\
       --apparent-size   print apparent sizes, rather than disk usage; 
although\n\
                           the apparent size is usually smaller, it may be\n\
@@ -281,7 +286,7 @@
 print_size (uintmax_t n_bytes, const char *string)
 {
   print_only_size (n_bytes);
-  printf ("\t%s\n", string);
+  printf ("\t%s%c", string,eolc);
   fflush (stdout);
 }
 
@@ -456,7 +461,7 @@
       print_only_size (size_to_print);
       fputc ('\t', stdout);
       fputs (file, stdout);
-      fputc ('\n', stdout);
+      fputc (eolc, stdout);
       fflush (stdout);
     }
 }
@@ -542,7 +547,7 @@
                                     &output_block_size);
 
   fail = 0;
-  while ((c = getopt_long (argc, argv, "abchHklmsxB:DLPSX:",
+  while ((c = getopt_long (argc, argv, "0abchHklmsxB:DLPSX:",
                           long_options, NULL)) != -1)
     {
       long int tmp_long;
@@ -550,6 +555,10 @@
        {
        case 0:                 /* Long option. */
          break;
+        
+       case '0':
+          eolc = '\0';
+         break;
 
        case 'a':
          opt_all = 1;


-- 
web site       : http://olivier.delhomme.free.fr/
gpg public key : http://olivier.delhomme.free.fr/delhomme.gpg




reply via email to

[Prev in Thread] Current Thread [Next in Thread]