]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/string/strlcpy.c
Inital import
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / string / strlcpy.c
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 #else
13 # define Wstrlcpy strlcpy
14 #endif
15
16 /* OpenBSD function:
17  * Copy at most n-1 chars from src to dst and nul-terminate dst.
18  * Returns strlen(src), so truncation occurred if the return value is >= n. */
19
20 #ifdef WANT_WIDE
21 size_t Wstrlcpy(register Wchar *__restrict dst,
22                                   register const Wchar *__restrict src,
23                                   size_t n) attribute_hidden;
24 #endif
25 size_t Wstrlcpy(register Wchar *__restrict dst,
26                                   register const Wchar *__restrict src,
27                                   size_t n)
28 {
29         const Wchar *src0 = src;
30         Wchar dummy[1];
31
32         if (!n) {
33                 dst = dummy;
34         } else {
35                 --n;
36         }
37
38         while ((*dst = *src) != 0) {
39                 if (n) {
40                         --n;
41                         ++dst;
42                 }
43                 ++src;
44         }
45
46         return src - src0;
47 }
48 #ifdef WANT_WIDE
49
50 #ifndef __UCLIBC_HAS_LOCALE__
51 strong_alias(__wcslcpy,wcsxfrm)
52 libc_hidden_def(wcsxfrm)
53 #endif
54
55 #else
56
57 libc_hidden_def(strlcpy)
58 #ifndef __UCLIBC_HAS_LOCALE__
59 strong_alias(strlcpy,strxfrm)
60 libc_hidden_def(strxfrm)
61 #endif
62
63 #endif