]> pd.if.org Git - pdclib/blob - functions/wchar/wcsncpy.c
PDCLib includes with quotes, not <>.
[pdclib] / functions / wchar / wcsncpy.c
1 /* wchar_t * wcsncpy( wchar_t *, const wchar_t * , size_t );\r
2 \r
3    This file is part of the Public Domain C Library (PDCLib).\r
4    Permission is granted to use, modify, and / or redistribute at will.\r
5 */\r
6 \r
7 #include <wchar.h>\r
8 \r
9 #ifndef REGTEST\r
10 \r
11 wchar_t *wcsncpy( wchar_t * _PDCLIB_restrict s1, \r
12                   const wchar_t * _PDCLIB_restrict s2,\r
13                   size_t n )\r
14 {\r
15     wchar_t * rc = s1;\r
16     while ( ( n > 0 ) && ( *s1++ = *s2++ ) )\r
17     {\r
18         /* Cannot do "n--" in the conditional as size_t is unsigned and we have\r
19            to check it again for >0 in the next loop below, so we must not risk\r
20            underflow.\r
21         */\r
22         --n;\r
23     }\r
24     /* Checking against 1 as we missed the last --n in the loop above. */\r
25     while ( n-- > 1 )\r
26     {\r
27         *s1++ = '\0';\r
28     }\r
29     return rc;\r
30 }\r
31 \r
32 \r
33 #endif\r
34 \r
35 #ifdef TEST\r
36 #include "_PDCLIB_test.h"\r
37 \r
38 int main( void )\r
39 {\r
40     return TEST_RESULTS;\r
41 }\r
42 \r
43 #endif\r