2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <sys/types.h>
27 #include <appcore-common.h>
31 #include <app_private.h>
32 #include <app_service_private.h>
38 #define LOG_TAG "TIZEN_N_APPLICATION"
40 static char* app_get_resource_directory()
42 static char *resource_directory = NULL;
44 if (resource_directory == NULL)
46 char *resource_directory_tmp;
49 if (app_get_package(&package) != APP_ERROR_NONE)
51 LOGE("[%s] INVALID_CONTEXT(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
55 resource_directory_tmp = calloc(1, sizeof(char) * TIZEN_PATH_MAX);
57 if (resource_directory_tmp == NULL)
59 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, APP_ERROR_OUT_OF_MEMORY);
63 snprintf(resource_directory_tmp, TIZEN_PATH_MAX, PATH_FMT_RES_DIR, package);
70 resource_directory = resource_directory_tmp;
73 return resource_directory;
76 char* app_get_resource(const char *resource, char *buffer, int size)
78 char *resource_directory;
83 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid resource", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
87 if (buffer == NULL || size <= 0)
89 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid buffer", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
93 resource_directory = app_get_resource_directory();
95 if (resource_directory == NULL)
97 LOGE("[%s] INVALID_CONTEXT(0x%08x) : failed to get the path to the resource directory", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
101 abs_path_size = strlen(resource_directory)+ strlen("/") + strlen(resource);
103 if (size <= abs_path_size)
105 LOGE("[%s] INVALID_PARAMETER(0x%08x) : the buffer is not big enough", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
109 snprintf(buffer, size, "%s/%s", resource_directory, resource);
114 char* app_get_data_directory(char *buffer, int size)
116 static char *abs_path = NULL;
118 if (buffer == NULL || size <= 0)
120 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid buffer", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
124 if (abs_path == NULL)
129 if (app_get_package(&package) != 0)
131 LOGE("[%s] INVALID_CONTEXT(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
135 abs_path_tmp = calloc(1, sizeof(char) * TIZEN_PATH_MAX);
137 if (abs_path_tmp == NULL)
139 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, APP_ERROR_OUT_OF_MEMORY);
143 snprintf(abs_path_tmp, TIZEN_PATH_MAX, PATH_FMT_DATA_DIR, package);
150 abs_path = abs_path_tmp;
153 if (abs_path == NULL)
155 LOGE("[%s] INVALID_CONTEXT(0x%08x) : failed to get the absolute path to the data directory", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
159 if (size <= strlen(abs_path))
161 LOGE("[%s] INVALID_PARAMETER(0x%08x) : the buffer is not big enough", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
165 snprintf(buffer, size, "%s", abs_path);