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 */
26int 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 */
38int 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/* The V100R001C01 version num is 0x5 (High 8 bits) */
46#define SECUREC_C_VERSION     0x500U
47#define SECUREC_SPC_VERSION   0x10U
48#define SECUREC_VERSION_STR   "1.1.16"
49
50/*
51 * Get version string and version number.
52 * The rules for version number are as follows:
53 * 1) SPC verNumber<->verStr like:
54 * 0x201<->C01
55 * 0x202<->C01SPC001   Redefine numbers after this version
56 * 0x502<->C01SPC002
57 * 0x503<->C01SPC003
58 * ...
59 * 0X50a<->SPC010
60 * 0X50b<->SPC011
61 * ...
62 * 0x700<->C02
63 * 0x701<->C01SPC001
64 * 0x702<->C02SPC002
65 * ...
66 * 2) CP verNumber<->verStr like:
67 * 0X601<->CP0001
68 * 0X602<->CP0002
69 * ...
70 */
71const char *GetHwSecureCVersion(unsigned short *verNumber)
72{
73    if (verNumber != NULL) {
74        *verNumber = (unsigned short)(SECUREC_C_VERSION | SECUREC_SPC_VERSION);
75    }
76    return SECUREC_VERSION_STR;
77}
78#if SECUREC_EXPORT_KERNEL_SYMBOL
79EXPORT_SYMBOL(GetHwSecureCVersion);
80#endif
81
82