Re: Usage of strncpy in the kernel

Mouse <[email protected]>
Newsgroups gmane.os.netbsd.devel.kernel
Message-ID <[email protected]>
> strncpy() has the advantage of working nicely and predictably
> regardless of whether the known buffer's length is that of the source
> or that of the destination.  I.e. one can use it to copy a known
> number of possibly (or definitely) unterminated chars from an array
> of a given length into an array of the same or larger size;

Huh?

If I have an array [N1], NUL-terminated unless length is N1, and I want
to copy that quasi-string into an array [N2], with truncation if src
length > N2 and NUL-termination if src length < N2...I can't see how
strncpy can do that.  I don't think it can do that even when it's known
N1<N2.  (Neither can any of the other str* functions I'm familiar with.
I don't think any single call can unless it takes two size arguments.)

/~\ The ASCII				  Mouse
\ / Ribbon Campaign
 X  Against HTML		[email protected]
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.