tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Usage of strncpy in the kernel



> 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		mouse%rodents-montreal.org@localhost
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Home | Main Index | Thread Index | Old Index