||[May. 10th, 2000|10:26 pm]
strncpy() function....I've just spent an hour debugging part of our operating system project and finally now just traced it down to my misunderstanding of the |
The strcpy() function copies the string pointed to be src (including the terminating `\0' character) to the array pointed to by dest. The strings may not overlap, and the destination string dest must be large enough to receive the copy.Why does it null-pad it? I don't see that as being particularly beneficial. I don't mind it... and now that I understand that n should be the MIN(src, dst) it's all good... but it seems unnecessary. Evan? Scott?
The strncpy() function is similar, except that not more than n bytes of src are copied. Thus, if there is no null byte among the first n bytes of src, the result wil not be null-terminated.
In the case where the length of src is less than that of n, the remainder of dest will be padded with nulls.