summaryrefslogtreecommitdiffhomepage
path: root/src/u16_wcpncpy.c
blob: 6ee5d2de922cf146d4286e105c9fdfe6b98bcdf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*******************************************************************/
/*  u16ports: u16 variants of wide character string functions.     */
/*  Copyright (C) 2017  Z. Gilboa                                  */
/*  Released under the Standard MIT License; see COPYING.U16PORTS. */
/*******************************************************************/

#include <stdint.h>
#include <u16ports/u16ports.h>

uint16_t * u16_wcpncpy(uint16_t * dst, const uint16_t * src, size_t len)
{
	uint16_t * ret;
	uint16_t * cap;
	size_t     n;

	cap = &dst[len];

	for (n=len; n && *src; n--)
		*dst++ = *src++;

	ret = *src ? cap : &dst[len-n];

	for (; dst<cap; )
		*dst++ = 0;

	return ret;
}