| 1 | # Copyright 1999-2005 Gentoo Foundation |
1 | # Copyright 1999-2005 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.193 2005/07/21 02:16:45 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.194 2005/08/09 22:40:39 vapier Exp $ |
| 4 | # |
4 | # |
| 5 | # Author: Martin Schlemmer <azarah@gentoo.org> |
5 | # Author: Martin Schlemmer <azarah@gentoo.org> |
| 6 | # |
6 | # |
| 7 | # This eclass is for general purpose functions that most ebuilds |
7 | # This eclass is for general purpose functions that most ebuilds |
| 8 | # have to implement themselves. |
8 | # have to implement themselves. |
| … | |
… | |
| 375 | # vapier@gentoo.org |
375 | # vapier@gentoo.org |
| 376 | # |
376 | # |
| 377 | # Takes just 1 optional parameter (the directory to create tmpfile in) |
377 | # Takes just 1 optional parameter (the directory to create tmpfile in) |
| 378 | emktemp() { |
378 | emktemp() { |
| 379 | local exe="touch" |
379 | local exe="touch" |
| 380 | [ "$1" == "-d" ] && exe="mkdir" && shift |
380 | [[ $1 == -d ]] && exe="mkdir" && shift |
| 381 | local topdir="$1" |
381 | local topdir=$1 |
| 382 | |
382 | |
| 383 | if [ -z "${topdir}" ] |
383 | if [[ -z ${topdir} ]] ; then |
| 384 | then |
|
|
| 385 | [ -z "${T}" ] \ |
384 | [[ -z ${T} ]] \ |
| 386 | && topdir="/tmp" \ |
385 | && topdir="/tmp" \ |
| 387 | || topdir="${T}" |
386 | || topdir=${T} |
| 388 | fi |
387 | fi |
| 389 | |
388 | |
| 390 | if [ -z "$(type -p mktemp)" ] |
389 | if [[ -z $(type -p mktemp) ]] ; then |
| 391 | then |
|
|
| 392 | local tmp=/ |
390 | local tmp=/ |
| 393 | while [ -e "${tmp}" ] ; do |
391 | while [[ -e ${tmp} ]] ; do |
| 394 | tmp="${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM}" |
392 | tmp=${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM} |
| 395 | done |
393 | done |
| 396 | ${exe} "${tmp}" |
394 | ${exe} "${tmp}" || ${exe} -p "${tmp}" |
| 397 | echo "${tmp}" |
395 | echo "${tmp}" |
| 398 | else |
396 | else |
| 399 | [ "${exe}" == "touch" ] \ |
397 | [[ ${exe} == "touch" ]] \ |
| 400 | && exe="-p" \ |
398 | && exe="-p" \ |
| 401 | || exe="-d" |
399 | || exe="-d" |
| 402 | mktemp ${exe} "${topdir}" |
400 | mktemp ${exe} "${topdir}" |
| 403 | fi |
401 | fi |
| 404 | } |
402 | } |