basicfuncs: Handle empty environment variables when using $(env)

When using the $(env) template function, if the environment variable is
empty or non-existent, don't try to add a NULL string to the result.
This fixes a Glib warning, which, under some cases, would turn into a
crash. (Fixes BugZilla#277)

Reported-by: Nick Alcock <nix@esperi.org.uk>
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>