]> mj.ucw.cz Git - libucw.git/commitdiff
Added obj_find_anum() which is obj_find_aval() combined with atol() and
authorMartin Mares <mj@ucw.cz>
Sat, 14 Aug 2004 15:15:53 +0000 (15:15 +0000)
committerMartin Mares <mj@ucw.cz>
Sat, 14 Aug 2004 15:15:53 +0000 (15:15 +0000)
a default value (this is a very common idiom at many places).

Added size_attr() which calculates size of a given attribute in the
current bucket format.

lib/obj2buck.c
lib/object.c
lib/object.h

index 367764a5aef3f214610752313cbe07daf19c338d..6cd2589626f9ca9e81ee39c6eaefc715ad6bd54c 100644 (file)
@@ -42,6 +42,19 @@ attr_set_type(uns type)
     }
 }
 
+uns
+size_attr(uns len)
+{
+  ASSERT(len <= MAX_ATTR_SIZE);
+  if (use_v33)
+    {
+      len++;
+      return len + utf8_space(len);
+    }
+  else
+    return len + 2;
+}
+
 inline byte *
 put_attr(byte *ptr, uns type, byte *val, uns len)
 {
index ab882c12a139479db0e0f007f41bdb87c0dc6ccb..6a2a90c5b5d46aeec6c8709be842121bd553f41a 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <string.h>
 #include <stdio.h>
+#include <stdlib.h>
 
 void
 obj_dump(struct odes *o)
@@ -117,6 +118,13 @@ obj_find_aval(struct odes *o, uns x)
   return a ? a->val : NULL;
 }
 
+uns
+obj_find_anum(struct odes *o, uns x, uns def)
+{
+  struct oattr *a = obj_find_attr(o, x);
+  return a ? (uns)atol(a->val) : def;
+}
+
 struct oattr *
 obj_set_attr(struct odes *o, uns x, byte *v)
 {
index 01c47dfbbf27b629f5ae01b52589c243f2316717..c889953b7ca3c7f833444b43e7c6af6dbc56f534 100644 (file)
@@ -34,6 +34,7 @@ struct oattr *obj_find_attr(struct odes *, uns);
 struct oattr *obj_find_attr_last(struct odes *, uns);
 uns obj_del_attr(struct odes *, struct oattr *);
 byte *obj_find_aval(struct odes *, uns);
+uns obj_find_anum(struct odes *, uns, uns);
 struct oattr *obj_set_attr(struct odes *, uns, byte *);
 struct oattr *obj_set_attr_num(struct odes *, uns, uns);
 struct oattr *obj_add_attr(struct odes *, uns, byte *);
@@ -65,6 +66,8 @@ int obj_read(struct fastbuf *, struct odes *);
 
 void attr_set_type(uns type);
 
+uns size_attr(uns len);
+
 byte *put_attr(byte *ptr, uns type, byte *val, uns len);
 byte *put_attr_str(byte *ptr, uns type, byte *val);
 byte *put_attr_vformat(byte *ptr, uns type, byte *mask, va_list va);