Group :: System/Configuration/Printing
RPM: mpage
Main Changelog Spec Patches Sources Download Gear Bugs and FR Repocop
Patch: mpage-2.5.7-alt-tmpfile.patch
Download
Download
diff --git a/mpage/file.c b/mpage/file.c
index f82d042..c029e06 100644
--- a/mpage/file.c
+++ b/mpage/file.c
@@ -27,7 +27,8 @@
#include "mpage.h"
-
+#include <error.h>
+extern const char *__progname;
static int looks_utf8(FILE *fp);
@@ -164,10 +165,21 @@ do_stdin(asheet, outfd)
#if 1
FILE *fd;
char buffer[LINESIZE];
- char tmpfile[LINESIZE];
int incnt, outcnt;
int tmpfd;
+ /*nomal tmpdir support*/
+ const char suffix[] = ".XXXXXX";
+ const char *tmp_dir = getenv("TMPDIR")?:"/tmp";
+ unsigned tmp_len = strlen( tmp_dir );
+ unsigned prog_len = strlen( __progname );
+ char tmpfile[ tmp_len + prog_len + sizeof(suffix) + 1 ];
+
+ memcpy( tmpfile, tmp_dir, tmp_len );
+ tmpfile[ tmp_len ] = '/';
+ memcpy( tmpfile + tmp_len + 1, __progname, prog_len );
+ memcpy( tmpfile + tmp_len + prog_len + 1, suffix, sizeof(suffix) );
+
/*
* Now the utf8 patch is in we always create a temporary file.
* So now is the time to just create a temp file and continue
@@ -176,7 +188,6 @@ do_stdin(asheet, outfd)
* but the tmpfilename
*/
- (void) strcpy(tmpfile, "/tmp/mpage-stdin-XXXXXX");
if ( (tmpfd = mkstemp(tmpfile)) == -1) {
fprintf(stderr, "%s: cannot create temporary file", MPAGE);
perror(MPAGE);