diff options
author | midipix <writeonce@midipix.org> | 2017-11-11 14:26:10 -0500 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2017-11-25 11:30:32 -0500 |
commit | 24bfc0746fd5f55a983ab566381cd959b7549b3d (patch) | |
tree | 898281c3a62ecd1f955f83f62dc03d6830a13302 | |
parent | 0c84af4c4f4cb6c63487830c8e2b943d28d3221a (diff) | |
download | u16ports-24bfc0746fd5f55a983ab566381cd959b7549b3d.tar.bz2 u16ports-24bfc0746fd5f55a983ab566381cd959b7549b3d.tar.xz |
added u16_mbstowcs().
-rw-r--r-- | project/common.mk | 1 | ||||
-rw-r--r-- | src/u16_mbstowcs.c | 36 |
2 files changed, 37 insertions, 0 deletions
diff --git a/project/common.mk b/project/common.mk index 49fdcae..af8cf6b 100644 --- a/project/common.mk +++ b/project/common.mk @@ -1,6 +1,7 @@ API_SRCS = \ src/u16_mbsinit.c \ src/u16_mbrtowc.c \ + src/u16_mbstowcs.c \ INTERNAL_SRCS = \ diff --git a/src/u16_mbstowcs.c b/src/u16_mbstowcs.c new file mode 100644 index 0000000..8b84379 --- /dev/null +++ b/src/u16_mbstowcs.c @@ -0,0 +1,36 @@ +/*******************************************************************/ +/* u16ports: u16 variants of wide character string functions. */ +/* Copyright (C) 2017 Z. Gilboa */ +/* Released under the Standard MIT License; see COPYING.U16PORTS. */ +/*******************************************************************/ + +#include <wchar.h> +#include <uchar.h> +#include <u16ports/u16ports.h> + +size_t u16_mbstowcs(uint16_t * dst, const char * src, size_t len) +{ + size_t nbytes; + uint16_t * wch; + mbstate_t st = {0}; + + for (wch=dst; len; src+=nbytes) { + if ((nbytes = mbrtoc16(wch,src,4,&st)) == (size_t)-1) { + return (size_t)(-1); + + } else if (nbytes == 0) { + return wch - dst; + + } else if (nbytes == (size_t)-3) { + nbytes = 0; + len--; + wch++; + + } else { + len--; + wch++; + } + } + + return wch - dst; +} |