Commit | Line | Data |
---|---|---|
6dc2ca62 MD |
1 | /* |
2 | * Common Trace Format | |
3 | * | |
4 | * Strings read/write functions. | |
5 | * | |
ccd7e1c8 | 6 | * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
6dc2ca62 | 7 | * |
ccd7e1c8 MD |
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: | |
de0ba614 | 14 | * |
ccd7e1c8 MD |
15 | * The above copyright notice and this permission notice shall be included in |
16 | * all copies or substantial portions of the Software. | |
6dc2ca62 MD |
17 | */ |
18 | ||
d79865b9 | 19 | #include <babeltrace/ctf/types.h> |
a3dbc794 | 20 | #include <limits.h> /* C99 limits */ |
6dc2ca62 MD |
21 | #include <string.h> |
22 | ||
bed864a7 | 23 | void ctf_string_copy(struct stream_pos *dest, struct stream_pos *src, |
f6625916 | 24 | const struct declaration_string *string_declaration) |
6dc2ca62 | 25 | { |
bed864a7 | 26 | size_t len; |
47e0f2e2 | 27 | char *destaddr, *srcaddr; |
6dc2ca62 | 28 | |
f6625916 | 29 | align_pos(src, string_declaration->p.alignment); |
bed864a7 MD |
30 | srcaddr = get_pos_addr(src); |
31 | len = strlen(srcaddr) + 1; | |
a52d7f6a | 32 | if (dest->dummy) |
6dc2ca62 | 33 | goto end; |
f6625916 | 34 | align_pos(dest, string_declaration->p.alignment); |
bed864a7 | 35 | destaddr = get_pos_addr(dest); |
a52d7f6a MD |
36 | strcpy(destaddr, srcaddr); |
37 | end: | |
bed864a7 | 38 | move_pos(dest, len); |
a52d7f6a MD |
39 | move_pos(src, len); |
40 | } | |
41 | ||
47e0f2e2 | 42 | void ctf_string_read(char **dest, struct stream_pos *src, |
f6625916 | 43 | const struct declaration_string *string_declaration) |
a52d7f6a MD |
44 | { |
45 | size_t len; | |
47e0f2e2 | 46 | char *srcaddr; |
a52d7f6a | 47 | |
f6625916 | 48 | align_pos(src, string_declaration->p.alignment); |
a52d7f6a MD |
49 | srcaddr = get_pos_addr(src); |
50 | len = strlen(srcaddr) + 1; | |
a52d7f6a | 51 | *dest = g_realloc(*dest, len); |
4c8bfb7e | 52 | strcpy(*dest, srcaddr); |
bed864a7 | 53 | move_pos(src, len); |
6dc2ca62 | 54 | } |
a52d7f6a | 55 | |
47e0f2e2 | 56 | void ctf_string_write(struct stream_pos *dest, const char *src, |
f6625916 | 57 | const struct declaration_string *string_declaration) |
a52d7f6a MD |
58 | { |
59 | size_t len; | |
47e0f2e2 | 60 | char *destaddr; |
a52d7f6a | 61 | |
f6625916 | 62 | align_pos(dest, string_declaration->p.alignment); |
a52d7f6a MD |
63 | len = strlen(src) + 1; |
64 | if (dest->dummy) | |
65 | goto end; | |
66 | destaddr = get_pos_addr(dest); | |
67 | strcpy(destaddr, src); | |
68 | end: | |
69 | move_pos(dest, len); | |
70 | } | |
71 | ||
47e0f2e2 | 72 | void ctf_string_free_temp(char *string) |
a52d7f6a MD |
73 | { |
74 | g_free(string); | |
75 | } |