+/**
+ * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
+ * where either in the "PATHS" section or the environtment "FOO" is
+ * set to "DIRECTORY". We also support default expansion,
+ * i.e. ${VARIABLE:-default} will expand to $VARIABLE if VARIABLE is
+ * set in PATHS or the environment, and otherwise to "default". Note
+ * that "default" itself can also be a $-expression, thus
+ * "${VAR1:-{$VAR2}}" will expand to VAR1 and if that is not defined
+ * to VAR2.
+ *
+ * @param cfg configuration to use for path expansion
+ * @param orig string to $-expand (will be freed!). Note that multiple
+ * $-expressions can be present in this string. They will all be
+ * $-expanded.
+ * @return $-expanded string
+ */
+char *
+GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ char *orig)
+{
+ char *dup;
+ size_t i;
+ size_t len;
+
+ for (i = 0; '\0' != orig[i]; i++)
+ {
+ if ('$' != orig[i])
+ continue;
+ dup = GNUNET_strdup (orig + i);
+ dup = expand_dollar (cfg, dup, 0);
+ len = strlen (dup) + 1;
+ orig = GNUNET_realloc (orig, i + len);
+ memcpy (orig + i, dup, len);
+ GNUNET_free (dup);
+ }
+ return orig;
+}
+
+