top | item 26349746 (no title) pix64 | 5 years ago strlcpy() isn't standard. You have to provide your own implementation if you want your code to be portable. discuss order hn newest cestith|5 years ago This is something git does. That's why they prefer it - it's available to git everywhere. schlupa|5 years ago It'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|5 years ago and *((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
cestith|5 years ago This is something git does. That's why they prefer it - it's available to git everywhere. schlupa|5 years ago It'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|5 years ago and *((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
schlupa|5 years ago It'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|5 years ago and *((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
cestith|5 years ago
schlupa|5 years ago
schlupa|5 years ago