X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;ds=sidebyside;f=avahi-daemon%2Fini-file-parser.c;h=0a99ce366cf542d3bc18aafc482236e184558ccd;hb=53e47a32e490f6f45a0e4382f5e9c6e38a273436;hp=1b50335ba4e0fcbfaac772dfbc4bf9614539ad69;hpb=15f5bd4aa32e7c462ebccc8c1ef8da70bdcc68f4;p=catta diff --git a/avahi-daemon/ini-file-parser.c b/avahi-daemon/ini-file-parser.c index 1b50335..0a99ce3 100644 --- a/avahi-daemon/ini-file-parser.c +++ b/avahi-daemon/ini-file-parser.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -38,14 +36,14 @@ AvahiIniFile* avahi_ini_file_load(const char *fname) { FILE *fo; AvahiIniFileGroup *group = NULL; unsigned line; - + assert(fname); if (!(fo = fopen(fname, "r"))) { avahi_log_error("Failed to open file '%s': %s", fname, strerror(errno)); return NULL; } - + f = avahi_new(AvahiIniFile, 1); AVAHI_LLIST_HEAD_INIT(AvahiIniFileGroup, f->groups); f->n_groups = 0; @@ -54,12 +52,12 @@ AvahiIniFile* avahi_ini_file_load(const char *fname) { while (!feof(fo)) { char ln[256], *s, *e; AvahiIniFilePair *pair; - + if (!(fgets(ln, sizeof(ln), fo))) break; line++; - + s = ln + strspn(ln, " \t"); s[strcspn(s, "\r\n")] = 0; @@ -69,19 +67,19 @@ AvahiIniFile* avahi_ini_file_load(const char *fname) { if (*s == '[') { /* new group */ - + if (!(e = strchr(s, ']'))) { avahi_log_error("Unclosed group header in %s:%u: <%s>", fname, line, s); goto fail; } *e = 0; - + group = avahi_new(AvahiIniFileGroup, 1); group->name = avahi_strdup(s+1); group->n_pairs = 0; AVAHI_LLIST_HEAD_INIT(AvahiIniFilePair, group->pairs); - + AVAHI_LLIST_PREPEND(AvahiIniFileGroup, groups, f->groups, group); f->n_groups++; } else { @@ -91,26 +89,26 @@ AvahiIniFile* avahi_ini_file_load(const char *fname) { avahi_log_error("Missing assignment in %s:%u: <%s>", fname, line, s); goto fail; } - + if (!group) { avahi_log_error("Assignment outside group in %s:%u <%s>", fname, line, s); goto fail; } - + /* Split the key and the value */ *(e++) = 0; - + pair = avahi_new(AvahiIniFilePair, 1); pair->key = avahi_strdup(s); pair->value = avahi_strdup(e); - + AVAHI_LLIST_PREPEND(AvahiIniFilePair, pairs, group->pairs, pair); group->n_pairs++; } } - + fclose(fo); - + return f; fail: @@ -130,7 +128,7 @@ void avahi_ini_file_free(AvahiIniFile *f) { while ((g = f->groups)) { AvahiIniFilePair *p; - + while ((p = g->pairs)) { avahi_free(p->key); avahi_free(p->value); @@ -190,7 +188,7 @@ void avahi_strfreev(char **p) { if (!p) return; - + for (i = p; *i; i++) avahi_free(*i);