Open Broadcaster Software
Free, open source software for live streaming and recording
bmem.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2013 Hugh Bailey <obs.jim@gmail.com>
3
*
4
* Permission to use, copy, modify, and distribute this software for any
5
* purpose with or without fee is hereby granted, provided that the above
6
* copyright notice and this permission notice appear in all copies.
7
*
8
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
*/
16
17
#pragma once
18
19
#include "
c99defs.h
"
20
#include "
base.h
"
21
#include <wchar.h>
22
#include <string.h>
23
24
#ifdef __cplusplus
25
extern
"C"
{
26
#endif
27
28
struct
base_allocator
{
29
void
*(*malloc)(size_t);
30
void
*(*realloc)(
void
*, size_t);
31
void (*
free
)(
void
*);
32
};
33
34
EXPORT
void
base_set_allocator
(
struct
base_allocator
*defs);
35
36
EXPORT
void
*
bmalloc
(
size_t
size);
37
EXPORT
void
*
brealloc
(
void
*ptr,
size_t
size);
38
EXPORT
void
bfree
(
void
*ptr);
39
40
EXPORT
int
base_get_alignment
(
void
);
41
42
EXPORT
long
bnum_allocs
(
void
);
43
44
EXPORT
void
*
bmemdup
(
const
void
*ptr,
size_t
size);
45
46
static
inline
void
*bzalloc(
size_t
size)
47
{
48
void
*mem =
bmalloc
(size);
49
if
(mem)
50
memset(mem, 0, size);
51
return
mem;
52
}
53
54
static
inline
char
*bstrdup_n(
const
char
*str,
size_t
n)
55
{
56
char
*dup;
57
if
(!str)
58
return
NULL;
59
60
dup = (
char
*)
bmemdup
(str, n + 1);
61
dup[n] = 0;
62
63
return
dup;
64
}
65
66
static
inline
wchar_t
*bwstrdup_n(
const
wchar_t
*str,
size_t
n)
67
{
68
wchar_t
*dup;
69
if
(!str)
70
return
NULL;
71
72
dup = (
wchar_t
*)
bmemdup
(str, (n + 1) *
sizeof
(wchar_t));
73
dup[n] = 0;
74
75
return
dup;
76
}
77
78
static
inline
char
*bstrdup(
const
char
*str)
79
{
80
if
(!str)
81
return
NULL;
82
83
return
bstrdup_n(str, strlen(str));
84
}
85
86
static
inline
wchar_t
*bwstrdup(
const
wchar_t
*str)
87
{
88
if
(!str)
89
return
NULL;
90
91
return
bwstrdup_n(str, wcslen(str));
92
}
93
94
#ifdef __cplusplus
95
}
96
#endif
brealloc
EXPORT void * brealloc(void *ptr, size_t size)
base_allocator::free
void(* free)(void *)
Definition:
bmem.h:31
bnum_allocs
EXPORT long bnum_allocs(void)
bmemdup
EXPORT void * bmemdup(const void *ptr, size_t size)
bfree
EXPORT void bfree(void *ptr)
EXPORT
#define EXPORT
Definition:
c99defs.h:37
base.h
c99defs.h
base_allocator
Definition:
bmem.h:28
bmalloc
EXPORT void * bmalloc(size_t size)
base_set_allocator
EXPORT void base_set_allocator(struct base_allocator *defs)
base_get_alignment
EXPORT int base_get_alignment(void)
libobs
util
bmem.h
Generated on Sat Sep 26 2020 00:00:00 for Open Broadcaster Software by
1.8.20