3 # Copyright (c) 2013-2014. The SimGrid Team.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the license (GNU LGPL) which comes with this package.
10 LISTSEP="$(printf '\b')"
12 # Create a temporary file, with its name of the form $1_XXX$2, where XXX is replaced by an unique string.
13 # $1: prefix, $2: suffix
15 tmp=$(mktemp --suffix="$2" "$1_XXXXXXXXXX" 2> /dev/null)
16 if [ -z "$tmp" ]; then
17 # mktemp failed (unsupported --suffix ?), try unsafe mode
18 tmp=$(mktemp -u "$1_XXXXXXXXXX" 2> /dev/null)
19 if [ -z "$tmp" ]; then
20 # mktemp failed again (doesn't exist ?), try very unsafe mode
21 if [ -z "${mymktemp_seq}" ]; then
22 mymktemp_seq=$(date +%d%H%M%S)
24 tmp="$1_$$x${mymktemp_seq}"
25 mymktemp_seq=$((mymktemp_seq + 1))
28 # create temp file, and exit if it existed before
29 sh -C -c "true > \"${tmp}\"" || exit 1
34 # Add a word to the end of a list (words separated by LISTSEP)
35 # $1: list, $2...: words to add
37 local list content newcontent
41 eval content=\"\${$list}\"
45 if [ -z "$content" ]; then
48 content="$content${LISTSEP}$newcontent"
50 eval $list=\"\${content}\"
54 # Like list_add, but only if first word to add ($2) is not empty
55 list_add_not_empty () {
61 # Set contents of a list (words separated by LISTSEP)
62 # $1: list, $2...: words to set
68 # Get the content of a list: positional parameters ($1, $2, ...) are set to the content of the list
70 # usage: eval $(list_get list)
72 printf 'IFS="$LISTSEP"; eval set -- \\$%s; IFS="$SAVEIFS"' "$1"