From: Taeyoung Kim Date: Sat, 6 Jun 2015 13:00:20 +0000 (+0900) Subject: common: change file name system_info_no_file.c to system_info_file.c X-Git-Tag: submit/tizen/20150609.090025~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ca5a4f5a4f15d5c71d4456e509d5d5b545e35d5b;p=platform%2Fcore%2Fapi%2Fsystem-info.git common: change file name system_info_no_file.c to system_info_file.c - The codes are related with reading information from certain files. Thus the name is changed from 'no_file' to 'file' Change-Id: I238a4338b9494d5349362b7fe98750ea022be730 Signed-off-by: Taeyoung Kim --- diff --git a/include/system_info_private.h b/include/system_info_private.h index 1d3625c..00b671b 100644 --- a/include/system_info_private.h +++ b/include/system_info_private.h @@ -107,7 +107,7 @@ int system_info_get_build_date(system_info_key_e key, system_info_data_type_e da int system_info_get_build_time(system_info_key_e key, system_info_data_type_e data_type, void **value); int system_info_get_tethering_supported(system_info_key_e key, system_info_data_type_e data_type, void **value); -int system_info_get_no_file(const char *key, void **value); +int system_info_get_file(const char *key, void **value); #ifdef __cplusplus } diff --git a/src/system_info.c b/src/system_info.c index ecbdd8f..1e85601 100644 --- a/src/system_info.c +++ b/src/system_info.c @@ -338,7 +338,7 @@ API int system_info_get_platform_string(const char *key, char **value) return SYSTEM_INFO_ERROR_IO_ERROR; } - ret = system_info_get_no_file(key, (void**)&string); + ret = system_info_get_file(key, (void**)&string); if (ret == 0) { *value = string; return SYSTEM_INFO_ERROR_NONE; diff --git a/src/system_info_file.c b/src/system_info_file.c new file mode 100644 index 0000000..e44c2a8 --- /dev/null +++ b/src/system_info_file.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "CAPI_SYSTEM_INFO" + +#define SERIAL_TOK_DELIMITER "," +#define BUF_MAX 256 + +static int get_tizenid(char **value) +{ + char id[BUF_MAX]; + FILE *fp; + + fp = fopen(TIZEN_ID_PATH, "r"); + if (!fp) { + LOGE("Failed to open file (%s)", TIZEN_ID_PATH); + return SYSTEM_INFO_ERROR_IO_ERROR; + } + + if (fgets(id, sizeof(id), fp) == NULL) { + LOGE("Failed to get string (errno:%d)", errno); + fclose(fp); + return SYSTEM_INFO_ERROR_IO_ERROR; + } + + fclose(fp); + + if (strlen(id) == 0) { + LOGE("String length of id is 0"); + return SYSTEM_INFO_ERROR_IO_ERROR; + } + + *value = strdup(id); + + return 0; +} + +int system_info_get_file(const char *key, void **value) +{ + char *p_key; + + if (!key || !value) + return -EINVAL; + + p_key = strstr(key, "http://"); + if (p_key && p_key == key) + p_key = (char *)key + strlen("http://"); + else + p_key = (char *)key; + + if (!strncmp(p_key, "tizen.org/system/tizenid", strlen(p_key))) + return get_tizenid((char **)value); + + if (!strncmp(p_key, "tizen.org/system/build.date", strlen(p_key))) + return system_info_ini_get_string(INFO_FILE_PATH, "build:date", (char **)value); + + if (!strncmp(p_key, "tizen.org/system/build.string", strlen(p_key))) + return system_info_ini_get_string(INFO_FILE_PATH, "version:build", (char **)value); + + if (!strncmp(p_key, "tizen.org/system/build.time", strlen(p_key))) + return system_info_ini_get_string(INFO_FILE_PATH, "build:time", (char **)value); + + return -ENOENT; +} diff --git a/src/system_info_no_file.c b/src/system_info_no_file.c deleted file mode 100644 index 583ea70..0000000 --- a/src/system_info_no_file.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -#ifdef LOG_TAG -#undef LOG_TAG -#endif - -#define LOG_TAG "CAPI_SYSTEM_INFO" - -#define SERIAL_TOK_DELIMITER "," -#define BUF_MAX 256 - -static int get_tizenid(char **value) -{ - char id[BUF_MAX]; - FILE *fp; - - fp = fopen(TIZEN_ID_PATH, "r"); - if (!fp) { - LOGE("Failed to open file (%s)", TIZEN_ID_PATH); - return SYSTEM_INFO_ERROR_IO_ERROR; - } - - if (fgets(id, sizeof(id), fp) == NULL) { - LOGE("Failed to get string (errno:%d)", errno); - fclose(fp); - return SYSTEM_INFO_ERROR_IO_ERROR; - } - - fclose(fp); - - if (strlen(id) == 0) { - LOGE("String length of id is 0"); - return SYSTEM_INFO_ERROR_IO_ERROR; - } - - *value = strdup(id); - - return 0; -} - -int system_info_get_no_file(const char *key, void **value) -{ - char *p_key; - - if (!key || !value) - return -EINVAL; - - p_key = strstr(key, "http://"); - if (p_key && p_key == key) - p_key = (char *)key + strlen("http://"); - else - p_key = (char *)key; - - if (!strncmp(p_key, "tizen.org/system/tizenid", strlen(p_key))) - return get_tizenid((char **)value); - - if (!strncmp(p_key, "tizen.org/system/build.date", strlen(p_key))) - return system_info_ini_get_string(INFO_FILE_PATH, "build:date", (char **)value); - - if (!strncmp(p_key, "tizen.org/system/build.string", strlen(p_key))) - return system_info_ini_get_string(INFO_FILE_PATH, "version:build", (char **)value); - - if (!strncmp(p_key, "tizen.org/system/build.time", strlen(p_key))) - return system_info_ini_get_string(INFO_FILE_PATH, "build:time", (char **)value); - - return -ENOENT; -}