* Copy string src to buffer dst of size dsize. At most dsize-1 * chars will be copied. Always NUL terminates (unless dsize == 0). */
| 29 | * chars will be copied. Always NUL terminates (unless dsize == 0). |
| 30 | */ |
| 31 | void strfcpy(char* dst, const char* src, size_t dsize) |
| 32 | { |
| 33 | size_t nleft = dsize; |
| 34 | |
| 35 | /* Copy as many bytes as will fit. */ |
| 36 | if (nleft != 0) { |
| 37 | while (--nleft != 0) { |
| 38 | if ((*dst++ = *src++) == '\0') { |
| 39 | break; |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | /* Not enough room in dst, add NUL */ |
| 45 | if (nleft == 0) { |
| 46 | if (dsize != 0) { |
| 47 | *dst = '\0'; /* NUL-terminate dst */ |
| 48 | } |
| 49 | } |
| 50 | } |
no outgoing calls
no test coverage detected