4 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
7 * Sooyoung Ha <yoosah.ha@samsung.com>
8 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
32 gchar *get_simulator_path(void)
34 gchar *simulator_path = NULL;
38 simulator_path = (char *)malloc( 512);
39 if(simulator_path == NULL){
42 memset(simulator_path, 0, 512);
44 length = readlink("/proc/self/exe", simulator_path, 512);
45 simulator_path[length] = '\0';
47 gchar simulator_org_path[512] = {0, };
48 GetModuleFileName(NULL, simulator_org_path, 512);
49 simulator_path = change_path_to_slash(simulator_org_path);
52 /* exception precess */
59 fprintf(stderr, "Path too long. Truncated.\n");
63 return simulator_path;
66 gchar *get_bin_path(void)
68 gchar *simulator_path = NULL;
69 simulator_path = get_simulator_path();
71 gchar *bin_path = NULL;
72 bin_path = g_path_get_dirname(simulator_path);
75 g_free(simulator_path);
82 gchar *simulator_path = NULL;
83 simulator_path = get_simulator_path();
86 path = g_path_get_dirname(simulator_path);
89 g_free(simulator_path);
94 gchar *get_skin_path(void)
102 gchar *skin_path = NULL;
103 skin_path = (char *)malloc( 512);
104 if(skin_path == NULL){
107 memset(skin_path, 0, 512);
108 strncpy(skin_path, path, 512);
110 sprintf(skin_path, "%s%s", path, "/skins");
117 gchar *get_data_path(void)
125 gchar *data_path = NULL;
126 data_path = (char *)malloc( 512);
127 if(data_path == NULL){
130 memset(data_path, 0, 512);
131 strncpy(data_path, path, 512);
133 sprintf(data_path, "%s%s", path, "/data");
140 gchar *get_kernel_path(void)
143 path = get_data_path();
148 gchar *kernel_path = NULL;
149 kernel_path = (char *)malloc( 512);
150 if(kernel_path == NULL){
154 memset(kernel_path, 0, 512);
155 strncpy(kernel_path, path, 512);
157 sprintf(kernel_path, "%s%s", path, "/kernel-img");
166 * @brief change_path_to_slash (\, \\ -> /)
167 * @param org path to change (C:\\test\\test\\test)
168 * @return changed path (C:/test/test/test)
171 gchar *change_path_to_slash(gchar *org_path)
173 if (!org_path || strlen(org_path) < 1)
177 length = strlen(org_path);
179 gchar *changed_path = NULL;
180 changed_path = (char *)malloc( 512);
181 memset(changed_path, 0, 512);
183 sprintf(changed_path, "%s", org_path);
185 for (i = 0 ; i < length; i ++) {
186 if (org_path[i] == '\\') {
187 changed_path[i] = '/';
194 gchar *get_conf_path(void)
196 gchar *conf_path = NULL;
199 conf_path = (char *)malloc( 512);
200 if(conf_path == NULL){
203 memset(conf_path, 0, 512);
212 strncpy(conf_path, path, 512);
214 sprintf(conf_path, "%s%s", path, "/conf");
218 TCHAR APP_PATH[MAX_PATH];
219 gchar org_conf_path[128] = {0, };
221 SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, APP_PATH);
222 sprintf(org_conf_path, "%s%s", APP_PATH, PID_DIR);
223 conf_path = change_path_to_slash(org_conf_path);
232 * @brief get_simulator conf file path
234 gchar *get_simulator_conf_filepath(void)
236 gchar *simulator_conf_filepath = NULL;
237 simulator_conf_filepath = (char *)malloc( 512);
238 memset(simulator_conf_filepath, 0, 512);
241 if (!strncmp(g_get_user_name(), "root", 4))
242 sprintf(simulator_conf_filepath, "/root%ssimulator.conf", PID_DIR);
244 sprintf(simulator_conf_filepath, "/home/%s%ssimulator.conf", g_get_user_name(), PID_DIR);
246 gchar *conf_path = get_conf_path();
247 sprintf(simulator_conf_filepath, "%ssimulator.conf", conf_path);
253 return simulator_conf_filepath;
258 * @brief get_default target conf file path
260 gchar *get_platform_conf_filepath(void)
262 gchar *simultor_path = NULL;
263 simultor_path = get_path();
265 gchar *default_conf_filepath = NULL;
266 default_conf_filepath = (char *)malloc( 512);
267 memset(default_conf_filepath, 0, 512);
269 sprintf(default_conf_filepath, "%s/.default_target.conf", simultor_path);
272 g_free(simultor_path);
274 return default_conf_filepath;
279 @brief search target name in directory name
280 @param directory_name: target directory name of scratchbox
283 char *search_target_name(char *directory_name)
285 int directory_len = 0;
287 char *found_name = NULL;
289 directory_len = strlen(directory_name);
291 /* search target name pointer */
292 for (search_i = directory_len; search_i > 0; search_i--) {
293 if (directory_name[search_i-1] == '/') {
294 found_name = directory_name + search_i;
302 char *find_exec_path(char *line) {
304 uintptr_t find_loc = 0;
306 char *start_p = NULL;
307 static char exec_path[512] = "";
312 // ld path -> factoryfs of bash_profile
313 //ldpath = strstr(line, "LD_LIBRARY_PATH");
316 ldpath = strstr(line, "FACTORY_FS");
317 if (ldpath == NULL) {
321 find_loc = (uintptr_t)ldpath - (uintptr_t)line;
323 for (loc = 0; loc < find_loc;loc++) {
324 if (line[loc] == '#') {
329 for (len = 0; len < strlen(ldpath);len++) {
331 if (ldpath[len] == '#') {
334 if (ldpath[len] == '=') {
335 start_p = &ldpath[len];
347 end_p = strstr(start_p, "/lib");
352 strncpy(exec_path, start_p+1, (int)end_p - (int)start_p -1);
355 strncpy(exec_path, start_p+1, strlen(start_p+1)-1);
361 char *find_exec_path_by_bash_profile(char *target_path)
364 char pathname[BUFSIZ] = "";
368 sprintf(pathname, "%s/root/.bash_profile", target_path);
370 if ((fp = fopen(pathname, "r")) == NULL) {
374 while (fgets(line, BUFSIZ, fp)) {
375 exec_path = find_exec_path(line);
377 if (exec_path != NULL) {
388 char *find_ld_path(char *line) {
391 uintptr_t find_loc = 0;
394 ldpath = strstr(line, "LD_LIBRARY_PATH");
395 if (ldpath == NULL) {
399 find_loc = (uintptr_t)ldpath - (uintptr_t)line;
401 for (loc = 0; loc < find_loc;loc++) {
402 if (line[loc] == '#') {
407 for (len = 0; len < strlen(ldpath);len++) {
408 if (ldpath[len] == '#') {
411 if (ldpath[len] == '=') {
416 return &ldpath[len] + 1;
419 char *find_ld_path_by_bash_profile(char *target_path)
422 char pathname[BUFSIZ] = "";
423 static char line[BUFSIZ] = "";
426 sprintf(pathname, "%s/root/.bash_profile", target_path);
428 if ((fp = fopen(pathname, "r")) == NULL) {
432 while (fgets(line, BUFSIZ, fp)) {
433 exec_path = find_ld_path(line);
435 if (exec_path != NULL) {
436 if (exec_path[strlen(exec_path) - 1] == '\n')
437 exec_path[strlen(exec_path) - 1] = '\0';