]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
make the delimeter chars configuralbe. This will allow us to
authorMiek Gieben <miekg@NLnetLabs.nl>
Mon, 14 Mar 2005 11:06:26 +0000 (11:06 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Mon, 14 Mar 2005 11:06:26 +0000 (11:06 +0000)
parse b64 encoded stuff by skipping over spaces

resolver.c
util.c
util.h

index c17c5546ccc4f841a296cada0bd4783cd901c165..416d247701dbdc8d9c3d169cb459025e6e324d85 100644 (file)
@@ -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 765c4ef202620079ff04c8de7afc4deee145a2be..348590d1a12e1af8dd7d1457ea145a71b9de174a 100644 (file)
--- 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 8a19537b4eecb05a551acdef51d43bd244fc2a38..11aa71ea555d41c5834d33f4d62cd9f1fc4d9f09 100644 (file)
--- 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 */