summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2013-10-06 17:26:51 +0100
committerPádraig Brady <P@draigBrady.com>2013-10-06 17:59:44 +0100
commit0c1d7917f19b4865544ab9f1b13dfcdfd4e65275 (patch)
treedd83d3ea254ca12948e4ce248676f76e3bef8934 /src
parent8e67c2dec1a595619d540bc3e52c2dfcf61a63a3 (diff)
downloadcoreutils-0c1d7917f19b4865544ab9f1b13dfcdfd4e65275.tar.xz
mktemp: with --quiet, only suppress I/O errors
The reason for having a --quiet option is to suppress only some subset of possible errors. The most useful separation here is with usage/internal errors, and errors due to file creation etc. (i.e. I/O errors). * src/mktemp.c (main): Match the --help and info docs and only suppress the file/dir creation error messages. * tests/misc/mktemp.pl: Adjust accordingly.
Diffstat (limited to 'src')
-rw-r--r--src/mktemp.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/src/mktemp.c b/src/mktemp.c
index 41d576306..05530a31a 100644
--- a/src/mktemp.c
+++ b/src/mktemp.c
@@ -26,7 +26,6 @@
#include "error.h"
#include "filenamecat.h"
#include "quote.h"
-#include "stdio--.h"
#include "tempname.h"
/* The official name of this program (e.g., no 'g' prefix). */
@@ -147,7 +146,7 @@ main (int argc, char **argv)
{
char const *dest_dir;
char const *dest_dir_arg = NULL;
- bool suppress_stderr = false;
+ bool suppress_file_err = false;
int c;
unsigned int n_args;
char *template;
@@ -181,7 +180,7 @@ main (int argc, char **argv)
use_dest_dir = true;
break;
case 'q':
- suppress_stderr = true;
+ suppress_file_err = true;
break;
case 't':
use_dest_dir = true;
@@ -205,15 +204,6 @@ main (int argc, char **argv)
}
}
- if (suppress_stderr)
- {
- /* From here on, redirect stderr to /dev/null.
- A diagnostic from getopt_long, above, would still go to stderr. */
- if (!freopen ("/dev/null", "wb", stderr))
- error (EXIT_FAILURE, errno,
- _("failed to redirect stderr to /dev/null"));
- }
-
n_args = argc - optind;
if (2 <= n_args)
{
@@ -317,8 +307,9 @@ main (int argc, char **argv)
int err = mkdtemp_len (dest_name, suffix_len, x_count, dry_run);
if (err != 0)
{
- error (0, errno, _("failed to create directory via template %s"),
- quote (template));
+ if (!suppress_file_err)
+ error (0, errno, _("failed to create directory via template %s"),
+ quote (template));
status = EXIT_FAILURE;
}
}
@@ -327,8 +318,9 @@ main (int argc, char **argv)
int fd = mkstemp_len (dest_name, suffix_len, x_count, dry_run);
if (fd < 0 || (!dry_run && close (fd) != 0))
{
- error (0, errno, _("failed to create file via template %s"),
- quote (template));
+ if (!suppress_file_err)
+ error (0, errno, _("failed to create file via template %s"),
+ quote (template));
status = EXIT_FAILURE;
}
}
@@ -342,7 +334,8 @@ main (int argc, char **argv)
{
int saved_errno = errno;
remove (dest_name);
- error (EXIT_FAILURE, saved_errno, _("write error"));
+ if (!suppress_file_err)
+ error (EXIT_FAILURE, saved_errno, _("write error"));
}
}