int get_cfg_value(char *psz_cfg_value, char *psz_cfg_id, FILE *f_descriptor)
{
if (NULL == psz_cfg_value || NULL == psz_cfg_id || NULL == f_descriptor)
{
return E_INVALIDARG;
}
char *psz_iterator;
char psz_cfg_item[MAX_CFG_LEN];
int i_iterator;
memset(psz_cfg_item, 0x0, sizeof(psz_cfg_item));
psz_iterator = NULL;
i_iterator = 0;
fseek(f_descriptor, 0, SEEK_SET);
while ((fgets(psz_cfg_item, (sizeof(psz_cfg_item) - 1),
f_descriptor)) != NULL)
{
char* psz_temp = psz_cfg_item;
while (*psz_temp != '\0' && (' ' == *psz_temp || '\t' == *psz_temp))
{
psz_temp++;
}
if ('#' == psz_temp[0] || '\0' == psz_temp[0])
{
continue;
}
if ((strstr(psz_temp, psz_cfg_id)) != NULL)
{
psz_iterator = index(psz_temp, EQUAL_TAG);
if (NULL == psz_iterator)
{
return E_INVALIDARG;
}
psz_iterator++;
while (*psz_iterator != '\0' && *psz_iterator != '\n')
{
psz_cfg_value[i_iterator] = *psz_iterator;
i_iterator++;
psz_iterator++;
}
psz_cfg_value[i_iterator] = '\0';
if (0 == strlen(psz_cfg_value))
{
return E_INVALIDARG;
}
return S_OK;
}
}
return E_NOTFOUND;
}
阅读(1647) | 评论(0) | 转发(0) |