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 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.
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
USA.
***/
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
USA.
***/
assert(fname);
if (!(fo = fopen(fname, "r"))) {
avahi_log_error("Failed to open file '%s': %s", fname, strerror(errno));
return NULL;
}
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;
f = avahi_new(AvahiIniFile, 1);
AVAHI_LLIST_HEAD_INIT(AvahiIniFileGroup, f->groups);
f->n_groups = 0;
s = ln + strspn(ln, " \t");
s[strcspn(s, "\r\n")] = 0;
s = ln + strspn(ln, " \t");
s[strcspn(s, "\r\n")] = 0;
if (!(e = strchr(s, ']'))) {
avahi_log_error("Unclosed group header in %s:%u: <%s>", fname, line, s);
goto fail;
}
*e = 0;
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);
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 {
AVAHI_LLIST_PREPEND(AvahiIniFileGroup, groups, f->groups, group);
f->n_groups++;
} else {
avahi_log_error("Missing assignment in %s:%u: <%s>", fname, line, s);
goto fail;
}
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;
}
if (!group) {
avahi_log_error("Assignment outside group in %s:%u <%s>", fname, line, s);
goto fail;
}
pair = avahi_new(AvahiIniFilePair, 1);
pair->key = avahi_strdup(s);
pair->value = avahi_strdup(e);
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++;
}
}
AVAHI_LLIST_PREPEND(AvahiIniFilePair, pairs, group->pairs, pair);
group->n_pairs++;
}
}
- size_t l = strcspn(t, ",");
+ size_t n, l = strcspn(t, ",");
+ const char *c;
+
+ /* Ignore leading blanks */
+ for (c = t, n = l; isblank(*c); c++, n--);
- *(i++) = avahi_strndup(t, l);
+ /* Ignore trailing blanks */
+ for (; n > 0 && isblank(c[n-1]); n--);
+
+ *(i++) = avahi_strndup(c, n);