Ok, so I am trying to retrieve a value from a file given a search key. The file will be a php file containing defines, like this:
Code:
define("LOG_DEBUG_LEVEL", "0");
This is what I am doing, which find the value, but wont error if its not found. If I comment out the above define in the file, no error is logged.
Code:
int getDebugLevel( char *key )
{
FILE *fp;
char *temp;
char *strLvl;
char line[256];
fp = fopen(MYFILE, "r");
if ( fp == NULL )
{
syslog(LOG_ERR,"Unable to open %s for reading", MYFILE);
return 1;
}
while(fgets(line, sizeof(line), fp) != NULL)
{
if(strstr(line, key))
{
temp = strdup(line);
strLvl = strsep(&temp, "\"");
strLvl = strsep(&temp, "\"");
break;
}
}
fclose(fp);
if( strLvl == NULL )
{
syslog(LOG_ERR,"Unable to find DEBUG LEVEL in %s" MYFILE);
return 1;
}
strncpy(value, strLvl, strlen(strLvl));
value = atoi(value);
return 1;
}