#!/bin/sh

destdir_=foo
template_=bar.XXXXXX

mkdir -p "$destdir_" || exit 1

# Try to use mktemp: first on systems which support -p, then without.
fail=
d=`unset TMPDIR; { mktemp -d -p "$destdir_" -t "$template_"; } 2>/dev/null` \
  || e=`TMPDIR="$destdir_" mktemp -d -t "$template_" 2>/dev/null` \
  || fail=1

sys=`uname -s`

if test "$d" ; then
    method=with-p
    dir="$d"
elif test "$e" ; then
    method=no-p
    dir="$e"
elif test "$fail" ; then
    method=X
    dir="(failed)"
else
    echo "error" >&2
    exit 1
fi
printf "%-10s   %s    %s\n" "$sys:" "$method" "$dir"
