| 159 | */ |
| 160 | |
| 161 | size_t dmStrlCpy(char *dst, const char *src, size_t siz) |
| 162 | { |
| 163 | char *d = dst; |
| 164 | const char *s = src; |
| 165 | size_t n = siz; |
| 166 | |
| 167 | /* Copy as many bytes as will fit */ |
| 168 | if (n != 0 && --n != 0) { |
| 169 | do { |
| 170 | if ((*d++ = *s++) == 0) |
| 171 | break; |
| 172 | } while (--n != 0); |
| 173 | } |
| 174 | |
| 175 | /* Not enough room in dst, add NUL and traverse rest of src */ |
| 176 | if (n == 0) { |
| 177 | if (siz != 0) |
| 178 | *d = '\0'; /* NUL-terminate dst */ |
| 179 | while (*s++) |
| 180 | ; |
| 181 | } |
| 182 | |
| 183 | return(s - src - 1); /* count does not include NUL */ |
| 184 | } |
| 185 | |
| 186 | #include <string.h> |
| 187 |
no outgoing calls