Use inheritance for trace descriptor and positions
[babeltrace.git] / formats / ctf / types / string.c
... / ...
CommitLineData
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
23void ctf_string_copy(struct stream_pos *pdest, struct stream_pos *psrc,
24 const struct declaration_string *string_declaration)
25{
26 struct ctf_stream_pos *dest = ctf_pos(pdest);
27 struct ctf_stream_pos *src = ctf_pos(psrc);
28 size_t len;
29 char *destaddr, *srcaddr;
30
31 ctf_align_pos(src, string_declaration->p.alignment);
32 srcaddr = ctf_get_pos_addr(src);
33 len = strlen(srcaddr) + 1;
34 if (dest->dummy)
35 goto end;
36 ctf_align_pos(dest, string_declaration->p.alignment);
37 destaddr = ctf_get_pos_addr(dest);
38 strcpy(destaddr, srcaddr);
39end:
40 ctf_move_pos(dest, len);
41 ctf_move_pos(src, len);
42}
43
44void ctf_string_read(char **dest, struct stream_pos *psrc,
45 const struct declaration_string *string_declaration)
46{
47 struct ctf_stream_pos *src = ctf_pos(psrc);
48 size_t len;
49 char *srcaddr;
50
51 ctf_align_pos(src, string_declaration->p.alignment);
52 srcaddr = ctf_get_pos_addr(src);
53 len = strlen(srcaddr) + 1;
54 *dest = g_realloc(*dest, len);
55 strcpy(*dest, srcaddr);
56 ctf_move_pos(src, len);
57}
58
59void ctf_string_write(struct stream_pos *pdest, const char *src,
60 const struct declaration_string *string_declaration)
61{
62 struct ctf_stream_pos *dest = ctf_pos(pdest);
63 size_t len;
64 char *destaddr;
65
66 ctf_align_pos(dest, string_declaration->p.alignment);
67 len = strlen(src) + 1;
68 if (dest->dummy)
69 goto end;
70 destaddr = ctf_get_pos_addr(dest);
71 strcpy(destaddr, src);
72end:
73 ctf_move_pos(dest, len);
74}
75
76void ctf_string_free_temp(char *string)
77{
78 g_free(string);
79}
This page took 0.022641 seconds and 4 git commands to generate.