* Get the value of an environment variable.
* "arg" is pointing to the '$'. It is advanced to after the name.
* If the environment variable was not set, silently assume it is empty.
- * Always return OK.
+ * Return FAIL if the name is invalid.
*/
static int
get_env_tv(arg, rettv, evaluate)
len = get_env_len(arg);
if (evaluate)
{
- if (len != 0)
+ if (len == 0)
+ return FAIL; /* can't be an environment variable */
+
+ cc = name[len];
+ name[len] = NUL;
+ /* first try vim_getenv(), fast for normal environment vars */
+ string = vim_getenv(name, &mustfree);
+ if (string != NULL && *string != NUL)
{
- cc = name[len];
- name[len] = NUL;
- /* first try vim_getenv(), fast for normal environment vars */
- string = vim_getenv(name, &mustfree);
- if (string != NULL && *string != NUL)
- {
- if (!mustfree)
- string = vim_strsave(string);
- }
- else
- {
- if (mustfree)
- vim_free(string);
+ if (!mustfree)
+ string = vim_strsave(string);
+ }
+ else
+ {
+ if (mustfree)
+ vim_free(string);
- /* next try expanding things like $VIM and ${HOME} */
- string = expand_env_save(name - 1);
- if (string != NULL && *string == '$')
- {
- vim_free(string);
- string = NULL;
- }
+ /* next try expanding things like $VIM and ${HOME} */
+ string = expand_env_save(name - 1);
+ if (string != NULL && *string == '$')
+ {
+ vim_free(string);
+ string = NULL;
}
- name[len] = cc;
}
+ name[len] = cc;
+
rettv->v_type = VAR_STRING;
rettv->vval.v_string = string;
}
:" script-local function used in Funcref must exist.
:so test_eval_func.vim
:"
+:" Using $ instead of '$' must give an error
+:try
+: call append($, 'foobar')
+:catch
+:$put =v:exception
+:endtry
+:"
:/^start:/+1,$wq! test.out
:" vim: et ts=4 isk-=\: fmr=???,???
:call getchar()