source: roaraudio/libroarpulse/xmalloc.c @ 4960:60cdebcb83ef

Last change on this file since 4960:60cdebcb83ef was 4708:c9d40761088a, checked in by phi, 13 years ago

updated copyright statements

File size: 2.9 KB
Line 
1//xmalloc.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2011
5 *  The code (may) include prototypes and comments (and maybe
6 *  other code fragements) from libpulse*. They are mostly copyrighted by:
7 *  Lennart Poettering <poettering@users.sourceforge.net> and
8 *  Pierre Ossman <drzeus@drzeus.cx>
9 *
10 *  This file is part of libroarpulse a part of RoarAudio,
11 *  a cross-platform sound system for both, home and professional use.
12 *  See README for details.
13 *
14 *  This file is free software; you can redistribute it and/or modify
15 *  it under the terms of the GNU General Public License version 3
16 *  as published by the Free Software Foundation.
17 *
18 *  RoarAudio is distributed in the hope that it will be useful,
19 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 *  GNU General Public License for more details.
22 *
23 *  You should have received a copy of the GNU General Public License
24 *  along with this software; see the file COPYING.  If not, write to
25 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
26 *  Boston, MA 02110-1301, USA.
27 *
28 *  NOTE for everyone want's to change something and send patches:
29 *  read README and HACKING! There a addition information on
30 *  the license of this document you need to read before you send
31 *  any patches.
32 *
33 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
34 *  or libpulse*:
35 *  The libs libroaresd, libroararts and libroarpulse link this libroar
36 *  and are therefore GPL. Because of this it may be illigal to use
37 *  them with any software that uses libesd, libartsc or libpulse*.
38 */
39
40#include <libroarpulse/libroarpulse.h>
41
42/** Allocate the specified number of bytes, just like malloc() does. However, in case of OOM, terminate */
43void* pa_xmalloc(size_t l) {
44 return roar_mm_malloc(l);
45}
46
47/** Same as pa_xmalloc(), but initialize allocated memory to 0 */
48void *pa_xmalloc0(size_t l) {
49 void * data = roar_mm_malloc(l);
50
51 if ( data == NULL )
52  return NULL;
53
54 memset(data, 0, l);
55
56 return data;
57}
58
59/**  The combination of pa_xmalloc() and realloc() */
60void *pa_xrealloc(void *ptr, size_t size) {
61 return roar_mm_realloc(ptr, size);
62}
63
64/** Free allocated memory */
65void pa_xfree(void *p) {
66 return roar_mm_free(p);
67}
68
69/** Duplicate the specified string, allocating memory with pa_xmalloc() */
70char *pa_xstrdup(const char *s) {
71 return roar_mm_strdup(s);
72}
73
74/** Duplicate the specified string, but truncate after l characters */
75char *pa_xstrndup(const char *s, size_t l) {
76 size_t i;
77 char * data;
78
79 for (i = 0; i < l && s[i] != 0; i++);
80
81 if ( (data = roar_mm_malloc(i+1)) == NULL )
82  return NULL;
83
84 memcpy(data, s, i);
85 data[i] = 0;
86
87 return data;
88}
89
90/** Duplicate the specified memory block */
91void* pa_xmemdup(const void *p, size_t l) {
92 void * data = roar_mm_malloc(l);
93
94 if ( data == NULL )
95  return NULL;
96
97 memcpy(data, p, l);
98
99 return data;
100}
101
102//ll
Note: See TracBrowser for help on using the repository browser.