TE
TechEcho
Home
24h Top
Newest
Best
Ask
Show
Jobs
English
GitHub
Twitter
Home
Strncpy like a boss
4 points
by
xfactor973
over 10 years ago
2 comments
tlb
over 10 years ago
Collapse
Please use strlcpy [1] instead.<p>[1] <a href="http://www.unix.com/man-page/freebsd/3/strlcpy/" rel="nofollow">http://www.unix.com/man-page/freebsd/3/strlcpy/</a>
评论 #8311464 未加载
nly
over 10 years ago
Putting aside the fact that using sizeof is risky in itself, i'd argue the default form should be<p><pre><code> strncpy (buffer, "abcd", sizeof(buffer)); assert (!buffer[sizeof(buffer) - 1]);</code></pre>