📄 glib-string-utility-functions.html
字号:
<a class="link" href="glib-Basic-Types.html#gsize">gsize</a> dest_size);</pre><p>Portability wrapper that calls <code class="function">strlcpy()</code> on systems which have it, and emulates<code class="function">strlcpy()</code> otherwise. Copies <em class="parameter"><code>src</code></em> to <em class="parameter"><code>dest</code></em>; <em class="parameter"><code>dest</code></em> is guaranteed to benul-terminated; <em class="parameter"><code>src</code></em> must be nul-terminated; <em class="parameter"><code>dest_size</code></em> is the buffer size, notthe number of chars to copy. Caveat: <code class="function">strlcpy()</code> is supposedly more secure than<code class="function">strcpy()</code> or <code class="function">strncpy()</code>, but if you really want to avoid screwups, <a class="link" href="glib-String-Utility-Functions.html#g-strdup"><code class="function">g_strdup()</code></a> isan even better idea.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>dest</code></em> :</span></p></td><td>destination buffer</td></tr><tr><td><p><span class="term"><em class="parameter"><code>src</code></em> :</span></p></td><td>source buffer</td></tr><tr><td><p><span class="term"><em class="parameter"><code>dest_size</code></em> :</span></p></td><td>length of <em class="parameter"><code>dest</code></em> in bytes</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td>length of <em class="parameter"><code>src</code></em></td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2966466"></a><h3><a name="g-strlcat"></a>g_strlcat ()</h3><a class="indexterm" name="id2966479"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gsize">gsize</a> g_strlcat (<a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *dest, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *src, <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> dest_size);</pre><p>Portability wrapper that calls <code class="function">strlcat()</code> on systems which have it, and emulates it otherwise. Appends nul-terminated <em class="parameter"><code>src</code></em> string to <em class="parameter"><code>dest</code></em>, guaranteeingnul-termination for <em class="parameter"><code>dest</code></em>. The total size of <em class="parameter"><code>dest</code></em> won't exceed<em class="parameter"><code>dest_size</code></em>. Caveat: this is supposedly a more secure alternative to <code class="function">strcat()</code> or<code class="function">strncat()</code>, but for real security <a class="link" href="glib-String-Utility-Functions.html#g-strconcat"><code class="function">g_strconcat()</code></a> is harder to mess up.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>dest</code></em> :</span></p></td><td>destination buffer, already containing one nul-terminated string</td></tr><tr><td><p><span class="term"><em class="parameter"><code>src</code></em> :</span></p></td><td>source buffer</td></tr><tr><td><p><span class="term"><em class="parameter"><code>dest_size</code></em> :</span></p></td><td>length of <em class="parameter"><code>dest</code></em> buffer in bytes (not length of existing string inside <em class="parameter"><code>dest</code></em>)</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td>length of <em class="parameter"><code>src</code></em> plus initial length of string in <em class="parameter"><code>dest</code></em></td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2966683"></a><h3><a name="g-strdup-printf"></a>g_strdup_printf ()</h3><a class="indexterm" name="id2966696"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* g_strdup_printf (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *format, ...);</pre><p>Similar to the standard C <code class="function">sprintf()</code> functionbut safer, since it calculates the maximum space required and allocatesmemory to hold the result.The returned string should be freed when no longer needed.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>format</code></em> :</span></p></td><td>a standard <code class="function">printf()</code> format string, but notice <a class="link" href="glib-String-Utility-Functions.html#string-precision">string precision pitfalls</a>.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>...</code></em> :</span></p></td><td>the parameters to insert into the format string.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td>a newly-allocated string holding the result.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2966803"></a><h3><a name="g-strdup-vprintf"></a>g_strdup_vprintf ()</h3><a class="indexterm" name="id2966815"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* g_strdup_vprintf (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *format, va_list args);</pre><p>Similar to the standard C <code class="function">vsprintf()</code> functionbut safer, since it calculates the maximum space required and allocatesmemory to hold the result.The returned string should be freed when no longer needed.</p><p>See also <a class="link" href="glib-String-Utility-Functions.html#g-vasprintf"><code class="function">g_vasprintf()</code></a>, which offers the same functionality, but additionallyreturns the length of the allocated string. </p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>format</code></em> :</span></p></td><td>a standard <code class="function">printf()</code> format string, but notice <a class="link" href="glib-String-Utility-Functions.html#string-precision">string precision pitfalls</a>.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>args</code></em> :</span></p></td><td>the list of parameters to insert into the format string.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td>a newly-allocated string holding the result.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2966944"></a><h3><a name="g-printf"></a>g_printf ()</h3><a class="indexterm" name="id2966958"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gint">gint</a> g_printf (<a class="link" href="glib-Basic-Types.html#gchar">gchar</a> const *format, ...);</pre><p>An implementation of the standard <code class="function">printf()</code> function which supports positional parameters, as specified in the Single Unix Specification.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>format</code></em> :</span></p></td><td> a standard <code class="function">printf()</code> format string, but notice <a class="link" href="glib-String-Utility-Functions.html#string-precision">string precision pitfalls</a>.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>...</code></em> :</span></p></td><td> the arguments to insert in the output.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> the number of bytes printed.</td></tr></tbody></table></div><p class="since">Since 2.2</p></div><hr><div class="refsect2" lang="en"><a name="id2967071"></a><h3><a name="g-vprintf"></a>g_vprintf ()</h3><a class="indexterm" name="id2967086"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gint">gint</a> g_vprintf (<a class="link" href="glib-Basic-Types.html#gchar">gchar</a> const *format, va_list args);</pre><p>An implementation of the standard <code class="function">vprintf()</code> function which supports positional parameters, as specified in the Single Unix Specification.</p><p></p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -