Index: ChangeLog
===================================================================
--- ChangeLog	(revision 4956)
+++ ChangeLog	(revision 4958)
@@ -10,4 +10,5 @@
 	* Done some libroardsp header cleanup (Closes: #36)
 	* Use zlib for gzip and zlib format (Closes: #29)
+	* Added simple memmgr (memory Manager) code.
 
 v. 0.4beta5 - Tue Apr 26 2011 08:42 CEST
Index: configure
===================================================================
--- configure	(revision 4941)
+++ configure	(revision 4958)
@@ -1512,4 +1512,12 @@
 
 #                 def                 name      call                         -- header
+test_func_defmake ROAR_HAVE_MALLOC    malloc    'malloc(0)'                  -- stdlib.h
+test_func_defmake ROAR_HAVE_CALLOC    calloc    'calloc(0, 0)'               -- stdlib.h
+test_func_defmake ROAR_HAVE_REALLOC   realloc   'realloc((void*)0, 0)'       -- stdlib.h
+test_func_defmake ROAR_HAVE_FREE      free      'free((void*)0)'             -- stdlib.h
+test_func_defmake ROAR_HAVE_STRDUP    strdup    'strdup((void*)0)'           -- string.h
+test_func_defmake ROAR_HAVE_STRNDUP   strndup   'strndup((void*)0)'          -- string.h
+test_func_defmake ROAR_HAVE_STRLEN    strlen    'strlen((void*)0)'           -- string.h
+test_func_defmake ROAR_HAVE_STRNLEN   strnlen   'strnlen((void*)0)'          -- string.h
 test_func_defmake ROAR_HAVE_SETENV    setenv    'setenv("", "", 0)'          -- stdlib.h
 test_func_defmake ROAR_HAVE_PUTENV    putenv    'putenv("")'                 -- stdlib.h
Index: include/libroar/memmgr.h
===================================================================
--- include/libroar/memmgr.h	(revision 4790)
+++ include/libroar/memmgr.h	(revision 4958)
@@ -39,11 +39,16 @@
 #include "libroar.h"
 
+#ifndef ROAR_USE_MEMMGR
+#if !defined(ROAR_HAVE_MALLOC) || !defined(ROAR_HAVE_CALLOC) || !defined(ROAR_HAVE_REALLOC) || !defined(ROAR_HAVE_FREE)
+#define ROAR_USE_MEMMGR
+#endif
+#endif
+
 #ifdef ROAR_USE_MEMMGR
 // those functions are currently not implemeted:
 void * roar_mm_calloc(size_t nmemb, size_t size);
 void * roar_mm_malloc(size_t size);
-void   roar_mm_free(void *ptr);
+int    roar_mm_free(void *ptr);
 void * roar_mm_realloc(void *ptr, size_t size);
-char * roar_mm_strdup(const char *s);
 
 /*
@@ -57,5 +62,4 @@
 #define roar_mm_free(ptr)           free((ptr))
 #define roar_mm_realloc(ptr, size)  realloc((ptr), (size))
-#define roar_mm_strdup(str)         strdup((str))
 #endif
 
@@ -101,4 +105,25 @@
 void * roar_mm_memdup(const void * s, size_t len);
 
+// string functions:
+#ifndef ROAR_HAVE_STRLEN
+ssize_t roar_mm_strlen(const char *s);
+#else
+#define roar_mm_strlen(str) strlen((str))
+#endif
+
+ssize_t roar_mm_strnlen(const char *s, size_t maxlen);
+
+#if defined(ROAR_USE_MEMMGR) || !defined(ROAR_HAVE_STRDUP)
+char * roar_mm_strdup(const char *s);
+#else
+#define roar_mm_strdup(str)         strdup((str))
+#endif
+
+#if defined(ROAR_USE_MEMMGR) || !defined(ROAR_HAVE_STRNDUP)
+char *roar_mm_strndup(const char *s, size_t n);
+#else
+#define roar_mm_strndup(str, size)         strdup((str), (size))
+#endif
+
 #endif
 
Index: libroar/Makefile
===================================================================
--- libroar/Makefile	(revision 4956)
+++ libroar/Makefile	(revision 4958)
@@ -11,5 +11,5 @@
 PASSWORD=passwordapi.o pinentry.o sshaskpass.o
 CRYPTO=crypto.o random.o $(HASHES) crc.o
-OBJS=libroar.o config.o debug.o error.o basic.o stream.o client.o simple.o auth.o socket.o ctl.o buffer.o meta.o file.o acl.o cdrom.o $(PASSWORD) $(VIO) stack.o slp.o nnode.o roardl.o roarx11.o beep.o proto.o env.o keyval.o vs.o ltm.o notify.o notify_proxy.o asyncctl.o enumdev.o serverinfo.o $(CRYPTO) authfile.o caps.o roarfloat.o base64.o trap.o
+OBJS=libroar.o config.o debug.o error.o basic.o stream.o client.o simple.o auth.o socket.o ctl.o buffer.o meta.o file.o acl.o cdrom.o $(PASSWORD) $(VIO) stack.o slp.o nnode.o roardl.o roarx11.o beep.o proto.o env.o keyval.o vs.o ltm.o notify.o notify_proxy.o asyncctl.o enumdev.o serverinfo.o $(CRYPTO) authfile.o caps.o roarfloat.o base64.o trap.o memmgr.o
 
 #DEFINES        = -DDEBUG
Index: libroar/libroar.c
===================================================================
--- libroar/libroar.c	(revision 4945)
+++ libroar/libroar.c	(revision 4958)
@@ -99,15 +99,4 @@
 }
 
-void * roar_mm_memdup(const void * s, size_t len) {
- void * ret = roar_mm_malloc(len);
-
- if ( ret == NULL )
-  return NULL;
-
- memcpy(ret, s, len);
-
- return ret;
-}
-
 int roar_usleep(uint_least32_t t) {
 #ifdef ROAR_TARGET_WIN32
Index: libroar/memmgr.c
===================================================================
--- libroar/memmgr.c	(revision 4958)
+++ libroar/memmgr.c	(revision 4958)
@@ -0,0 +1,246 @@
+//memmgr.c:
+
+/*
+ *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2011
+ *
+ *  This file is part of libroar a part of RoarAudio,
+ *  a cross-platform sound system for both, home and professional use.
+ *  See README for details.
+ *
+ *  This file is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 3
+ *  as published by the Free Software Foundation.
+ *
+ *  libroar is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ *
+ *  NOTE for everyone want's to change something and send patches:
+ *  read README and HACKING! There a addition information on
+ *  the license of this document you need to read before you send
+ *  any patches.
+ *
+ *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
+ *  or libpulse*:
+ *  The libs libroaresd, libroararts and libroarpulse link this lib
+ *  and are therefore GPL. Because of this it may be illigal to use
+ *  them with any software that uses libesd, libartsc or libpulse*.
+ */
+
+#include "libroar.h"
+
+#ifdef ROAR_USE_MEMMGR
+static char _libroar_null_buffer[8] = {0, 0, 0, 0, 0, 0, 0, 0};
+#endif
+
+#define _err(x) do { roar_err_set((x)); return NULL; } while (0)
+
+#ifdef ROAR_USE_MEMMGR
+void * roar_mm_calloc(size_t nmemb, size_t size) {
+ void * ret;
+
+ if ( nmemb == 0 || size == 0 )
+  return _libroar_null_buffer;
+
+#ifdef ROAR_HAVE_CALLOC
+ roar_err_clear_all();
+ ret = calloc(nmemb, size);
+
+ if ( ret == NULL )
+  roar_err_update();
+
+ return ret;
+#else
+ ret = roar_mm_malloc(nmemb*size);
+ if ( ret == NULL )
+  return NULL;
+
+ memset(ret, 0, nmemb*size);
+
+ return ret;
+#endif
+}
+
+void * roar_mm_malloc(size_t size) {
+ void * ret;
+
+ if ( size == 0 )
+  return _libroar_null_buffer;
+
+#ifdef ROAR_HAVE_MALLOC
+ roar_err_clear_all();
+ ret = malloc(size);
+
+ if ( ret == NULL )
+  roar_err_update();
+
+ return ret;
+#elif defined(ROAR_HAVE_CALLOC)
+ return roar_mm_calloc(1, size);
+#elif defined(ROAR_HAVE_REALLOC)
+ return roar_mm_realloc(NULL, size);
+#else
+ _err(ROAR_ERROR_NOSYS);
+#endif
+}
+
+int    roar_mm_free(void *ptr) {
+ if ( ptr == _libroar_null_buffer )
+  return 0;
+
+#ifdef ROAR_HAVE_FREE
+ free(ptr);
+ return 0;
+#elif defined(ROAR_HAVE_REALLOC)
+ if ( roar_mm_realloc(ptr, 0) != _libroar_null_buffer )
+  return -1;
+ return 0;
+#else
+ roar_err_set(ROAR_ERROR_NOSYS);
+ return -1;
+#endif
+}
+
+void * roar_mm_realloc(void *ptr, size_t size) {
+#ifdef ROAR_HAVE_REALLOC
+ void * ret;
+#endif
+
+ if ( ptr == NULL )
+  return roar_mm_malloc(size);
+
+ if ( size == 0 ) {
+  roar_mm_free(ptr);
+  return _libroar_null_buffer;
+ }
+
+#ifdef ROAR_HAVE_REALLOC
+ roar_err_clear_all();
+ ret = realloc(ptr, size);
+
+ if ( ret == NULL )
+  roar_err_update();
+
+ return ret;
+#else
+ _err(ROAR_ERROR_NOTSUP);
+#endif
+}
+#endif
+
+void * roar_mm_memdup(const void * s, size_t len) {
+ void * ret;
+
+ if ( s == NULL )
+  _err(ROAR_ERROR_FAULT);
+
+ ret = roar_mm_malloc(len);
+
+ if ( ret == NULL )
+  return NULL;
+
+ memcpy(ret, s, len);
+
+ return ret;
+}
+
+#if defined(ROAR_USE_MEMMGR) || !defined(ROAR_HAVE_STRDUP)
+char * roar_mm_strdup(const char *s) {
+ void * ret;
+#ifndef ROAR_HAVE_STRDUP
+ ssize_t len;
+#endif
+
+ if ( s == NULL )
+  _err(ROAR_ERROR_FAULT);
+
+#ifdef ROAR_HAVE_STRDUP
+ roar_err_clear_all();
+ ret = strdup(s);
+
+ if ( ret == NULL )
+  roar_err_update();
+#else
+ len = roar_mm_strlen(s);
+ if ( len == -1 )
+  return NULL;
+
+ ret = roar_mm_memdup(s, len+1);
+#endif
+
+ return ret;
+}
+#endif
+
+#if defined(ROAR_USE_MEMMGR) || !defined(ROAR_HAVE_STRNDUP)
+char *roar_mm_strndup(const char *s, size_t n) {
+ void * ret;
+#ifndef ROAR_HAVE_STRDUP
+ ssize_t len;
+#endif
+
+ if ( s == NULL )
+  _err(ROAR_ERROR_FAULT);
+
+#ifdef ROAR_HAVE_STRDUP
+ roar_err_clear_all();
+ ret = strndup(s, n);
+
+ if ( ret == NULL )
+  roar_err_update();
+#else
+ len = roar_mm_strnlen(s, n);
+ if ( len == -1 )
+  return NULL;
+
+ ret = roar_mm_memdup(s, len+1);
+#endif
+
+ return ret;
+}
+#endif
+
+#ifndef ROAR_HAVE_STRLEN
+ssize_t roar_mm_strlen(const char *s) {
+ size_t ret = 0;
+
+ if ( s == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ for (; *s != 0; s++, ret++);
+
+ return ret;
+}
+#endif
+
+ssize_t roar_mm_strnlen(const char *s, size_t maxlen) {
+ size_t ret = 0;
+
+ if ( s == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+#ifdef ROAR_HAVE_STRNLEN
+ ret = strnlen(s, maxlen);
+#else
+ for (; ret < maxlen && *s != 0; s++, ret++);
+#endif
+
+ if ( ret == maxlen ) {
+  roar_err_set(ROAR_ERROR_ILLSEQ);
+  return -1;
+ }
+
+ return ret;
+}
+
+//ll
