* Copy src to dst, truncating or null-padding to always copy n bytes. * Return dst. */
| 42 | * Return dst. |
| 43 | */ |
| 44 | char * |
| 45 | strncpy(char * __restrict dst, const char * __restrict src, size_t n) |
| 46 | { |
| 47 | if (n != 0) { |
| 48 | char *d = dst; |
| 49 | const char *s = src; |
| 50 | |
| 51 | do { |
| 52 | if ((*d++ = *s++) == '\0') { |
| 53 | /* NUL pad the remaining n-1 bytes */ |
| 54 | while (--n != 0) |
| 55 | *d++ = '\0'; |
| 56 | break; |
| 57 | } |
| 58 | } while (--n != 0); |
| 59 | } |
| 60 | return (dst); |
| 61 | } |
no outgoing calls