X-Git-Url: http://git.tuebingen.mpg.de/?p=gsu.git;a=blobdiff_plain;f=common;h=ec7b8e2cfd816f1faadc6b2ffd8c45c2da37fc28;hp=d41809585ab22e282fdc57ed757ea9e716b66aae;hb=692f2f3c9dfd6a1d6692e6f131e4e40c02f7f1bc;hpb=1e5e330b7a100636ef7d3874a322e7c23d7fe575 diff --git a/common b/common index d418095..ec7b8e2 100644 --- a/common +++ b/common @@ -90,3 +90,35 @@ _gsu_setup() gsu_banner_txt="${gsu_banner_txt:-set \$gsu_banner_txt to customize this message}" _gsu_init_errors } + +# We'd love to use mktemp -t here, but on Linux -t is deprecated in favor of +# --tempdir, which is not supported on *BSD. Hence we have to implement our own +# logic for -t. +# +# The second parameter to this function is optional. It is ignored if the +# template ($1) is an absolute path. Conversely, if the template is a relative +# path and a second parameter is given, $2 is assumed to be the directory in +# which the temporary file should be created. +gsu_make_tempfile() +{ + local template="$1" + local dir + + if [[ "${template:0:1}" != '/' ]]; then # relative path + if (($# > 1)); then + dir="$2" + elif [[ -n "${TMPDIR:-}" ]]; then + dir="$TMPDIR" + else + dir="/tmp" + fi + template="$dir/$template" + fi + result="$(mktemp "$template")" + if (($? != 0)); then + ret=-$E_GSU_MKTEMP + result="template: $template" + return + fi + ret=$GSU_SUCCESS +}