• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2014-2021. All rights reserved.
3  * Licensed under Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *          http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
8  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
9  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  * Description: Provides internal functions used by this library, such as memory
12  *              copy and memory move. Besides, include some helper function for
13  *              printf family API, such as SecVsnprintfImpl
14  * Create: 2014-02-25
15  */
16 
17 /* Avoid duplicate header files,not include securecutil.h */
18 #include "securecutil.h"
19 
20 #if defined(ANDROID) && !defined(SECUREC_CLOSE_ANDROID_HANDLE) && (SECUREC_HAVE_WCTOMB || SECUREC_HAVE_MBTOWC)
21 #include <wchar.h>
22 #if SECUREC_HAVE_WCTOMB
23 /*
24  * Convert wide characters to narrow multi-bytes
25  */
wctomb(char * s,wchar_t wc)26 int wctomb(char *s, wchar_t wc)
27 {
28     return (int)wcrtomb(s, wc, NULL);
29 }
30 #endif
31 
32 #if SECUREC_HAVE_MBTOWC
33 /*
34  * Converting narrow multi-byte characters to wide characters
35  * mbrtowc returns -1 or -2 upon failure, unlike mbtowc, which only returns -1
36  * When the return value is less than zero, we treat it as a failure
37  */
mbtowc(wchar_t * pwc,const char * s,size_t n)38 int mbtowc(wchar_t *pwc, const char *s, size_t n)
39 {
40     return (int)mbrtowc(pwc, s, n, NULL);
41 }
42 #endif
43 #endif
44 
45