/* TODO:
x use getopt_long
- - use error, not pferror
+ x use error, not pferror
- bracket strings with _(...) for gettext
*/
#include <config.h>
#include <getopt.h>
+#include <stdio.h>
#include <stdarg.h> /* Used by pferror */
#include "system.h"
*/
#if __GNUC__ >= 2
static void pfstatus (char const *,...) __attribute__ ((format (printf, 1, 2)));
-static void pferror (char const *,...) __attribute__ ((format (printf, 1, 2)));
#endif
/*
}
}
-/* Print an error message on stderr, leaving any status message visible. */
-static void
-pferror (char const *fmt,...)
-{
- va_list ap;
- int e = errno;
-
- flushstatus (); /* Make it look pretty */
-
- if (program_name)
- {
- fputs (program_name, stderr);
- fputs (": ", stderr);
- }
- va_start (ap, fmt);
- vfprintf (stderr, fmt, ap);
- va_end (ap);
- fputs (": ", stderr);
- fputs (strerror (e), stderr);
- putc ('\n', stderr);
-}
-
/*
* Get the size of a file that doesn't want to cooperate (such as a
* device) by doing a binary search for the last readable byte. The size
if (lseek (fd, 0, SEEK_SET) < 0)
{
- pferror ("Error seeking `%s'", name);
+ error (0, 0, _("Error seeking `%s'"), name);
return -1;
}
if (ssize < 0)
{
int e = errno;
- pferror ("Error writing `%s' at %lu",
- name, size - cursize + soff);
+ error (0, 0, _("Error writing `%s' at %lu"),
+ name, size - cursize + soff);
/* FIXME: this is slightly fragile in that some systems
may fail with a different errno. */
/* This error confuses people. */
/* Force what we just wrote to hit the media. */
if (fdatasync (fd) < 0)
{
- pferror ("Error syncing `%s'", name);
+ error (0, 0, _("Error syncing `%s'"), name);
return -1;
}
return 0;
if (!passes)
passes = DEFAULT_PASSES;
- n = 0; /* dopass takes n -- 0 to mean "don't print progress" */
+ n = 0; /* dopass takes n -- 0 to mean "don't print progress" */
if (flags->verbose)
n = passes + ((flags->zero_fill) != 0);
if (fstat (fd, &st))
{
- pferror ("Can't fstat file `%s'", name);
+ error (0, 0, _("Can't fstat file `%s'"), name);
return -1;
}
/* Check for devices */
if (!S_ISREG (st.st_mode) && !(flags->allow_devices))
{
- fprintf (stderr,
- "`%s' is not a regular file: use -d to enable operations on devices\n",
- name);
+ error (0, 0,
+ _("`%s' is not a regular file: use -d to enable operations on devices"),
+ name);
return -1;
}
passarray = malloc (passes * sizeof (int));
if (!passarray)
{
- pferror ("Can't alllocate array for %lu passes",
- (unsigned long) passes);
+ error (0, 0, _("unable to allocate storage for %lu passes"),
+ (unsigned long) passes);
return -1;
}
newname = strdup (oldname); /* This is a malloc */
if (!newname)
{
- pferror ("malloc failed");
+ error (0, 0, _("malloc failed"));
return -1;
}
if (flags->verbose)
origname = strdup (oldname);
if (!origname)
{
- pferror ("malloc failed");
+ error (0, 0, _("malloc failed"));
free (newname);
return -1;
}
}
if (fd < 0)
{
- pferror ("Unable to open `%s'", name);
+ error (0, 0, _("Unable to open `%s'"), name);
return -1;
}
{
err = wipename (name, flags);
if (err < 0)
- pferror ("Unable to delete file `%s'", name);
+ error (0, 0, _("Unable to delete file `%s'"), name);
}
return err;
}