--- mc-4.6.0/doc/ru/mc.1.in.jj	2003-02-03 22:59:14.000000000 +0100
+++ mc-4.6.0/doc/ru/mc.1.in	2004-04-13 18:24:11.114172689 +0200
@@ -1557,8 +1557,10 @@ A	Dump the currently selected file
 	od -c %f
 
 B	Edit a bug report and send it to root
-	vi /tmp/mail.$$
-	mail -s "Midnight Commander bug" root < /tmp/mail.$$
+	I=`mktemp ${MC_TMPDIR:-/tmp}/mail.XXXXXX` || exit 1
+	vi $I
+	mail -s "Midnight Commander bug" root < $I
+	rm -f $I
 
 M	Read mail
 	emacs -f rmail
--- mc-4.6.0/doc/mc.1.in.jj	2003-02-05 16:54:31.000000000 +0100
+++ mc-4.6.0/doc/mc.1.in	2004-04-13 18:21:17.634262547 +0200
@@ -1385,8 +1385,10 @@ A	Dump the currently selected file
 	od -c %f
 
 B	Edit a bug report and send it to root
-	vi /tmp/mail.$$
-	mail -s "Midnight Commander bug" root < /tmp/mail.$$
+	I=`mktemp ${MC_TMPDIR:-/tmp}/mail.XXXXXX` || exit 1
+	vi $I
+	mail -s "Midnight Commander bug" root < $I
+	rm -f $I
 
 M	Read mail
 	emacs -f rmail
--- mc-4.6.0/doc/es/mc.1.in.jj	2003-02-05 16:54:31.000000000 +0100
+++ mc-4.6.0/doc/es/mc.1.in	2004-04-13 18:21:39.714305516 +0200
@@ -1361,8 +1361,10 @@ A	Vuelca el contenido del archivo selecc
 	od -c %f
 
 B	Edita un informe de errores y lo envía al superusuario
-	vi /tmp/mail.$$
-	mail -s "Error Midnight Commander" root < /tmp/mail.$$
+	I=`mktemp ${MC_TMPDIR:-/tmp}/mail.XXXXXX` || exit 1
+	vi $I
+	mail -s "Error Midnight Commander" root < $I
+	rm -f $I
 
 M	Lee al correo
 	emacs -f rmail
--- mc-4.6.0/doc/it/mc.1.in.jj	2003-01-19 18:11:06.000000000 +0100
+++ mc-4.6.0/doc/it/mc.1.in	2004-04-13 18:23:26.018254464 +0200
@@ -1379,8 +1379,10 @@ A	Mostra un dump del file correntemente 
 	od -c %f
 
 B	Modifica un rapporto bachi e lo spedisce a root
-	vi /tmp/mail.$$
-	mail -s "Midnight Commander bug" root < /tmp/mail.$$
+	I=`mktemp ${MC_TMPDIR:-/tmp}/mail.XXXXXX` || exit 1
+	vi $I
+	mail -s "Midnight Commander bug" root < $I
+	rm -f $I
 
 M	Legge la posta
 	emacs -f rmail
--- mc-4.6.0/doc/hu/mc.1.in.jj	2003-01-16 11:30:55.000000000 +0100
+++ mc-4.6.0/doc/hu/mc.1.in	2004-04-13 18:22:50.634595677 +0200
@@ -1381,8 +1381,10 @@ A       A kiválasztott fájlok listázása 
         od -c %f
 
 B       A hiba leírás szerkesztése és elküldése a root-nak
-        vi /tmp/mail.$$
-        mail -s "Midnight Commander bug" root < /tmp/mail.$$
+	I=`mktemp ${MC_TMPDIR:-/tmp}/mail.XXXXXX` || exit 1
+        vi $I
+        mail -s "Midnight Commander bug" root < $I
+	rm -f $I
 
 M       Levél olvasás
         emacs -f rmail
--- mc-4.6.0/lib/cedit.menu.jj	2002-08-24 19:39:08.000000000 +0200
+++ mc-4.6.0/lib/cedit.menu	2004-04-13 18:18:40.771374419 +0200
@@ -449,7 +449,7 @@ s       Invoke `shell'
 
 m       view `man'
         MAN=%{Enter name of man:}
-        TMPFILE=/tmp/mcview.$MAN.$$
+        TMPFILE=`mktemp ${MC_TMPDIR:-/tmp}/mcview.$MAN.$$` || exit 1
         man -Pcat $MAN >$TMPFILE
         mcview $TMPFILE
         rm -f $TMPFILE
