www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

mktemp.sh (866B)


      1 #!/bin/sh
      2 
      3 set -e
      4 
      5 the_tmp_dir="${_CS_DARWIN_USER_TEMP_DIR:-"${TMPDIR:-"/tmp"}"}/"
      6 
      7 if test $# -ge 1 && test "$1" = "-d"; then
      8   shift
      9   mkdir_opt='-d'
     10 else
     11   mkdir_opt=''
     12 fi
     13 
     14 if test $# -gt 0; then
     15   echo "Usage: $0 [-d]" >&2
     16   exit 1
     17 fi
     18 
     19 result="$(mktemp $mkdir_opt "${the_tmp_dir}/tmp.XXXXXXXXXX")"
     20 
     21 # Sanity checks:
     22 
     23 # Something went wrong while creating the file or directory:
     24 if ! test -e "$result"; then echo "MKTEMP_SH_ERROR"; exit 1; fi
     25 # This could result in a very bad rm invocation:
     26 if ! test "$result" != "/"; then echo "MKTEMP_SH_ERROR"; exit 1; fi
     27 # Something went wrong while creating the file:
     28 if test "x$mkdir_opt" = "x" && ! test -f "$result"; then echo "MKTEMP_SH_ERROR"; exit 1; fi
     29 # Something went wrong while creating the directory:
     30 if test "x$mkdir_opt" = "x-d" && ! test -d "$result"; then echo "MKTEMP_SH_ERROR"; exit 1; fi
     31 
     32 echo "$result"