Pass SYSCONFDIR from makefile to workaround autoconf issue
[platform/adaptation/samsung_exynos/audio-hal-wm1831-tw2.git] / tizen-audio-util.c
1 /*
2  * audio-hal
3  *
4  * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "tizen-audio-internal.h"
29
30 /* ------ dump helper --------  */
31 #define MAX(a, b) ((a) > (b) ? (a) : (b))
32
33 dump_data_t* _audio_dump_new(int length)
34 {
35     dump_data_t* dump = NULL;
36
37     if ((dump = malloc(sizeof(dump_data_t)))) {
38         memset(dump, 0, sizeof(dump_data_t));
39         if ((dump->strbuf = malloc(length))) {
40             dump->p = &dump->strbuf[0];
41             dump->left = length;
42         } else {
43             free(dump);
44             dump = NULL;
45         }
46     }
47
48     return dump;
49 }
50
51 void _audio_dump_add_str(dump_data_t *dump, const char *fmt, ...)
52 {
53     int len;
54     va_list ap;
55
56     if (!dump)
57         return;
58
59     va_start(ap, fmt);
60     len = vsnprintf(dump->p, dump->left, fmt, ap);
61     va_end(ap);
62
63     dump->p += MAX(0, len);
64     dump->left -= MAX(0, len);
65 }
66
67 char* _audio_dump_get_str(dump_data_t *dump)
68 {
69     return (dump) ? dump->strbuf : NULL;
70 }
71
72 void _audio_dump_free(dump_data_t *dump)
73 {
74     if (dump) {
75         if (dump->strbuf)
76             free(dump->strbuf);
77         free(dump);
78     }
79 }
80 /* ------ dump helper --------  */