aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Shishkin <virtuoso@slind.org>2010-10-22 13:27:16 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-10-22 13:27:16 +0200
commit6722737ece4b8db3e30b53aef8f981f53db1621e (patch)
tree8e2ddb1d3a43d595ac4584e3d1ef23f49a462bf4
parentcbfeaac7afe31323d46c52da3b98a949232d708e (diff)
downloadbusybox-w32-6722737ece4b8db3e30b53aef8f981f53db1621e.tar.gz
busybox-w32-6722737ece4b8db3e30b53aef8f981f53db1621e.tar.bz2
busybox-w32-6722737ece4b8db3e30b53aef8f981f53db1621e.zip
*: introduce and use xmkstemp. -65 bytes.
Signed-off-by: Alexander Shishkin <virtuoso@slind.org> Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r--coreutils/dos2unix.c8
-rw-r--r--editors/diff.c5
-rw-r--r--editors/patch.c3
-rw-r--r--editors/sed.c4
-rw-r--r--include/libbb.h1
-rw-r--r--libbb/xfuncs_printf.c8
-rw-r--r--printutils/lpr.c4
7 files changed, 17 insertions, 16 deletions
diff --git a/coreutils/dos2unix.c b/coreutils/dos2unix.c
index ba1ca8c79..eab8110dc 100644
--- a/coreutils/dos2unix.c
+++ b/coreutils/dos2unix.c
@@ -41,12 +41,10 @@ static void convert(char *fn, int conv_type)
41 fstat(fileno(in), &st); 41 fstat(fileno(in), &st);
42 42
43 temp_fn = xasprintf("%sXXXXXX", resolved_fn); 43 temp_fn = xasprintf("%sXXXXXX", resolved_fn);
44 i = mkstemp(temp_fn); 44 i = xmkstemp(temp_fn);
45 if (i == -1 45 if (fchmod(i, st.st_mode) == -1)
46 || fchmod(i, st.st_mode) == -1
47 ) {
48 bb_simple_perror_msg_and_die(temp_fn); 46 bb_simple_perror_msg_and_die(temp_fn);
49 } 47
50 out = xfdopen_for_write(i); 48 out = xfdopen_for_write(i);
51 } 49 }
52 50
diff --git a/editors/diff.c b/editors/diff.c
index 83de52753..d9d709db6 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -685,9 +685,8 @@ static int diffreg(char *file[2])
685 */ 685 */
686 if (lseek(fd, 0, SEEK_SET) == -1 && errno == ESPIPE) { 686 if (lseek(fd, 0, SEEK_SET) == -1 && errno == ESPIPE) {
687 char name[] = "/tmp/difXXXXXX"; 687 char name[] = "/tmp/difXXXXXX";
688 int fd_tmp = mkstemp(name); 688 int fd_tmp = xmkstemp(name);
689 if (fd_tmp < 0) 689
690 bb_perror_msg_and_die("mkstemp");
691 unlink(name); 690 unlink(name);
692 if (bb_copyfd_eof(fd, fd_tmp) < 0) 691 if (bb_copyfd_eof(fd, fd_tmp) < 0)
693 xfunc_die(); 692 xfunc_die();
diff --git a/editors/patch.c b/editors/patch.c
index fff06907f..33ff8b569 100644
--- a/editors/patch.c
+++ b/editors/patch.c
@@ -200,8 +200,7 @@ int copy_tempfile(int fdin, char *name, char **tempname)
200 int fd; 200 int fd;
201 201
202 *tempname = xasprintf("%sXXXXXX", name); 202 *tempname = xasprintf("%sXXXXXX", name);
203 fd = mkstemp(*tempname); 203 fd = xmkstemp(*tempname);
204 if(-1 == fd) bb_perror_msg_and_die("no temp file");
205 204
206 // Set permissions of output file 205 // Set permissions of output file
207 fstat(fdin, &statbuf); 206 fstat(fdin, &statbuf);
diff --git a/editors/sed.c b/editors/sed.c
index 8d9f7b25b..964d0405e 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -1370,9 +1370,7 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
1370 } 1370 }
1371 1371
1372 G.outname = xasprintf("%sXXXXXX", argv[i]); 1372 G.outname = xasprintf("%sXXXXXX", argv[i]);
1373 nonstdoutfd = mkstemp(G.outname); 1373 nonstdoutfd = xmkstemp(G.outname);
1374 if (-1 == nonstdoutfd)
1375 bb_perror_msg_and_die("can't create temp file %s", G.outname);
1376 G.nonstdout = xfdopen_for_write(nonstdoutfd); 1374 G.nonstdout = xfdopen_for_write(nonstdoutfd);
1377 1375
1378 /* Set permissions/owner of output file */ 1376 /* Set permissions/owner of output file */
diff --git a/include/libbb.h b/include/libbb.h
index 01dc33e63..409c434cb 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -425,6 +425,7 @@ int xopen_stdin(const char *pathname) FAST_FUNC;
425void xrename(const char *oldpath, const char *newpath) FAST_FUNC; 425void xrename(const char *oldpath, const char *newpath) FAST_FUNC;
426int rename_or_warn(const char *oldpath, const char *newpath) FAST_FUNC; 426int rename_or_warn(const char *oldpath, const char *newpath) FAST_FUNC;
427off_t xlseek(int fd, off_t offset, int whence) FAST_FUNC; 427off_t xlseek(int fd, off_t offset, int whence) FAST_FUNC;
428int xmkstemp(char *template) FAST_FUNC;
428off_t fdlength(int fd) FAST_FUNC; 429off_t fdlength(int fd) FAST_FUNC;
429 430
430uoff_t FAST_FUNC get_volume_size_in_bytes(int fd, 431uoff_t FAST_FUNC get_volume_size_in_bytes(int fd,
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index ba660a2db..56ee459e4 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -240,6 +240,14 @@ off_t FAST_FUNC xlseek(int fd, off_t offset, int whence)
240 return off; 240 return off;
241} 241}
242 242
243int FAST_FUNC xmkstemp(char *template)
244{
245 int fd = mkstemp(template);
246 if (fd < 0)
247 bb_perror_msg_and_die("can't create temp file '%s'", template);
248 return fd;
249}
250
243// Die with supplied filename if this FILE* has ferror set. 251// Die with supplied filename if this FILE* has ferror set.
244void FAST_FUNC die_if_ferror(FILE *fp, const char *fn) 252void FAST_FUNC die_if_ferror(FILE *fp, const char *fn)
245{ 253{
diff --git a/printutils/lpr.c b/printutils/lpr.c
index fb7860d41..284917926 100644
--- a/printutils/lpr.c
+++ b/printutils/lpr.c
@@ -159,9 +159,7 @@ int lpqr_main(int argc UNUSED_PARAM, char *argv[])
159 // if data file is stdin, we need to dump it first 159 // if data file is stdin, we need to dump it first
160 if (LONE_DASH(*argv)) { 160 if (LONE_DASH(*argv)) {
161 strcpy(tempfile, "/tmp/lprXXXXXX"); 161 strcpy(tempfile, "/tmp/lprXXXXXX");
162 dfd = mkstemp(tempfile); 162 dfd = xmkstemp(tempfile);
163 if (dfd < 0)
164 bb_perror_msg_and_die("mkstemp");
165 bb_copyfd_eof(STDIN_FILENO, dfd); 163 bb_copyfd_eof(STDIN_FILENO, dfd);
166 xlseek(dfd, 0, SEEK_SET); 164 xlseek(dfd, 0, SEEK_SET);
167 *argv = (char*)bb_msg_standard_input; 165 *argv = (char*)bb_msg_standard_input;