summaryrefslogtreecommitdiff
path: root/sponge.c
diff options
context:
space:
mode:
authorJoey Hess <joey@kodama.kitenet.net>2008-04-11 19:03:50 -0400
committerJoey Hess <joey@kodama.kitenet.net>2008-04-11 19:03:50 -0400
commitb6d635bc28bf7d94201bcd167905cebc48abf7cb (patch)
treef4d017809c490df4ffd1e661ecc0f6d9f2995417 /sponge.c
parentf69844b98d71598fbf9ef3f4da137b16eff1621e (diff)
downloadmoreutils-b6d635bc28bf7d94201bcd167905cebc48abf7cb.tar.gz
minor changes
Diffstat (limited to 'sponge.c')
-rw-r--r--sponge.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/sponge.c b/sponge.c
index f17bf86..0dd676a 100644
--- a/sponge.c
+++ b/sponge.c
@@ -223,7 +223,9 @@ FILE *open_tmpfile(void) {
mode_t mask;
char *tmpdir;
char const * const template="%s/sponge.XXXXXX";
-
+
+ trapsignals();
+ cs = cs_enter();
tmpdir = getenv("TMPDIR");
if (tmpdir == NULL)
tmpdir = "/tmp";
@@ -234,14 +236,12 @@ FILE *open_tmpfile(void) {
exit(1);
}
sprintf(tmpname, template, tmpdir);
-
- trapsignals();
- cs = cs_enter();
mask=umask(077);
tmpfd = mkstemp(tmpname);
umask(mask);
atexit(onexit_cleanup); // solaris on_exit(onexit_cleanup, 0);
cs_leave(cs);
+
if (tmpfd < 0) {
perror("mkstemp failed");
exit(1);
@@ -340,7 +340,6 @@ int main (int argc, char **argv) {
}
}
else {
- outfile = stdout;
if (outname) {
outfile = fopen(outname, "w");
if (!outfile) {
@@ -348,6 +347,9 @@ int main (int argc, char **argv) {
exit(1);
}
}
+ else {
+ outfile = stdout;
+ }
if (bufused)
write_buff_out(bufstart, bufused, outfile);
fclose(outfile);