3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 #include "utility/sync_util.h"
22 #include "utility/fw_file.h"
24 #include "fsapi/operation.h"
26 #include <tzplatform_config.h>
29 #define EXPORT_API __attribute__ ((visibility("default")))
32 #ifndef SYNC_AGENT_LOG
34 #define LOG_TAG "AF_UTIL_FILE"
37 #define UTIL_DEFAULT_ACCOUNT_PLUGIN_FOLDER tzplatform_mkpath(TZ_SYS_DATA,"sync-agent/db")
39 EXPORT_API int sync_agent_set_int_into_file(char *file_path, int value)
43 retvm_if(file_path == NULL, 0, "file_path parameter is NULL !!");
46 char *temp_value = NULL;
48 if (!sync_agent_is_existing_fs(UTIL_DEFAULT_ACCOUNT_PLUGIN_FOLDER)) {
49 if (!sync_agent_create_directory(UTIL_DEFAULT_ACCOUNT_PLUGIN_FOLDER)) {
50 _DEBUG_ERROR("Failed to create default folder");
56 snprintf(path, sizeof(path), "%s/%s", UTIL_DEFAULT_ACCOUNT_PLUGIN_FOLDER, file_path);
57 temp_value = g_strdup_printf("%d", value);
59 if (temp_value != NULL) {
60 _DEBUG_INFO("path = %s", path);
61 _DEBUG_INFO("value = %s", temp_value);
63 if (!sync_agent_write_whole_file(path, temp_value, strlen(temp_value), true)) {
64 _DEBUG_ERROR("Failed write data");
71 _DEBUG_ERROR("strdup() FAIL !!!");
81 EXPORT_API int sync_agent_get_int_from_file(char *file_path, int *value)
85 retvm_if(file_path == NULL, 0, "file_path parameter is NULL !!");
86 retvm_if(value == NULL, 0, "value parameter is NULL !!");
89 char *temp_value = NULL;
92 snprintf(path, sizeof(path), "%s/%s", UTIL_DEFAULT_ACCOUNT_PLUGIN_FOLDER, file_path);
94 _DEBUG_INFO("path = %s", path);
95 if (!sync_agent_read_whole_file(path, &temp_value, &size)) {
96 _DEBUG_ERROR("Failed to read file");
101 *value = atoi(temp_value);
103 _DEBUG_INFO("value = %d", *value);
105 // if (temp_value != NULL)
113 EXPORT_API int sync_agent_unset_file(char *file_path)
117 retvm_if(file_path == NULL, 0, "file_path parameter is NULL !!");
121 snprintf(path, sizeof(path), "%s/%s", UTIL_DEFAULT_ACCOUNT_PLUGIN_FOLDER, file_path);
122 _DEBUG_INFO("path = %s", path);
126 return sync_agent_delete_file(path);