]> mj.ucw.cz Git - libucw.git/commitdiff
Multi-part objects (with header and body separated by an empty line and terminated
authorMartin Mares <mj@ucw.cz>
Sat, 10 Apr 2004 20:36:01 +0000 (20:36 +0000)
committerMartin Mares <mj@ucw.cz>
Sat, 10 Apr 2004 20:36:01 +0000 (20:36 +0000)
either by EOF or by a NUL byte) are very common, so let's introduce a special
function for reading them.

lib/object.c
lib/object.h

index fb957bd7e61169271226a5689738e30f8a7fc8ae..db471c4b0257e25d58e61e4ce9ec6bb9f1879eae 100644 (file)
@@ -58,6 +58,16 @@ obj_read(struct fastbuf *f, struct odes *o)
   return 0;
 }
 
+void
+obj_read_multi(struct fastbuf *f, struct odes *o)
+{
+  /* Read a multi-part object ending with either EOF or a NUL character */
+  byte buf[MAX_ATTR_SIZE];
+  while (bpeekc(f) > 0 && bgets(f, buf, sizeof(buf)))
+    if (buf[0])
+      obj_add_attr(o, buf[0], buf+1);
+}
+
 void
 obj_write(struct fastbuf *f, struct odes *d)
 {
index 99ff28263164aaa96b3eb6e3fc4b4698c03906bf..4f6cffbc0737296d0f782446d0466ceea8faa72f 100644 (file)
@@ -29,6 +29,7 @@ struct oattr {                                /* Object attribute */
 void obj_dump(struct odes *);
 struct odes *obj_new(struct mempool *);
 int obj_read(struct fastbuf *, struct odes *);
+void obj_read_multi(struct fastbuf *, struct odes *);
 void obj_write(struct fastbuf *, struct odes *);
 void obj_write_nocheck(struct fastbuf *, struct odes *);
 struct oattr *obj_find_attr(struct odes *, uns);