Rename: type_class, type -> type, declaration
[babeltrace.git] / formats / ctf / types / string.c
1 /*
2 * Common Trace Format
3 *
4 * Strings read/write functions.
5 *
6 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
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:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 */
18
19 #include <babeltrace/ctf/types.h>
20 #include <limits.h> /* C99 limits */
21 #include <string.h>
22
23 void ctf_string_copy(struct stream_pos *dest, struct stream_pos *src,
24 const struct type_string *string_type)
25 {
26 size_t len;
27 char *destaddr, *srcaddr;
28
29 align_pos(src, string_type->p.alignment);
30 srcaddr = get_pos_addr(src);
31 len = strlen(srcaddr) + 1;
32 if (dest->dummy)
33 goto end;
34 align_pos(dest, string_type->p.alignment);
35 destaddr = get_pos_addr(dest);
36 strcpy(destaddr, srcaddr);
37 end:
38 move_pos(dest, len);
39 move_pos(src, len);
40 }
41
42 void ctf_string_read(char **dest, struct stream_pos *src,
43 const struct type_string *string_type)
44 {
45 size_t len;
46 char *srcaddr;
47
48 align_pos(src, string_type->p.alignment);
49 srcaddr = get_pos_addr(src);
50 len = strlen(srcaddr) + 1;
51 *dest = g_realloc(*dest, len);
52 strcpy(*dest, srcaddr);
53 move_pos(src, len);
54 }
55
56 void ctf_string_write(struct stream_pos *dest, const char *src,
57 const struct type_string *string_type)
58 {
59 size_t len;
60 char *destaddr;
61
62 align_pos(dest, string_type->p.alignment);
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
72 void ctf_string_free_temp(char *string)
73 {
74 g_free(string);
75 }
This page took 0.030467 seconds and 4 git commands to generate.