*: introduce and use xmkstemp. -65 bytes.
authorAlexander Shishkin <virtuoso@slind.org>
Fri, 22 Oct 2010 11:27:16 +0000 (13:27 +0200)
committerDenys Vlasenko <dvlasenk@redhat.com>
Fri, 22 Oct 2010 11:27:16 +0000 (13:27 +0200)
Signed-off-by: Alexander Shishkin <virtuoso@slind.org>
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
coreutils/dos2unix.c
editors/diff.c
editors/patch.c
editors/sed.c
include/libbb.h
libbb/xfuncs_printf.c
printutils/lpr.c

index ba1ca8c79dd906f3292c2a1cb3ea31a00f282bbf..eab8110dc8146563e71c5e35c92c59df34ddbfa2 100644 (file)
@@ -41,12 +41,10 @@ static void convert(char *fn, int conv_type)
                fstat(fileno(in), &st);
 
                temp_fn = xasprintf("%sXXXXXX", resolved_fn);
-               i = mkstemp(temp_fn);
-               if (i == -1
-                || fchmod(i, st.st_mode) == -1
-               ) {
+               i = xmkstemp(temp_fn);
+               if (fchmod(i, st.st_mode) == -1)
                        bb_simple_perror_msg_and_die(temp_fn);
-               }
+
                out = xfdopen_for_write(i);
        }
 
index 83de5275302d2f29e6e0010294fbc7e4513ec736..d9d709db6cdfe2dc40afac41e90b844ec3bed936 100644 (file)
@@ -685,9 +685,8 @@ static int diffreg(char *file[2])
                 */
                if (lseek(fd, 0, SEEK_SET) == -1 && errno == ESPIPE) {
                        char name[] = "/tmp/difXXXXXX";
-                       int fd_tmp = mkstemp(name);
-                       if (fd_tmp < 0)
-                               bb_perror_msg_and_die("mkstemp");
+                       int fd_tmp = xmkstemp(name);
+
                        unlink(name);
                        if (bb_copyfd_eof(fd, fd_tmp) < 0)
                                xfunc_die();
index fff06907f653312bc9ccdb5c5c12c5687f16657c..33ff8b569a7bb0b2771084b95abccbee9156f31d 100644 (file)
@@ -200,8 +200,7 @@ int copy_tempfile(int fdin, char *name, char **tempname)
        int fd;
 
        *tempname = xasprintf("%sXXXXXX", name);
-       fd = mkstemp(*tempname);
-       if(-1 == fd) bb_perror_msg_and_die("no temp file");
+       fd = xmkstemp(*tempname);
 
        // Set permissions of output file
        fstat(fdin, &statbuf);
index 8d9f7b25be0fbbe6609a77bb5f0d90049b5a4347..964d0405ee922d14eca4024783e0b4ea34eb5acc 100644 (file)
@@ -1370,9 +1370,7 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
                        }
 
                        G.outname = xasprintf("%sXXXXXX", argv[i]);
-                       nonstdoutfd = mkstemp(G.outname);
-                       if (-1 == nonstdoutfd)
-                               bb_perror_msg_and_die("can't create temp file %s", G.outname);
+                       nonstdoutfd = xmkstemp(G.outname);
                        G.nonstdout = xfdopen_for_write(nonstdoutfd);
 
                        /* Set permissions/owner of output file */
index 01dc33e63ee1f9ae1d5583d073cc0d3071a43964..409c434cb8bcf9eab030c40dcc2c13db6f31e7e1 100644 (file)
@@ -425,6 +425,7 @@ int xopen_stdin(const char *pathname) FAST_FUNC;
 void xrename(const char *oldpath, const char *newpath) FAST_FUNC;
 int rename_or_warn(const char *oldpath, const char *newpath) FAST_FUNC;
 off_t xlseek(int fd, off_t offset, int whence) FAST_FUNC;
+int xmkstemp(char *template) FAST_FUNC;
 off_t fdlength(int fd) FAST_FUNC;
 
 uoff_t FAST_FUNC get_volume_size_in_bytes(int fd,
index ba660a2dbf2497df04316f121716313035d2db44..56ee459e45ffa4549692642646f7207ac19de5ce 100644 (file)
@@ -240,6 +240,14 @@ off_t FAST_FUNC xlseek(int fd, off_t offset, int whence)
        return off;
 }
 
+int FAST_FUNC xmkstemp(char *template)
+{
+       int fd = mkstemp(template);
+       if (fd < 0)
+               bb_perror_msg_and_die("can't create temp file '%s'", template);
+       return fd;
+}
+
 // Die with supplied filename if this FILE* has ferror set.
 void FAST_FUNC die_if_ferror(FILE *fp, const char *fn)
 {
index fb7860d414e75330024a95575ae266867658189b..284917926393b74387b23bdfd13405626522fbb7 100644 (file)
@@ -159,9 +159,7 @@ int lpqr_main(int argc UNUSED_PARAM, char *argv[])
                // if data file is stdin, we need to dump it first
                if (LONE_DASH(*argv)) {
                        strcpy(tempfile, "/tmp/lprXXXXXX");
-                       dfd = mkstemp(tempfile);
-                       if (dfd < 0)
-                               bb_perror_msg_and_die("mkstemp");
+                       dfd = xmkstemp(tempfile);
                        bb_copyfd_eof(STDIN_FILENO, dfd);
                        xlseek(dfd, 0, SEEK_SET);
                        *argv = (char*)bb_msg_standard_input;