]> err.no Git - moreutils/commitdiff
minor changes
authorJoey Hess <joey@kodama.kitenet.net>
Fri, 11 Apr 2008 23:03:50 +0000 (19:03 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Fri, 11 Apr 2008 23:03:50 +0000 (19:03 -0400)
sponge.c

index f17bf860d0ee49e105f72a7cfc76cf0f27654926..0dd676aa1d8dc0d04cab50cc36c1b676e76ccd12 100644 (file)
--- 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);