1 /*
2  * Copyright (C) 2002     Manuel Novoa III
3  * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
4  *
5  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6  */
7 
8 #include "_string.h"
9 
10 #ifdef WANT_WIDE
11 # define Wstrlcpy __wcslcpy
12 # define Wstrxfrm wcsxfrm
13 #else
14 # define Wstrlcpy strlcpy
15 # define Wstrxfrm strxfrm
16 #endif
17 
18 /* OpenBSD function:
19  * Copy at most n-1 chars from src to dst and nul-terminate dst.
20  * Returns strlen(src), so truncation occurred if the return value is >= n. */
21 
Wstrlcpy(register Wchar * __restrict dst,register const Wchar * __restrict src,size_t n)22 size_t Wstrlcpy(register Wchar *__restrict dst,
23 				  register const Wchar *__restrict src,
24 				  size_t n)
25 {
26 	const Wchar *src0 = src;
27 	Wchar dummy[1];
28 
29 	if (!n) {
30 		dst = dummy;
31 	} else {
32 		--n;
33 	}
34 
35 	while ((*dst = *src) != 0) {
36 		if (n) {
37 			--n;
38 			++dst;
39 		}
40 		++src;
41 	}
42 
43 	return src - src0;
44 }
45 #ifndef WANT_WIDE
46 libc_hidden_def(strlcpy)
47 #endif
48 
49 #ifndef __UCLIBC_HAS_LOCALE__
50 strong_alias(Wstrlcpy,Wstrxfrm)
51 #endif
52