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.
25 #include <system_info.h>
26 #include <system_info_private.h>
32 #define LOG_TAG "CAPI_SYSTEM_INFO"
34 int system_info_get_value_from_cpuinfo(char *field, char **value)
39 char str[MAXBUFSIZE] = { 0, };
40 char tmpStr[MAXBUFSIZE] = { 0, };
42 if (system_info_get_system_info_model_type() == SYSTEM_INFO_MODEL_TYPE_EMULATOR) {
43 snprintf(tmpStr, sizeof(tmpStr), "default");
47 cpuinfo = fopen(CPU_INFO_FILE_PATH, "r");
48 if (NULL == cpuinfo) {
49 LOGE("cannot file open %s file!!!", CPU_INFO_FILE_PATH);
50 if (errno == EPERM || errno == EACCES)
51 return SYSTEM_INFO_ERROR_PERMISSION_DENIED;
52 return SYSTEM_INFO_ERROR_IO_ERROR;
55 while (fgets(str, sizeof(str), cpuinfo)) {
56 if (strncmp(field, str, strlen(field)))
59 name = strchr(str, ':');
60 tmpStrlen = strlen(name+2);
61 strncpy(tmpStr, name+2, tmpStrlen);
62 tmpStr[tmpStrlen-1] = '\0';
69 if (strlen(tmpStr) == 0) {
70 LOGE("Failed to get (%s) info", field);
71 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
74 *value = strdup(tmpStr);
76 LOGE("malloc() failed to get (%s) info", field);
77 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
80 return SYSTEM_INFO_ERROR_NONE;