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/ctf/types.h>
20 #include <limits.h> /* C99 limits */
23 void ctf_string_copy(struct stream_pos
*pdest
, struct stream_pos
*psrc
,
24 const struct declaration_string
*string_declaration
)
26 struct ctf_stream_pos
*dest
= ctf_pos(pdest
);
27 struct ctf_stream_pos
*src
= ctf_pos(psrc
);
29 char *destaddr
, *srcaddr
;
31 ctf_align_pos(src
, string_declaration
->p
.alignment
);
32 srcaddr
= ctf_get_pos_addr(src
);
33 len
= strlen(srcaddr
) + 1;
36 ctf_align_pos(dest
, string_declaration
->p
.alignment
);
37 destaddr
= ctf_get_pos_addr(dest
);
38 strcpy(destaddr
, srcaddr
);
40 ctf_move_pos(dest
, len
);
41 ctf_move_pos(src
, len
);
44 void ctf_string_read(struct stream_pos
*ppos
, struct definition
*definition
)
46 struct definition_string
*string_definition
=
47 container_of(definition
, struct definition_string
, p
);
48 const struct declaration_string
*string_declaration
=
49 string_definition
->declaration
;
50 struct ctf_stream_pos
*pos
= ctf_pos(ppos
);
54 ctf_align_pos(pos
, string_declaration
->p
.alignment
);
55 srcaddr
= ctf_get_pos_addr(pos
);
56 len
= strlen(srcaddr
) + 1;
57 if (string_definition
->alloc_len
< len
) {
58 string_definition
->value
=
59 g_realloc(string_definition
->value
, len
);
60 string_definition
->alloc_len
= len
;
62 memcpy(string_definition
->value
, srcaddr
, len
);
63 string_definition
->len
= len
;
64 ctf_move_pos(pos
, len
);
67 void ctf_string_write(struct stream_pos
*ppos
,
68 struct definition
*definition
)
70 struct definition_string
*string_definition
=
71 container_of(definition
, struct definition_string
, p
);
72 const struct declaration_string
*string_declaration
=
73 string_definition
->declaration
;
74 struct ctf_stream_pos
*pos
= ctf_pos(ppos
);
78 ctf_align_pos(pos
, string_declaration
->p
.alignment
);
79 assert(string_definition
->value
!= NULL
);
80 len
= string_definition
->len
;
83 destaddr
= ctf_get_pos_addr(pos
);
84 strcpy(destaddr
, string_definition
->value
);
86 ctf_move_pos(pos
, len
);
This page took 0.031658 seconds and 4 git commands to generate.