提交 da5c7335 编写于 作者: J Ján Tomko

docs: hacking: document preferred strdup alternatives

Recommend g_str(n)dup instead of VIR_STRDUP.
Signed-off-by: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
Reviewed-by: NAndrea Bolognani <abologna@redhat.com>
上级 95f3a1fe
...@@ -1275,18 +1275,14 @@ BAD: ...@@ -1275,18 +1275,14 @@ BAD:
</p> </p>
<pre> <pre>
VIR_STRDUP(char *dst, const char *src); dst = g_strdup(src);
VIR_STRNDUP(char *dst, const char *src, size_t n); dst = g_strndup(src, n);
</pre> </pre>
<p> <p>
You should avoid using strdup or strndup directly as they do not report You should avoid using strdup or strndup directly as they do not handle
out-of-memory error, and do not allow a NULL source. Use out-of-memory errors, and do not allow a NULL source.
VIR_STRDUP or VIR_STRNDUP macros instead, which return 0 for Use <code>g_strdup</code> and <code>g_strndup</code> from GLib which
NULL source, 1 for successful copy, and -1 for allocation abort on OOM and handle NULL source by returning NULL.
failure with the error already reported. In very
specific cases, when you don't want to report the out-of-memory error, you
can use VIR_STRDUP_QUIET or VIR_STRNDUP_QUIET, but such usage is very rare
and usually considered a flaw.
</p> </p>
<h2><a id="strbuf">Variable length string buffer</a></h2> <h2><a id="strbuf">Variable length string buffer</a></h2>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册