2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
32 #include <pulse/gccmacro.h>
33 #include <pulsecore/core-util.h>
34 #include <pulsecore/macro.h>
38 /* Make sure not to allocate more than this much memory. */
39 #define MAX_ALLOC_SIZE (1024*1024*96) /* 96MB */
47 static void oom(void) PA_GCC_NORETURN
;
49 /* called in case of an OOM situation. Prints an error message and
51 static void oom(void) {
52 static const char e
[] = "Not enough memory\n";
53 pa_loop_write(STDERR_FILENO
, e
, sizeof(e
)-1, NULL
);
60 void* pa_xmalloc(size_t size
) {
63 pa_assert(size
< MAX_ALLOC_SIZE
);
65 if (!(p
= malloc(size
)))
71 void* pa_xmalloc0(size_t size
) {
74 pa_assert(size
< MAX_ALLOC_SIZE
);
76 if (!(p
= calloc(1, size
)))
82 void *pa_xrealloc(void *ptr
, size_t size
) {
85 pa_assert(size
< MAX_ALLOC_SIZE
);
87 if (!(p
= realloc(ptr
, size
)))
92 void* pa_xmemdup(const void *p
, size_t l
) {
96 char *r
= pa_xmalloc(l
);
102 char *pa_xstrdup(const char *s
) {
106 return pa_xmemdup(s
, strlen(s
)+1);
109 char *pa_xstrndup(const char *s
, size_t l
) {
115 if ((e
= memchr(s
, 0, l
)))
116 return pa_xmemdup(s
, (size_t) (e
-s
+1));
124 void pa_xfree(void *p
) {