aboutsummaryrefslogtreecommitdiffstats
path: root/src/confparser.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2018-04-17 12:30:44 +0300
committergramanas <anastasis.gramm2@gmail.com>2018-04-17 17:39:29 +0300
commit562bad603ce0fe2a6556f0f1aae4f08c9c300987 (patch)
tree8646982cdcd625dcf7f04262b66d9e78bf53afe4 /src/confparser.c
parent94bc38df829c4816e629c7dcaed31b1e7c75bc4b (diff)
downloadck-562bad603ce0fe2a6556f0f1aae4f08c9c300987.tar.gz
ck-562bad603ce0fe2a6556f0f1aae4f08c9c300987.tar.bz2
ck-562bad603ce0fe2a6556f0f1aae4f08c9c300987.zip
fix memory leaks, add logo
Diffstat (limited to 'src/confparser.c')
-rw-r--r--src/confparser.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/confparser.c b/src/confparser.c
index 0edd155..2ffe701 100644
--- a/src/confparser.c
+++ b/src/confparser.c
@@ -26,15 +26,13 @@ int remove_newline(char buff[]) {
return strlen(buff);
}
-char* read_next_line(FILE *f) {
+int read_next_line(char *line, FILE *f) {
char nextLine[200];
- char *line;
if (fgets(nextLine, 200, f) == NULL) {
- return NULL;
+ return -1;
}
- line = malloc(remove_newline(nextLine));
strcpy(line, nextLine);
- return line;
+ return 0;
}
int is_empty(const char *s) {
@@ -88,9 +86,9 @@ ConfigParserResult parse(Conf *conf, UserOpt *opt) {
}
free(confName);
int flag = 1;
- char *line = read_next_line(confPtr);
+ char line[200];
char matched[200];
- while (line != NULL) {
+ while (read_next_line(line, confPtr)) {
switch(match_variables(line, matched)) {
#define X(var, str, name) \
case CV_##var: \
@@ -108,8 +106,6 @@ ConfigParserResult parse(Conf *conf, UserOpt *opt) {
default:
printf("%s:\n%s\n", "Config error in line", line);
}
- free(line);
- line=read_next_line(confPtr);
}
#define X(var, str) \
if (conf->var == NULL) { \