--- mc-4.6.0/lib/mc.menu.jj	2002-12-08 02:12:19.000000000 +0100
+++ mc-4.6.0/lib/mc.menu	2004-04-13 18:25:27.982396902 +0200
@@ -14,9 +14,10 @@ shell_patterns=0
 	
 
 0       Edit a bug report and send it to root
-        ${EDITOR-vi} /tmp/mail.$$
-	test -r /tmp/mail.$$ && mail root < /tmp/mail.$$
-	rm -f /tmp/mail.$$
+	I=`mktemp ${MC_TMPDIR:-/tmp}/mail.XXXXXX` || exit 1
+	${EDITOR-vi} $I
+	test -r $I && mail root < $I
+	rm -f $I
 
 =+ f \.1$ | f \.3$ | f \.4$ | f \.5$ | f \.6$ | f \.7$ | f \.8$ | f \.man$ & t r
 1       Display the file with roff -man
@@ -112,8 +113,9 @@ h       Strip headers from current newsa
 	CHECK=`awk '{print $1 ; exit}' %f` 2>/dev/null
 	case $CHECK in
 	  Newsgroups:|Path:)
-	      cp %f /tmp/%f.$$ && sed '/^'"$CHECK"' /,/^$/d' /tmp/%f.$$ > %f
-              [ "$?" = "0" ] && rm /tmp/%f.$$
+	      I=`mktemp ${MC_TMPDIR:-/tmp}/news.XXXXXX` || exit 1
+	      cp %f $I && sed '/^'"$CHECK"' /,/^$/d' $I > %f
+              [ "$?" = "0" ] && rm $I
 	      echo %f: header removed
 		;;
 	  *)
@@ -126,7 +128,7 @@ H       Strip headers from the marked ne
 	set %t
 	while [ -n "$1" ]; do
 	  CHECK=`awk '{print $1 ; exit}' $1` 2>/dev/null
-	  WFILE=/tmp/${1}.$$
+	  WFILE=`mktemp ${MC_TMPDIR:-/tmp}/news.XXXXXX` || exit 1
 	  case $CHECK in
 	    Newsgroups:|Path:)
 	      cp $1 $WFILE && sed '/^'"$CHECK"' /,/^$/d' $WFILE > $1
