fix prevent violation
[framework/system/dynamic-analysis-probe.git] / helper / dahelper.c
1 /*\r
2  *  DA probe\r
3  *\r
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
5  *\r
6  * Contact:\r
7  *\r
8  * Jaewon Lim <jaewon81.lim@samsung.com>\r
9  * Woojin Jung <woojin2.jung@samsung.com>\r
10  * Juyoung Kim <j0.kim@samsung.com>\r
11  *\r
12  * This library is free software; you can redistribute it and/or modify it under\r
13  * the terms of the GNU Lesser General Public License as published by the\r
14  * Free Software Foundation; either version 2.1 of the License, or (at your option)\r
15  * any later version.\r
16  *\r
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY\r
18  * WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
19  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public\r
20  * License for more details.\r
21  *\r
22  * You should have received a copy of the GNU Lesser General Public License\r
23  * along with this library; if not, write to the Free Software Foundation, Inc., 51\r
24  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\r
25  *\r
26  * Contributors:\r
27  * - S-Core Co., Ltd\r
28  *\r
29  */\r
30 \r
31 #include <wchar.h>                      // for wcslen\r
32 #include <unistd.h>                     // for unlink\r
33 #include <sys/types.h>\r
34 #include <dirent.h>                     // for opendir, readdir\r
35 \r
36 #include "dahelper.h"\r
37 \r
38 char *lib_string[NUM_ORIGINAL_LIBRARY] = {"libc.so.6", "libpthread.so.0", \r
39         "libelementary.so", "libosp-uifw.so", "libosp-appfw.so", "libosp-web.so", \r
40         "libecore_input_evas.so.1", "libdaemon.so.0", "libcapi-appfw-application.so.0"};\r
41 void *lib_handle[NUM_ORIGINAL_LIBRARY];\r
42 \r
43 /* trace info global variable */\r
44 __traceInfo gTraceInfo =\r
45 {\r
46         {\r
47                 1,                                                      // int eventIndex\r
48                 PTHREAD_MUTEX_INITIALIZER       // pthread_mutex_t eventMutex\r
49         },              // __indexInfo\r
50         {\r
51                 -1,                                                     // int daemonSock\r
52                 PTHREAD_MUTEX_INITIALIZER       // ptrhread_mutex_t sockMutex\r
53         },              // __socketInfo\r
54         {\r
55                 {0, },                                          // char appName[128]\r
56                 0                                                       // unsigned int startTime\r
57         },              // __appInfo\r
58         {\r
59                 0,                                                      // int state\r
60                 PTHREAD_MUTEX_INITIALIZER       // ptrhread_mutex_t ssMutex\r
61         },              // __screenshotInfo\r
62         {\r
63                 NULL,                                           // map_start\r
64                 NULL                                            // map_end\r
65         },              // __mapInfo\r
66         -1,                                                             // int stateTouch\r
67         0,                                                              // int init_complete\r
68         0,                                                              // int custom_chart_callback_count\r
69         0                                                               // unsigned long optionflag\r
70 };\r
71 \r
72 __thread unsigned long  gSTrace = 0;\r
73 \r
74 \r
75 void WcharToChar(char* pstrDest, const wchar_t* pwstrSrc)\r
76 {\r
77         int nLen=(int)wcslen(pwstrSrc);\r
78         wcstombs(pstrDest, pwstrSrc, nLen+1);\r
79 }\r
80 \r
81 // return 0 if succeed\r
82 // return -1 if error occured\r
83 int remove_indir(const char *dirname)\r
84 {\r
85         DIR *dir;\r
86         struct dirent *entry;\r
87         char path[MAX_PATH_LENGTH];\r
88 \r
89         dir = opendir(dirname);\r
90         if(dir == NULL)\r
91         {\r
92                 return -1;\r
93         }\r
94 \r
95         while((entry = readdir(dir)) != NULL)\r
96         {\r
97                 if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))\r
98                 {\r
99                         snprintf(path, (size_t) MAX_PATH_LENGTH, "%s/%s", dirname, entry->d_name);\r
100                         if (entry->d_type != DT_DIR)    // file\r
101                         {\r
102                                 unlink(path);\r
103                         }\r
104                         else { }        // directory\r
105                 }\r
106         }\r
107         closedir(dir);\r
108 \r
109         return 0;\r
110 }\r
111 \r
112 \r