2 ms·
strlcpy() isn't standard. You have to provide your own implementation if you want your code to be portable.
by pix64 6y ago
strlcpy() isn't standard. You have to provide your own implementation if you want your code to be portable.
- cestith 6y agoThis is something git does. That's why they prefer it - it's available to git everywhere.
- schlupa 6y agoIt's 4 lines of code to implement it. So even if it is not available on a platform (glibc mmmh because of Dreppers stubborness), it's no problem. size_t strlcpy(char *dst, const char *src, size_t dstsize) { size_t len = strlen(src); if(dstsize) *((char*)mempcpy(dst, src, min(len, dstsize-1))) = 0; return len; }
- schlupa 6y agoand *((char*)mempcpy(dst, src, min(len, dstsize-1))) = 0; can be replace by ((char*)memcpy(dst, src, min(len, dstsize-1))[min(len, dstsize-1)] = 0; if you don't have mempcpy