--- mc-4.6.0/vfs/extfs/deb.in.jj	2002-12-11 21:57:00.000000000 +0100
+++ mc-4.6.0/vfs/extfs/deb.in	2004-04-13 19:21:34.022158752 +0200
@@ -149,15 +149,10 @@ sub mcdebfs_run
 	}
 	else
 	{
-	        $suffix = "aaa";
-		while (1) {
-		    $tmpdir = "/tmp/mcdebfs.run".$$.$suffix;
-		    last if mkdir $tmpdir, 0700;
-		    $suffix++;
-		    # Somebody is being really nasty, give up
-		    exit 1 if $suffix eq "zzz";
-		}
-		
+		use File::Temp qw(mkdtemp);
+		my $template = "/tmp/mcdebfs.run.XXXXXX";
+		$template="$ENV{MC_TMPDIR}/mcdebfs.XXXXXX" if ($ENV{MC_TMPDIR});
+		$tmpdir = mkdtemp($template);
 		$tmpcmd="$tmpdir/run";
 		&mcdebfs_copyout($archive, $filename, $tmpcmd);
 		system("chmod u+x $tmpcmd");
--- mc-4.6.0/vfs/extfs/uar.in.jj	2002-12-12 10:21:35.000000000 +0100
+++ mc-4.6.0/vfs/extfs/uar.in	2004-04-07 18:35:10.000000000 +0200
@@ -22,8 +22,7 @@ mcarfs_copyout ()
 
 mcarfs_copyin ()
 {
-    TMPDIR=/tmp/mctmpdir-uar.$$
-    mkdir $TMPDIR || exit 1
+    TMPDIR=`mktemp -d ${MC_TMPDIR:-/tmp}/mctmpdir-uar.XXXXXX` || exit 1
     name=`basename "$2"`
     (cd $TMPDIR && cp -fp "$3" $name && $XAR r "$1" $name)
     rm -rf $TMPDIR
--- mc-4.6.0/vfs/extfs/uha.in.jj	2002-12-14 06:10:53.000000000 +0100
+++ mc-4.6.0/vfs/extfs/uha.in	2004-04-07 18:36:03.000000000 +0200
@@ -31,8 +31,7 @@ mchafs_list ()
 
 mchafs_copyout ()
 {
-    TMPDIR="/tmp/mctmpdir-uha.$$"
-    mkdir $TMPDIR || exit 1
+    TMPDIR=`mktemp -d ${MC_TMPDIR:-/tmp}/mctmpdir-uha.XXXXXX` || exit 1
     cd $TMPDIR
 
     $HA xyq "$1" "$2" >/dev/null
--- mc-4.6.0/vfs/extfs/ulha.in.jj	2002-12-14 05:39:10.000000000 +0100
+++ mc-4.6.0/vfs/extfs/ulha.in	2004-04-07 18:39:35.000000000 +0200
@@ -35,12 +35,6 @@ LHA_LIST="lha lq"
 LHA_GET="lha pq"
 LHA_PUT="lha aq"
 
-# Define a directory to create a temporary file for when
-# running a command to be run from the archive
-TMPDIR="/tmp/mctmpdir-uha.$$"
-# Temporary file within the directory
-TMPCMD=$TMPDIR/run
-
 # The 'list' command executive
 
 mc_lha_fs_list()
@@ -121,9 +115,9 @@ mc_lha_fs_copyin ()
 
 mc_lha_fs_run()
 {
+   TMPDIR=`mktemp -d ${MC_TMPDIR:-/tmp}/mctmpdir-ulha.XXXXXX` || exit 1
    trap "rm -rf $TMPDIR; exit 0" 1 2 3 4 15
-   # FIXME: Try harder to generate a unique directory if this fails
-   mkdir -m 0700 $TMPDIR || exit 1
+   TMPCMD=$TMPDIR/run
    $LHA_GET "$1" "$2" > $TMPCMD  
    chmod a+x $TMPCMD
    $TMPCMD
--- mc-4.6.0/vfs/extfs/urar.in.jj	2003-01-24 16:56:25.000000000 +0100
+++ mc-4.6.0/vfs/extfs/urar.in	2004-04-07 18:44:29.000000000 +0200
@@ -77,8 +77,7 @@ mcrarfs_mkdir ()
 # preserve pwd. It is clean, but is it necessary?
     pwd=`pwd`
 # Create a directory and create in it a tmp directory with the good name     
-    dir=tmpdir.${RANDOM}
-    mkdir $dir
+    dir=`mktemp -d ${MC_TMPDIR:-/tmp}/mctmpdir-urar.XXXXXX` || exit 1
     cd $dir
     mkdir -p "$2"  
 # rar cannot create an empty directory    
--- mc-4.6.0/vfs/extfs/uzip.in.jj	2002-12-12 10:15:20.000000000 +0100
+++ mc-4.6.0/vfs/extfs/uzip.in	2004-04-13 19:21:52.297883504 +0200
@@ -344,10 +344,10 @@ sub cleandirs {
 
 # Make a temporary directory with mode 0700.
 sub mktmpdir {
-	while (1) {
-		my $dir = POSIX::tmpnam();
-		return $dir if mkdir ($dir, 0700);
-	}
+	use File::Temp qw(mkdtemp);
+	my $template = "/tmp/mcuzipfs.XXXXXX";
+	$template="$ENV{MC_TMPDIR}/mcuzipfs.XXXXXX" if ($ENV{MC_TMPDIR});
+	return mkdtemp($template);
 }
 
 # Make a filename absolute and return it.
--- mc-4.6.0/vfs/extfs/uzoo.in.jj	2002-12-14 05:29:13.000000000 +0100
+++ mc-4.6.0/vfs/extfs/uzoo.in	2004-04-07 18:47:50.000000000 +0200
@@ -13,8 +13,7 @@ ZOO=zoo
 # it to a temporary directory.
 mklink ()
 {
-    TMPDIR="/tmp/mctmpdir-uzoo.$$"
-    mkdir $TMPDIR || exit 1
+    TMPDIR=`mktemp -d ${MC_TMPDIR:-/tmp}/mctmpdir-uzoo.XXXXXX` || exit 1
     trap 'cd /; rm -rf $TMPDIR' 0 1 2 3 5 13 15
     ARCHIVE=$TMPDIR/tmp.zoo
     ln -sf "$1" "$ARCHIVE"
