Babeltrace type: build warning cleanup
[babeltrace.git] / types / string.c
CommitLineData
bed864a7 1/*
ccd7e1c8 2 * string.c
bed864a7 3 *
ccd7e1c8 4 * BabelTrace - String Type Converter
bed864a7 5 *
ccd7e1c8 6 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
bed864a7 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:
bed864a7 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.
bed864a7
MD
17 */
18
19#include <babeltrace/compiler.h>
20#include <babeltrace/align.h>
4c8bfb7e 21#include <babeltrace/format.h>
bed864a7
MD
22
23void string_copy(struct stream_pos *dest, const struct format *fdest,
24 struct stream_pos *src, const struct format *fsrc,
25 const struct type_class *type_class)
26{
27 struct type_class_string *string_class =
28 container_of(type_class, struct type_class_string, p);
29
30 if (fsrc->string_copy == fdest->string_copy) {
31 fsrc->string_copy(dest, src, string_class);
32 } else {
a52d7f6a
MD
33 unsigned char *tmp = NULL;
34
35 fsrc->string_read(&tmp, src, string_class);
36 fdest->string_write(dest, tmp, string_class);
37 fsrc->string_free_temp(tmp);
bed864a7
MD
38 }
39}
40
41void string_type_free(struct type_class_string *string_class)
42{
43 g_free(string_class);
44}
45
46static void _string_type_free(struct type_class *type_class)
47{
48 struct type_class_string *string_class =
49 container_of(type_class, struct type_class_string, p);
50 string_type_free(string_class);
51}
52
53struct type_class_string *string_type_new(const char *name)
54{
55 struct type_class_string *string_class;
56 int ret;
57
58 string_class = g_new(struct type_class_string, 1);
59 string_class->p.name = g_quark_from_string(name);
60 string_class->p.alignment = CHAR_BIT;
61 string_class->p.copy = string_copy;
62 string_class->p.free = _string_type_free;
4c8bfb7e 63 string_class->p.ref = 1;
bed864a7 64 if (string_class->p.name) {
be85c1c7 65 ret = register_type(&string_class->p);
bed864a7
MD
66 if (ret) {
67 g_free(string_class);
68 return NULL;
69 }
70 }
71 return string_class;
72}
This page took 0.024962 seconds and 4 git commands to generate.