source: roaraudio/libroarpulse/xmalloc.c @ 3466:6d461930b82b

Last change on this file since 3466:6d461930b82b was 3394:e9e1f877b280, checked in by phi, 10 years ago

wrote memory functions

File size: 2.9 KB
Line 
1//xmalloc.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
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, 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 *  NOTE for everyone want's to change something and send patches:
28 *  read README and HACKING! There a addition information on
29 *  the license of this document you need to read before you send
30 *  any patches.
31 *
32 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
33 *  or libpulse*:
34 *  The libs libroaresd, libroararts and libroarpulse link this libroar
35 *  and are therefore GPL. Because of this it may be illigal to use
36 *  them with any software that uses libesd, libartsc or libpulse*.
37 */
38
39#include <libroarpulse/libroarpulse.h>
40
41/** Allocate the specified number of bytes, just like malloc() does. However, in case of OOM, terminate */
42void* pa_xmalloc(size_t l) {
43 return roar_mm_malloc(l);
44}
45
46/** Same as pa_xmalloc(), but initialize allocated memory to 0 */
47void *pa_xmalloc0(size_t l) {
48 void * data = roar_mm_malloc(l);
49
50 if ( data == NULL )
51  return NULL;
52
53 memset(data, 0, l);
54
55 return data;
56}
57
58/**  The combination of pa_xmalloc() and realloc() */
59void *pa_xrealloc(void *ptr, size_t size) {
60 return roar_mm_realloc(ptr, size);
61}
62
63/** Free allocated memory */
64void pa_xfree(void *p) {
65 return roar_mm_free(p);
66}
67
68/** Duplicate the specified string, allocating memory with pa_xmalloc() */
69char *pa_xstrdup(const char *s) {
70 return roar_mm_strdup(s);
71}
72
73/** Duplicate the specified string, but truncate after l characters */
74char *pa_xstrndup(const char *s, size_t l) {
75 size_t i;
76 char * data;
77
78 for (i = 0; i < l && s[i] != 0; i++);
79
80 if ( (data = roar_mm_malloc(i+1)) == NULL )
81  return NULL;
82
83 memcpy(data, s, i);
84 data[i] = 0;
85
86 return data;
87}
88
89/** Duplicate the specified memory block */
90void* pa_xmemdup(const void *p, size_t l) {
91 void * data = roar_mm_malloc(l);
92
93 if ( data == NULL )
94  return NULL;
95
96 memcpy(data, p, l);
97
98 return data;
99}
100
101//ll
Note: See TracBrowser for help on using the repository browser.