13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
int lc_process_conf_space(const char *appname, const char *configfile) {
FILE *configfp = NULL;
char linebuf[LC_LINEBUF_LEN] = {0}, *linebuf_ptr = NULL;
char *cmd = NULL, *value = NULL, *sep = NULL;
char *fgetsret = NULL;
int lcpvret = -1;
if (appname == NULL || configfile == NULL) {
return(-1);
}
configfp = fopen(configfile, "r");
if (configfp == NULL) {
return(-1);
}
while (1) {
fgetsret = fgets(linebuf, sizeof(linebuf) - 1, configfp);
if (fgetsret == NULL) {
break;
|
>
>
>
>
|
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
int lc_process_conf_space(const char *appname, const char *configfile) {
FILE *configfp = NULL;
char linebuf[LC_LINEBUF_LEN] = {0}, *linebuf_ptr = NULL;
char *cmd = NULL, *value = NULL, *sep = NULL;
char *fgetsret = NULL;
int lcpvret = -1;
int retval = 0;
lc_err_t save_lc_errno = LC_ERR_NONE;
if (appname == NULL || configfile == NULL) {
lc_errno = LC_ERR_INVDATA;
return(-1);
}
configfp = fopen(configfile, "r");
if (configfp == NULL) {
lc_errno = LC_ERR_CANTOPEN;
return(-1);
}
while (1) {
fgetsret = fgets(linebuf, sizeof(linebuf) - 1, configfp);
if (fgetsret == NULL) {
break;
|
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
*sep++;
}
value = sep;
} else {
value = NULL;
}
lcpvret = lc_process_var(cmd, NULL, value, LC_FLAGS_VAR);
if (lcpvret < 0) {
PRINTERR_D("Invalid command: \"%s\"", cmd);
}
}
fclose(configfp);
return(0);
}
|
>
>
>
|
>
>
>
>
>
>
>
|
|
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
*sep++;
}
value = sep;
} else {
value = NULL;
}
save_lc_errno = lc_errno;
lc_errno = LC_ERR_NONE;
lcpvret = lc_process_var(cmd, NULL, value, LC_FLAGS_VAR);
if (lcpvret < 0) {
if (lc_errno == LC_ERR_NONE) {
PRINTERR_D("Invalid command: \"%s\"", cmd);
lc_errno = LC_ERR_INVCMD;
} else {
PRINTERR_D("Error processing command (command was valid, but an error occured, errno was set)");
}
retval = -1;
} else {
lc_errno = save_lc_errno;
}
}
fclose(configfp);
return(retval);
}
|