c - wcscpy_s - buffer size when the pointer is not the start of the buffer? -


i'm little confused second parameter wcscpy_s , similar functions. microsoft (on wcscat_s) points out that

the second parameter total size of buffer, not remaining size

unfortunately, in code sample following remark, point start of destination buffer every time:

char buf[16]; strcpy_s(buf, 16, "start"); strcat_s(buf, 16, " end");               // correct strcat_s(buf, 16 – strlen(buf), " end"); // incorrect 

so i'm left wondering... remark apply when pointer isn't start of buffer? or should in fact specifying remaining bytes available in buffer in such cases? or somehow recognize actual starting address of buffer if pass buf+1 first parameter?

let's wanted replace basename in path using wcscpy_s, proper?

#define bufsize 11 wchar_t buf[bufsize]; wchar_t *basename; wcscpy_s(buf, bufsize, l"c:\\foo.txt"); basename = pathfindfilenamew(buf); wcscpy_s(basename, (bufsize - ((size_t)basename - (size_t)buf)), l"bar.txt");