]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/cmd/webfs/sub.c
git/branch: somewhere in the syncing, the fix for junk files was lost
[plan9front.git] / sys / src / cmd / webfs / sub.c
index b8ca1e3ac613299b9c9d65538579ddf8bdd08652..633f0edbf4e4115db2f5c8250d71accf65167169 100644 (file)
@@ -8,6 +8,8 @@
 #include "dat.h"
 #include "fns.h"
 
+char *whitespace = " \t\r\n";
+
 void*
 emalloc(int n)
 {
@@ -69,14 +71,22 @@ delkey(Key *h, char *key)
        return h;
 }
 
-char*
-lookkey(Key *k, char *key)
+Key*
+getkey(Key *k, char *key)
 {
        while(k){
                if(!cistrcmp(k->key, key))
-                       return k->val;
+                       break;
                k = k->next;
        }
+       return k;
+}
+
+char*
+lookkey(Key *k, char *key)
+{
+       if(k = getkey(k, key))
+               return k->val;
        return nil;
 }
 
@@ -85,12 +95,14 @@ parsehdr(char *s)
 {
        char *v;
 
+       if(*s == 0)
+               return nil;
        v = strchr(s, 0)-1;
-       while(v >= s && strchr("\n\r\t ", *v))
+       while(v >= s && strchr(whitespace, *v))
                *v-- = 0;
        if(v = strchr(s, ':')){
                *v++ = 0;
-               while(strchr("\t ", *v))
+               while(*v == ' ' || *v == '\t')
                        v++;
                if(*s && *v)
                        return addkey(0, s, v);