4 * Strings read/write functions.
6 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
19 #include <babeltrace/babeltrace.h>
20 #include <babeltrace/ctf/types.h>
21 #include <limits.h> /* C99 limits */
24 void ctf_string_read(struct stream_pos
*ppos
, struct definition
*definition
)
26 struct definition_string
*string_definition
=
27 container_of(definition
, struct definition_string
, p
);
28 const struct declaration_string
*string_declaration
=
29 string_definition
->declaration
;
30 struct ctf_stream_pos
*pos
= ctf_pos(ppos
);
34 ctf_align_pos(pos
, string_declaration
->p
.alignment
);
35 srcaddr
= ctf_get_pos_addr(pos
);
36 len
= strlen(srcaddr
) + 1;
37 if (string_definition
->alloc_len
< len
) {
38 string_definition
->value
=
39 g_realloc(string_definition
->value
, len
);
40 string_definition
->alloc_len
= len
;
42 printf_debug("CTF string read %s\n", srcaddr
);
43 memcpy(string_definition
->value
, srcaddr
, len
);
44 string_definition
->len
= len
;
45 ctf_move_pos(pos
, len
* CHAR_BIT
);
48 void ctf_string_write(struct stream_pos
*ppos
,
49 struct definition
*definition
)
51 struct definition_string
*string_definition
=
52 container_of(definition
, struct definition_string
, p
);
53 const struct declaration_string
*string_declaration
=
54 string_definition
->declaration
;
55 struct ctf_stream_pos
*pos
= ctf_pos(ppos
);
59 ctf_align_pos(pos
, string_declaration
->p
.alignment
);
60 assert(string_definition
->value
!= NULL
);
61 len
= string_definition
->len
;
64 destaddr
= ctf_get_pos_addr(pos
);
65 memcpy(destaddr
, string_definition
->value
, len
);
67 ctf_move_pos(pos
, len
* CHAR_BIT
);
This page took 0.035385 seconds and 5 git commands to generate.