TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Strncpy like a boss

4 pointsby xfactor973over 10 years ago

2 comments

tlbover 10 years ago
Please use strlcpy [1] instead.<p>[1] <a href="http://www.unix.com/man-page/freebsd/3/strlcpy/" rel="nofollow">http:&#x2F;&#x2F;www.unix.com&#x2F;man-page&#x2F;freebsd&#x2F;3&#x2F;strlcpy&#x2F;</a>
评论 #8311464 未加载
nlyover 10 years ago
Putting aside the fact that using sizeof is risky in itself, i&#x27;d argue the default form should be<p><pre><code> strncpy (buffer, &quot;abcd&quot;, sizeof(buffer)); assert (!buffer[sizeof(buffer) - 1]);</code></pre>