> In the new code, we have a different failure case: the code doesn't handle the case of a Pascal string, because it tries to take STRLEN(str) even if maxlen is specified.

Yes, that is the reason, why I suggested to use agin the old version of `len`.

> xstpncpy actually just calls memcpy anyway, if you already know the length you want. If the string is not NUL-terminated or maxlen < strlen, it acts exactly like mempcpy(dst, src, maxlen). If the string IS NUL-terminated and strlen < maxlen, it acts like memset(dst + strlen(src), 0, maxlen - strlen(src)); return mempcpy(dst, src, strlen(src));, unnecesarily filling up the string with '\0'.

If we agree that `maxlen <= buflen(str)` then yes, `memcpy` would be enough. Otherwise `xstpncpy` reproduces the old behaviour (and in some cases (`must_append == TRUE && maxlen > buflen(src)`) appends some additional `NUL` bytes).

> How about we document this better and go for the original vim code, and keep memcpy?

Documenting the intended use of `maxlen` would be nice. Does that mean we assume now that `maxlen <= buflen(str)`?