changeset 1166:f29fa5b6b748

Add dmMemset().
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Mar 2015 07:36:51 +0200
parents 737ae4718c8f
children 848a88ce7a57
files Makefile Makefile.cross-mingw src/dmlib.c src/dmlib.h
diffstat 4 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Thu Mar 05 07:27:54 2015 +0200
+++ b/Makefile	Thu Mar 05 07:36:51 2015 +0200
@@ -1,6 +1,8 @@
 #
 # Generic UNIX targets
 #
+DM_CFLAGS += -DDM_HAVE_MEMSET=1
+
 DMLIB ?= ./
 BINPATH ?= ./
 OBJPATH ?= ./obj/unix/
--- a/Makefile.cross-mingw	Thu Mar 05 07:27:54 2015 +0200
+++ b/Makefile.cross-mingw	Thu Mar 05 07:36:51 2015 +0200
@@ -2,6 +2,8 @@
 # For Win32/Win64 version cross-compilation via MinGW
 # compiler suite under Linux/Unix
 #
+DM_CFLAGS += -DDM_HAVE_MEMSET=1
+
 MINGW_PREFIX ?= i686-w64-mingw32-
 MINGW_PATH ?= /usr/i686-w64-mingw32
 
--- a/src/dmlib.c	Thu Mar 05 07:27:54 2015 +0200
+++ b/src/dmlib.c	Thu Mar 05 07:36:51 2015 +0200
@@ -113,6 +113,19 @@
 }
 
 
+#ifndef DM_HAVE_MEMSET
+void * dmMemset(void *ptr, const int c, size_t n)
+{
+    Uint8 *p = (Uint8 *) ptr;
+
+    while (n--)
+        *p++ = c;
+
+    return ptr;
+}
+#endif
+
+
 BOOL dmGetIntVal(const char *s, unsigned int *i)
 {
     if (s[0] == '$')
--- a/src/dmlib.h	Thu Mar 05 07:27:54 2015 +0200
+++ b/src/dmlib.h	Thu Mar 05 07:36:51 2015 +0200
@@ -399,6 +399,14 @@
 void *     dmRealloc(void *, size_t);
 void *     dmCalloc(size_t, size_t);
 void       dmFree(void *);
+#ifdef DM_HAVE_MEMSET
+static inline void * dmMemset(void *ptr, const int c, size_t n)
+{
+    return memset(ptr, c, n);
+}
+#else
+void *     dmMemset(void *ptr, const int c, size_t n);
+#endif
 
 char *     dm_strdup(const char *);
 char *     dm_strndup(const char *, const size_t n);