I am confronted with the following code:
int get_config(const char *key, char *value) {
FILE *fp = NULL;
char s[100];
char *ret1 = NULL;
char *ret2 = NULL;
fp = fopen(CONFIG_FILE_PATH, "r");
if (fp == NULL) {
perror(CONFIG_FILE_PATH);
return FALSE;
}
while (fgets(s, 100, fp) != NULL) {
//printf("line=%s", s);
ret1 = strstr(s, key);
if (ret1 != NULL) {
ret1 = strstr(s, "=");
if (ret1 != NULL) {
ret1++;
ret2 = strstr(s, "\n");
strncpy(value, ret1, ret2 - ret1);
//printf("ret1=%p ret2=%p\n", ret1,ret2);
value[ret2 - ret1] = 0x0;
printf("config key=%s value=%s\n", key, value);
fclose(fp);
fp = NULL;
ret1 = NULL;
ret2 = NULL;
return TRUE;
}
}
}
I struggle to understand what ret1++
does. If I understood the strstr()
correctly, after ret1 = strstr(s, "=");
ret1 will contain all everything following the = sign within s.
Lets assume this not a number, but a word "value", resulting in ret1 = value
What does this mean for ret1++
?
Maybe my assumption of the CONFIG_FILE_PATH is wrong, and a number always follows the equal sign.
Sidenote:
I just wished, I knew what CONFIG_FILE_PATH looks like. But as #define CONFIG_FILE_PATH "/etc/config/duvs.conf"
But this path is probably located on the device, this program is written for... :/