On 6 May 2014 15:36, Eric Blake <ebl...@redhat.com> wrote: > mktemp is not POSIX. BSD mktemp lacks -t: > > http://www.freebsd.org/cgi/man.cgi?query=mktemp&apropos=0&sektion=1&manpath=Red+Hat+Linux%2Fi386+9&format=html
Sigh. > and there are probably systems that lack mktemp(1) altogether. You'll > need to come up with a more portable alternative. > > Here's what autoconf recommends (modify to fit...): > > # Create a (secure) tmp directory for tmp files. > > { > tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && > test -d "$tmp" > } || > { > tmp=./conf$$-$RANDOM > (umask 077 && mkdir "$tmp") > } || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 > ac_tmp=$tmp Yuck. > The use of $$ and $RANDOM is safe (even on shells that lack $RANDOM) > because of the fact that mkdir is atomic and the umask is correctly set > prior to the mkdir. I dislike the use of $RANDOM, because it means we behave inconsistently. If it's OK for $RANDOM to expand to "" then we should just not use it at all, because that's OK and the same everywhere. Similarly, if it's OK not to use mktemp on some systems, we should use the same non-mktemp code everywhere. We could sidestep this rubbish by not trying to put our temp files in /tmp/, and instead just put them in the build directory (ie ./conf-temps/ or something similar, which we blow away and recreate every time). thanks -- PMM