1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <stdint.h>
17 #include <dlfcn.h>
18 #include <stdio.h>
19
20
21 int g_strcpyTime = 100;
22 static void *g_handle = NULL;
23
GetHandle(void)24 static void GetHandle(void)
25 {
26 if (g_handle != NULL) {
27 return;
28 }
29 g_handle = dlopen("libsec_shared.z.so", RTLD_LAZY);
30 }
31
strcpy_s(char * strDest,size_t destMax,const char * strSrc)32 int strcpy_s(char *strDest, size_t destMax, const char *strSrc)
33 {
34 GetHandle();
35 if (g_handle == NULL) {
36 printf("dlopen failed\n");
37 }
38 if (g_strcpyTime == 0) {
39 g_strcpyTime++;
40 return -1;
41 }
42
43 static int (*func)(char *strDest, size_t destMax, const char *strSrc) = NULL;
44 if (func == NULL) {
45 func = (int (*)(char *strDest, size_t destMax, const char *strSrc))dlsym(g_handle, "strcpy_s");
46 }
47 if (func == NULL) {
48 printf("dlsym strcpy_s failed\n");
49 return -1;
50 }
51
52 return func(strDest, destMax, strSrc);
53 }