summaryrefslogtreecommitdiff
path: root/src/evalfunc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/evalfunc.c')
-rw-r--r--src/evalfunc.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 65279a52f..4b0995185 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -8057,22 +8057,32 @@ f_mkdir(typval_T *argvars, typval_T *rettv)
dir = get_tv_string_buf(&argvars[0], buf);
if (*dir == NUL)
- rettv->vval.v_number = FAIL;
- else
- {
- if (*gettail(dir) == NUL)
- /* remove trailing slashes */
- *gettail_sep(dir) = NUL;
+ return;
- if (argvars[1].v_type != VAR_UNKNOWN)
+ if (*gettail(dir) == NUL)
+ /* remove trailing slashes */
+ *gettail_sep(dir) = NUL;
+
+ if (argvars[1].v_type != VAR_UNKNOWN)
+ {
+ if (argvars[2].v_type != VAR_UNKNOWN)
{
- if (argvars[2].v_type != VAR_UNKNOWN)
- prot = (int)get_tv_number_chk(&argvars[2], NULL);
- if (prot != -1 && STRCMP(get_tv_string(&argvars[1]), "p") == 0)
- mkdir_recurse(dir, prot);
+ prot = (int)get_tv_number_chk(&argvars[2], NULL);
+ if (prot == -1)
+ return;
+ }
+ if (STRCMP(get_tv_string(&argvars[1]), "p") == 0)
+ {
+ if (mch_isdir(dir))
+ {
+ /* With the "p" flag it's OK if the dir already exists. */
+ rettv->vval.v_number = OK;
+ return;
+ }
+ mkdir_recurse(dir, prot);
}
- rettv->vval.v_number = prot == -1 ? FAIL : vim_mkdir_emsg(dir, prot);
}
+ rettv->vval.v_number = vim_mkdir_emsg(dir, prot);
}
#endif