Changeset 3394:e9e1f877b280 in roaraudio


Ignore:
Timestamp:
02/11/10 15:04:42 (10 years ago)
Author:
phi
Branch:
default
Message:

wrote memory functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroarpulse/xmalloc.c

    r3393 r3394  
    1 //*.c: 
     1//xmalloc.c: 
    22 
    33/* 
     
    3939#include <libroarpulse/libroarpulse.h> 
    4040 
     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 
    41101//ll 
Note: See TracChangeset for help on using the changeset viewer.