Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two strategies for safe string manipulation. The Linux / <a href="http://www.gnu.org/s/libc/">glibc</a> maintainers refuse to add safe functions, arguing that you should keep the length of your strings at hand and use <code>memcpy</code>. </p> <p>On the other hand, Mac OSX includes <code>strlcpy</code> and <code>strlcat</code> from BSD. <a href="http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/snprintf.3.html"><code>snprintf</code></a> and <a href="http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/asprintf.3.html"><code>asprintf</code></a> can be used on both platforms to much the same effect:</p> <pre><code>size_t strlcpy(char *d, char const *s, size_t n) { return snprintf(d, n, "%s", s); } size_t strlcat(char *d, char const *s, size_t n) { return snprintf(d, n, "%s%s", d, s); } </code></pre> <p>You could also consider using the BSD implementation <a href="http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/string/">found here</a>. If your code will be compiled on multiple platforms, you can test for the presence of glibc using <a href="http://predef.sourceforge.net/prelib.html">pre-defined library macros</a>:</p> <pre><code>#if defined __GNU_LIBRARY__ || defined __GLIBC__ size_t strlcpy(char *, char const *, size_t); size_t strlcat(char *, char const *, size_t); #endif </code></pre> <p>Conversion between character encodings is most easily handled using the <a href="http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/iconv.3.html"><code>iconv</code></a> interface.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload