*: introduce and use xmkstemp. -65 bytes.
Signed-off-by: Alexander Shishkin <virtuoso@slind.org> Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
This commit is contained in:
parent
cbfeaac7af
commit
6722737ece
@ -41,12 +41,10 @@ static void convert(char *fn, int conv_type)
|
|||||||
fstat(fileno(in), &st);
|
fstat(fileno(in), &st);
|
||||||
|
|
||||||
temp_fn = xasprintf("%sXXXXXX", resolved_fn);
|
temp_fn = xasprintf("%sXXXXXX", resolved_fn);
|
||||||
i = mkstemp(temp_fn);
|
i = xmkstemp(temp_fn);
|
||||||
if (i == -1
|
if (fchmod(i, st.st_mode) == -1)
|
||||||
|| fchmod(i, st.st_mode) == -1
|
|
||||||
) {
|
|
||||||
bb_simple_perror_msg_and_die(temp_fn);
|
bb_simple_perror_msg_and_die(temp_fn);
|
||||||
}
|
|
||||||
out = xfdopen_for_write(i);
|
out = xfdopen_for_write(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -685,9 +685,8 @@ static int diffreg(char *file[2])
|
|||||||
*/
|
*/
|
||||||
if (lseek(fd, 0, SEEK_SET) == -1 && errno == ESPIPE) {
|
if (lseek(fd, 0, SEEK_SET) == -1 && errno == ESPIPE) {
|
||||||
char name[] = "/tmp/difXXXXXX";
|
char name[] = "/tmp/difXXXXXX";
|
||||||
int fd_tmp = mkstemp(name);
|
int fd_tmp = xmkstemp(name);
|
||||||
if (fd_tmp < 0)
|
|
||||||
bb_perror_msg_and_die("mkstemp");
|
|
||||||
unlink(name);
|
unlink(name);
|
||||||
if (bb_copyfd_eof(fd, fd_tmp) < 0)
|
if (bb_copyfd_eof(fd, fd_tmp) < 0)
|
||||||
xfunc_die();
|
xfunc_die();
|
||||||
|
@ -200,8 +200,7 @@ int copy_tempfile(int fdin, char *name, char **tempname)
|
|||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
*tempname = xasprintf("%sXXXXXX", name);
|
*tempname = xasprintf("%sXXXXXX", name);
|
||||||
fd = mkstemp(*tempname);
|
fd = xmkstemp(*tempname);
|
||||||
if(-1 == fd) bb_perror_msg_and_die("no temp file");
|
|
||||||
|
|
||||||
// Set permissions of output file
|
// Set permissions of output file
|
||||||
fstat(fdin, &statbuf);
|
fstat(fdin, &statbuf);
|
||||||
|
@ -1370,9 +1370,7 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
G.outname = xasprintf("%sXXXXXX", argv[i]);
|
G.outname = xasprintf("%sXXXXXX", argv[i]);
|
||||||
nonstdoutfd = mkstemp(G.outname);
|
nonstdoutfd = xmkstemp(G.outname);
|
||||||
if (-1 == nonstdoutfd)
|
|
||||||
bb_perror_msg_and_die("can't create temp file %s", G.outname);
|
|
||||||
G.nonstdout = xfdopen_for_write(nonstdoutfd);
|
G.nonstdout = xfdopen_for_write(nonstdoutfd);
|
||||||
|
|
||||||
/* Set permissions/owner of output file */
|
/* Set permissions/owner of output file */
|
||||||
|
@ -425,6 +425,7 @@ int xopen_stdin(const char *pathname) FAST_FUNC;
|
|||||||
void xrename(const char *oldpath, const char *newpath) FAST_FUNC;
|
void xrename(const char *oldpath, const char *newpath) FAST_FUNC;
|
||||||
int rename_or_warn(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;
|
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;
|
off_t fdlength(int fd) FAST_FUNC;
|
||||||
|
|
||||||
uoff_t FAST_FUNC get_volume_size_in_bytes(int fd,
|
uoff_t FAST_FUNC get_volume_size_in_bytes(int fd,
|
||||||
|
@ -240,6 +240,14 @@ off_t FAST_FUNC xlseek(int fd, off_t offset, int whence)
|
|||||||
return off;
|
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.
|
// Die with supplied filename if this FILE* has ferror set.
|
||||||
void FAST_FUNC die_if_ferror(FILE *fp, const char *fn)
|
void FAST_FUNC die_if_ferror(FILE *fp, const char *fn)
|
||||||
{
|
{
|
||||||
|
@ -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 data file is stdin, we need to dump it first
|
||||||
if (LONE_DASH(*argv)) {
|
if (LONE_DASH(*argv)) {
|
||||||
strcpy(tempfile, "/tmp/lprXXXXXX");
|
strcpy(tempfile, "/tmp/lprXXXXXX");
|
||||||
dfd = mkstemp(tempfile);
|
dfd = xmkstemp(tempfile);
|
||||||
if (dfd < 0)
|
|
||||||
bb_perror_msg_and_die("mkstemp");
|
|
||||||
bb_copyfd_eof(STDIN_FILENO, dfd);
|
bb_copyfd_eof(STDIN_FILENO, dfd);
|
||||||
xlseek(dfd, 0, SEEK_SET);
|
xlseek(dfd, 0, SEEK_SET);
|
||||||
*argv = (char*)bb_msg_standard_input;
|
*argv = (char*)bb_msg_standard_input;
|
||||||
|
Loading…
Reference in New Issue
Block a user