8
9
10
11
12
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
39
40
41
42
43
44
45
46
47
48
49
|
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
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 = lc_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;
}
if (feof(configfp)) {
break;
}
linebuf_ptr = &linebuf[strlen(linebuf) - 1];
while (*linebuf_ptr < ' ' && linebuf_ptr >= linebuf) {
*linebuf_ptr = '\0';
linebuf_ptr--;
}
|
|
>
>
>
>
>
>
>
>
>
|
|
>
>
|
8
9
10
11
12
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
int lc_process_conf_space(const char *appname, const char *configfile) {
LC_FILE *configfp = NULL;
const char *local_lc_errfile;
char linebuf[LC_LINEBUF_LEN] = {0}, *linebuf_ptr = NULL;
char *cmd = NULL, *value = NULL, *sep = NULL;
char *fgetsret = NULL;
int local_lc_errline;
int lcpvret = -1;
int retval = 0;
lc_err_t save_lc_errno = LC_ERR_NONE;
local_lc_errfile = configfile;
local_lc_errline = 0;
if (appname == NULL || configfile == NULL) {
lc_errfile = local_lc_errfile;
lc_errline = local_lc_errline;
lc_errno = LC_ERR_INVDATA;
return(-1);
}
configfp = lc_fopen(configfile, "r");
if (configfp == NULL) {
lc_errfile = local_lc_errfile;
lc_errline = local_lc_errline;
lc_errno = LC_ERR_CANTOPEN;
return(-1);
}
while (1) {
fgetsret = lc_fgets(linebuf, sizeof(linebuf) - 1, configfp);
if (fgetsret == NULL) {
break;
}
if (lc_feof(configfp)) {
break;
}
local_lc_errline++;
linebuf_ptr = &linebuf[strlen(linebuf) - 1];
while (*linebuf_ptr < ' ' && linebuf_ptr >= linebuf) {
*linebuf_ptr = '\0';
linebuf_ptr--;
}
|
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#endif
lc_errno = LC_ERR_INVCMD;
} else {
#ifdef DEBUG
fprintf(stderr, "Error processing command (command was valid, but an error occured, errno was set)\n");
#endif
}
retval = -1;
} else {
lc_errno = save_lc_errno;
}
}
fclose(configfp);
return(retval);
}
|
>
>
|
|
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
#endif
lc_errno = LC_ERR_INVCMD;
} else {
#ifdef DEBUG
fprintf(stderr, "Error processing command (command was valid, but an error occured, errno was set)\n");
#endif
}
lc_errfile = local_lc_errfile;
lc_errline = local_lc_errline;
retval = -1;
} else {
lc_errno = save_lc_errno;
}
}
lc_fclose(configfp);
return(retval);
}
|