4 * Array format access functions.
6 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
8 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
21 #include <babeltrace/ctf/types.h>
23 int ctf_array_read(struct stream_pos
*ppos
, struct definition
*definition
)
25 struct definition_array
*array_definition
=
26 container_of(definition
, struct definition_array
, p
);
27 struct declaration_array
*array_declaration
=
28 array_definition
->declaration
;
29 struct declaration
*elem
= array_declaration
->elem
;
30 struct ctf_stream_pos
*pos
=
31 container_of(ppos
, struct ctf_stream_pos
, parent
);
33 if (elem
->id
== CTF_TYPE_INTEGER
) {
34 struct declaration_integer
*integer_declaration
=
35 container_of(elem
, struct declaration_integer
, p
);
37 if (integer_declaration
->encoding
== CTF_STRING_UTF8
38 || integer_declaration
->encoding
== CTF_STRING_ASCII
) {
40 if (integer_declaration
->len
== CHAR_BIT
41 && integer_declaration
->p
.alignment
== CHAR_BIT
) {
43 ctf_align_pos(pos
, integer_declaration
->p
.alignment
);
44 if (!ctf_pos_access_ok(pos
, array_declaration
->len
* CHAR_BIT
))
47 g_string_assign(array_definition
->string
, "");
48 g_string_insert_len(array_definition
->string
,
49 0, (char *) ctf_get_pos_addr(pos
),
50 array_declaration
->len
);
51 ctf_move_pos(pos
, array_declaration
->len
* CHAR_BIT
);
56 return array_rw(ppos
, definition
);
59 int ctf_array_write(struct stream_pos
*ppos
, struct definition
*definition
)
61 struct definition_array
*array_definition
=
62 container_of(definition
, struct definition_array
, p
);
63 struct declaration_array
*array_declaration
=
64 array_definition
->declaration
;
65 struct declaration
*elem
= array_declaration
->elem
;
66 struct ctf_stream_pos
*pos
=
67 container_of(ppos
, struct ctf_stream_pos
, parent
);
69 if (elem
->id
== CTF_TYPE_INTEGER
) {
70 struct declaration_integer
*integer_declaration
=
71 container_of(elem
, struct declaration_integer
, p
);
73 if (integer_declaration
->encoding
== CTF_STRING_UTF8
74 || integer_declaration
->encoding
== CTF_STRING_ASCII
) {
76 if (integer_declaration
->len
== CHAR_BIT
77 && integer_declaration
->p
.alignment
== CHAR_BIT
) {
79 ctf_align_pos(pos
, integer_declaration
->p
.alignment
);
80 if (!ctf_pos_access_ok(pos
, array_declaration
->len
* CHAR_BIT
))
83 memcpy((char *) ctf_get_pos_addr(pos
),
84 array_definition
->string
->str
,
85 array_declaration
->len
);
86 ctf_move_pos(pos
, array_declaration
->len
* CHAR_BIT
);
91 return array_rw(ppos
, definition
);
This page took 0.032982 seconds and 4 git commands to generate.