TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Strncpy like a boss

4 点作者 xfactor973超过 10 年前

2 条评论

tlb超过 10 年前
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 未加载
nly超过 10 年前
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>