From: Miek Gieben Date: Mon, 14 Mar 2005 11:06:26 +0000 (+0000) Subject: make the delimeter chars configuralbe. This will allow us to X-Git-Tag: release-0.50~262 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=684f227c04665905f3d14926ee328febda2589e6;p=thirdparty%2Fldns.git make the delimeter chars configuralbe. This will allow us to parse b64 encoded stuff by skipping over spaces --- diff --git a/resolver.c b/resolver.c index c17c5546..416d2477 100644 --- a/resolver.c +++ b/resolver.c @@ -432,7 +432,7 @@ ldns_resolver_new_frm_file(const char *filename) } /* the file is opened. it's line based - this will be a bit messy */ - while (readword(word, fp, MAXLINE_LEN) != -1) { + while (readword(word, fp, "\n\t ", MAXLINE_LEN) != -1) { /* do something */ switch(expect) { case RESOLV_KEYWORD: diff --git a/util.c b/util.c index 765c4ef2..348590d1 100644 --- a/util.c +++ b/util.c @@ -156,22 +156,35 @@ int_to_hexdigit(int i) /** * read a word from a stream. Return the number * of character read or -1 on failure or EOF + * All the chars in *del are used to stop when reading. + * It defaults to '\n\t ' (newline, tab, space); */ int -readword(char *line, FILE *from, size_t lim) +readword(char *word, FILE *from, char *del, size_t lim) { int c; char *l; + char *d; + char *delim; int i; - l = line; i = 0; + l = word; i = 0; + if (!del) { + delim = "\n\t "; + } else { + delim = del; + } + while ((c = getc(from)) != EOF) { - if (c != '\n' && c != ' ' && c != '\t') { - *l++ = c; lim--; i++; - } else { - *l = '\0'; - return i; + + for (d = del; *d; d++) { + if (c == *d) { + *l = '\0'; + return i; + } } + *l++ = c; lim--; i++; + if ((size_t)i > lim) { return -1; } diff --git a/util.h b/util.h index 8a19537b..11aa71ea 100644 --- a/util.h +++ b/util.h @@ -165,6 +165,6 @@ char int_to_hexdigit(int ch); /** * return a word from a stream */ -int readword(char *, FILE *, size_t); +int readword(char *, FILE *, char *, size_t); #endif /* !_UTIL_H */