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);
}
*/
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();
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);
}
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 */
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,
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)
{
// 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;