Port: Add bt_common_get_page_size
[babeltrace.git] / lib / ctf-writer / serialize.c
index 6058dd354563b7644015ebd1de8f11ddd8546175..11ce8b443531a5783dc6d8a80bff101ba0b4ff8f 100644 (file)
  * SOFTWARE.
  */
 
+#include <stdlib.h>
 #include <stdio.h>
 #include <stdint.h>
-#include <stdbool.h>
 #include <babeltrace/ctf-ir/field-types.h>
 #include <babeltrace/ctf-ir/field-types-internal.h>
 #include <babeltrace/ctf-ir/fields.h>
 #include <babeltrace/ctf-ir/fields-internal.h>
 #include <babeltrace/ctf-writer/serialize-internal.h>
-#include <babeltrace/align.h>
-#include <babeltrace/mmap-align.h>
-#include <babeltrace/endian.h>
-#include <babeltrace/bitfield.h>
-#include <babeltrace/compat/fcntl.h>
+#include <babeltrace/align-internal.h>
+#include <babeltrace/mmap-align-internal.h>
+#include <babeltrace/endian-internal.h>
+#include <babeltrace/bitfield-internal.h>
+#include <babeltrace/compat/fcntl-internal.h>
+#include <babeltrace/types.h>
+#include <babeltrace/common-internal.h>
 #include <glib.h>
 
-/* "Native" to CTF IR byte order */
-#if (BYTE_ORDER == LITTLE_ENDIAN)
-# define MY_BT_CTF_BYTE_ORDER BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
-#else
-# define MY_BT_CTF_BYTE_ORDER BT_CTF_BYTE_ORDER_BIG_ENDIAN
-#endif
-
 #if (FLT_RADIX != 2)
 # error "Unsupported floating point radix"
 #endif
@@ -67,9 +62,9 @@ union intval {
 static
 int aligned_integer_write(struct bt_ctf_stream_pos *pos,
                union intval value, unsigned int alignment, unsigned int size,
-               bool is_signed, enum bt_ctf_byte_order byte_order)
+               bt_bool is_signed, enum bt_ctf_byte_order byte_order)
 {
-       bool rbo = (byte_order != MY_BT_CTF_BYTE_ORDER); /* reverse byte order */
+       bt_bool rbo = (byte_order != BT_CTF_MY_BYTE_ORDER); /* reverse byte order */
 
        if (!bt_ctf_stream_pos_align(pos, alignment))
                return -EFAULT;
@@ -115,7 +110,7 @@ int aligned_integer_write(struct bt_ctf_stream_pos *pos,
                        break;
                }
                default:
-                       assert(false);
+                       abort();
                }
        } else {
                switch (size) {
@@ -154,7 +149,7 @@ int aligned_integer_write(struct bt_ctf_stream_pos *pos,
                        break;
                }
                default:
-                       assert(false);
+                       abort();
                }
        }
 
@@ -165,7 +160,7 @@ int aligned_integer_write(struct bt_ctf_stream_pos *pos,
 
 static
 int integer_write(struct bt_ctf_stream_pos *pos, union intval value,
-       unsigned int alignment, unsigned int size, bool is_signed,
+       unsigned int alignment, unsigned int size, bt_bool is_signed,
        enum bt_ctf_byte_order byte_order)
 {
        if (!(alignment % CHAR_BIT)
@@ -266,7 +261,7 @@ int bt_ctf_field_floating_point_write(
                return -EINVAL;
        }
 
-       return integer_write(pos, value, type->alignment, size, false,
+       return integer_write(pos, value, type->alignment, size, BT_FALSE,
                byte_order);
 }
 
@@ -282,15 +277,15 @@ void bt_ctf_stream_pos_packet_seek(struct bt_ctf_stream_pos *pos, size_t index,
                /* unmap old base */
                ret = munmap_align(pos->base_mma);
                if (ret) {
-                       assert(false);
+                       // FIXME: this can legitimately fail?
+                       abort();
                }
                pos->base_mma = NULL;
        }
 
        /* The writer will add padding */
        pos->mmap_offset += pos->packet_size / CHAR_BIT;
-       pos->content_size = -1U;        /* Unknown at this point */
-       pos->packet_size = getpagesize() * 8 * CHAR_BIT;
+       pos->packet_size = PACKET_LEN_INCREMENT;
        do {
                ret = bt_posix_fallocate(pos->fd, pos->mmap_offset,
                        pos->packet_size / CHAR_BIT);
@@ -302,6 +297,7 @@ void bt_ctf_stream_pos_packet_seek(struct bt_ctf_stream_pos *pos, size_t index,
        pos->base_mma = mmap_align(pos->packet_size / CHAR_BIT, pos->prot,
                pos->flags, pos->fd, pos->mmap_offset);
        if (pos->base_mma == MAP_FAILED) {
-               assert(false);
+               // FIXME: this can legitimately fail?
+               abort();
        }
 }
This page took 0.02538 seconds and 4 git commands to generate.