[freenos] [freenos commit] r167 - Replaced strndup() with malloc() and memcpy() in String.h for OpenBSD.

  • From: codesite-noreply@xxxxxxxxxx
  • To: freenos@xxxxxxxxxxxxx
  • Date: Mon, 29 Jun 2009 09:15:38 +0000

Author: nieklinnenbank
Date: Mon Jun 29 01:43:21 2009
New Revision: 167

Modified:
   trunk/include/String.h

Log:
Replaced strndup() with malloc() and memcpy() in String.h for OpenBSD.
OpenBSD doesn't have a native strndup() function, which is needed to
compile some of the host system applications and libraries.


Modified: trunk/include/String.h
==============================================================================
--- trunk/include/String.h      (original)
+++ trunk/include/String.h      Mon Jun 29 01:43:21 2009
@@ -85,7 +85,12 @@
         */
        String(const char *s, Size max)
        {
-           value = strndup(s, max);
+           size_t len = strlen(s);
+           if (len > max)
+               len = max;
+           value = (char *) malloc(len + 1);
+           memcpy(value, s, len + 1);
+           value[len] = ZERO;
        }

        /**

Other related posts:

  • » [freenos] [freenos commit] r167 - Replaced strndup() with malloc() and memcpy() in String.h for OpenBSD. - codesite-noreply