blobmsg: add blobmsg_realloc_string_buffer()
[project/libubox.git] / blob.h
diff --git a/blob.h b/blob.h
index ffd9f9a..d78115f 100644 (file)
--- a/blob.h
+++ b/blob.h
@@ -26,8 +26,6 @@
 #include <stdio.h>
 #include <errno.h>
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-
 #if defined(__linux__) || defined(__CYGWIN__)
 #include <byteswap.h>
 #include <endian.h>
@@ -60,6 +58,8 @@
 #define __LITTLE_ENDIAN LITTLE_ENDIAN
 #endif
 
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+
 #define cpu_to_be64(x) bswap_64(x)
 #define cpu_to_be32(x) bswap_32(x)
 #define cpu_to_be16(x) bswap_16(x)
@@ -191,8 +191,10 @@ blob_get_u32(const struct blob_attr *attr)
 static inline uint64_t
 blob_get_u64(const struct blob_attr *attr)
 {
-       uint64_t *tmp = (uint64_t*)attr->data;
-       return be64_to_cpu(*tmp);
+       uint32_t *ptr = blob_data(attr);
+       uint64_t tmp = ((uint64_t) be32_to_cpu(ptr[0])) << 32;
+       tmp |= be32_to_cpu(ptr[1]);
+       return tmp;
 }
 
 static inline int8_t
@@ -236,12 +238,14 @@ extern void blob_set_raw_len(struct blob_attr *attr, unsigned int len);
 extern bool blob_attr_equal(const struct blob_attr *a1, const struct blob_attr *a2);
 extern int blob_buf_init(struct blob_buf *buf, int id);
 extern void blob_buf_free(struct blob_buf *buf);
+extern void blob_buf_grow(struct blob_buf *buf, int required);
 extern struct blob_attr *blob_new(struct blob_buf *buf, int id, int payload);
 extern void *blob_nest_start(struct blob_buf *buf, int id);
 extern void blob_nest_end(struct blob_buf *buf, void *cookie);
 extern struct blob_attr *blob_put(struct blob_buf *buf, int id, const void *ptr, int len);
 extern bool blob_check_type(const void *ptr, int len, int type);
 extern int blob_parse(struct blob_attr *attr, struct blob_attr **data, const struct blob_attr_info *info, int max);
+extern struct blob_attr *blob_memdup(struct blob_attr *attr);
 
 static inline struct blob_attr *
 blob_put_string(struct blob_buf *buf, int id, const char *str)