@aktau sorry, I don't understand about what trade-off you are talking. As I can see we can remove ```cwd``` entirely and avoid unnecessary stack(heap in original version) allocation and use only ```rettv->vval.v_string``` to avoid copying. Like this:
```c
static void f_getcwd(typval_T *argvars, typval_T *rettv)
{
  rettv->v_type = VAR_STRING;
  rettv->vval.v_string = xmalloc(MAXPATHL);
  if (os_dirname(rettv->vval.v_string, MAXPATHL) != FAIL) {
    free(rettv->vval.v_string);
    rettv->vval.v_string = NULL;
  }

#ifdef BACKSLASH_IN_FILENAME
  if (rettv->vval.v_string) {
    slash_adjust(rettv->vval.v_string);
  }
#endif
}
```
Is something wrong with that approach?