~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to src/shred.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* shred.c - overwrite files and devices to make it harder to recover data
2
2
 
3
 
   Copyright (C) 1999-2011 Free Software Foundation, Inc.
 
3
   Copyright (C) 1999-2012 Free Software Foundation, Inc.
4
4
   Copyright (C) 1997, 1998, 1999 Colin Plumb.
5
5
 
6
6
   This program is free software: you can redistribute it and/or modify
18
18
 
19
19
   Written by Colin Plumb.  */
20
20
 
21
 
/* TODO:
22
 
   - use consistent non-capitalization in error messages
23
 
   - add standard GNU copyleft comment
24
 
 
25
 
  - Add -r/-R/--recursive
26
 
  - Add -i/--interactive
27
 
  - Reserve -d
28
 
  - Add -L
29
 
  - Add an unlink-all option to emulate rm.
30
 
 */
31
 
 
32
21
/*
33
22
 * Do a more secure overwrite of given files or devices, to make it harder
34
23
 * for even very expensive hardware probing to recover the data.
79
68
 *   drastically bad if told to attack a named pipe or socket?
80
69
 */
81
70
 
82
 
/* The official name of this program (e.g., no `g' prefix).  */
 
71
/* The official name of this program (e.g., no 'g' prefix).  */
83
72
#define PROGRAM_NAME "shred"
84
73
 
85
74
#define AUTHORS proper_name ("Colin Plumb")
152
141
usage (int status)
153
142
{
154
143
  if (status != EXIT_SUCCESS)
155
 
    fprintf (stderr, _("Try `%s --help' for more information.\n"),
156
 
             program_name);
 
144
    emit_try_help ();
157
145
  else
158
146
    {
159
147
      printf (_("Usage: %s [OPTION]... FILE...\n"), program_name);
497
485
 
498
486
      offset += soff;
499
487
 
 
488
      bool done = offset == size;
 
489
 
500
490
      /* Time to print progress? */
501
 
      if (n
502
 
          && ((offset == size && *previous_human_offset)
503
 
              || thresh <= (now = time (NULL))))
 
491
      if (n && ((done && *previous_human_offset)
 
492
                || thresh <= (now = time (NULL))))
504
493
        {
505
494
          char offset_buf[LONGEST_HUMAN_READABLE + 1];
506
495
          char size_buf[LONGEST_HUMAN_READABLE + 1];
510
499
            = human_readable (offset, offset_buf,
511
500
                              human_floor | human_progress_opts, 1, 1);
512
501
 
513
 
          if (offset == size
514
 
              || !STREQ (previous_human_offset, human_offset))
 
502
          if (done || !STREQ (previous_human_offset, human_offset))
515
503
            {
516
504
              if (size < 0)
517
505
                error (0, 0, _("%s: pass %lu/%lu (%s)...%s"),
528
516
                    = human_readable (size, size_buf,
529
517
                                      human_ceiling | human_progress_opts,
530
518
                                      1, 1);
531
 
                  if (offset == size)
 
519
                  if (done)
532
520
                    human_offset = human_size;
533
521
                  error (0, 0, _("%s: pass %lu/%lu (%s)...%s/%s %d%%"),
534
522
                         qname, k, n, pass_string, human_offset, human_size,
822
810
            }
823
811
        }
824
812
 
825
 
      /* Allow `rounding up' only for regular files.  */
 
813
      /* Allow 'rounding up' only for regular files.  */
826
814
      if (0 <= size && !(flags->exact) && S_ISREG (st.st_mode))
827
815
        {
828
816
          size += ST_BLKSIZE (st) - 1 - (size - 1) % ST_BLKSIZE (st);