Fix wcslcpy compat.

This commit is contained in:
Felicity Tarnell 2014-03-08 13:05:44 +00:00
parent 7c26144e31
commit 1758e63f6b

View file

@ -20,13 +20,14 @@
#include <sys/types.h> #include <sys/types.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <wchar.h>
#include "config.h" #include "config.h"
/* /*
* Copy src to string dst of size siz. At most siz-1 characters * Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0). * will be copied. Always NUL terminates (unless siz == 0).
* Returns strlen(src); if retval >= siz, truncation occurred. * Returns wcslen(src); if retval >= siz, truncation occurred.
*/ */
#ifndef HAVE_WCSLCPY #ifndef HAVE_WCSLCPY
size_t size_t
@ -62,8 +63,8 @@ size_t n = siz;
/* /*
* Appends src to string dst of size siz (unlike strncat, siz is the * Appends src to string dst of size siz (unlike strncat, siz is the
* full size of dst, not space left). At most siz-1 characters * full size of dst, not space left). At most siz-1 characters
* will be copied. Always NUL terminates (unless siz <= strlen(dst)). * will be copied. Always NUL terminates (unless siz <= wcslen(dst)).
* Returns strlen(src) + MIN(siz, strlen(initial dst)). * Returns wcslen(src) + MIN(siz, wcslen(initial dst)).
* If retval >= siz, truncation occurred. * If retval >= siz, truncation occurred.
*/ */
#ifndef HAVE_WCSLCAT #ifndef HAVE_WCSLCAT
@ -82,7 +83,7 @@ size_t dlen;
n = siz - dlen; n = siz - dlen;
if (n == 0) if (n == 0)
return(dlen + strlen(s)); return(dlen + wcslen(s));
while (*s != '\0') { while (*s != '\0') {
if (n != 1) { if (n != 1) {
*d++ = *s; *d++ = *s;