name=$(basename "$0")
# prefer /dev/shm because it's an in-memory
# space that we can use to store data without
# having bits laying around in sectors.
tmpdir=/dev/shm
# fall back to $TMPDIR or /tmp - /dev/shm is Linux-only
# and shared memory space on other operating systems
# have non-standard methods of setup/access.
[ -w /dev/shm ] || tmpdir=${TMPDIR:-/tmp}

# reimplement mktemp here, because
# mktemp isn't defined in POSIX.
tmpfile=${tmpdir}/${name}.$(rand_chars 10 'A-Za-z0-9') \
  || die "couldn't generate random characters"

trap 'rm -f "$tmpfile"' EXIT
