]> git.webhop.me Git - lcd4linux.git/commitdiff
strndup() replacement
authormichael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Sun, 17 Jun 2007 06:06:19 +0000 (06:06 +0000)
committermichael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Sun, 17 Jun 2007 06:06:19 +0000 (06:06 +0000)
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@805 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

evaluator.c

index aaebee971308c0d094550723eea12da2e2349470..958ed6e2f1afa39dab3c338358a34529d26fb4d5 100644 (file)
@@ -199,6 +199,30 @@ static FUNCTION *Function = NULL;
 static unsigned int nFunction = 0;
 
 
+/* strndup() may be not available on several platforms */
+#ifndef HAVE_STRNDUP
+char *strndup(const char *source, size_t len)
+{
+    char *tmp = NULL;
+
+    if (source == NULL)
+       return NULL;
+
+    if (len >= strlen(source))
+       return strdup(source);
+
+    tmp = malloc(len + 1);
+    if (tmp == 0)
+       return NULL;
+
+    strncpy(tmp, source, len);
+    tmp[len] = '\0';
+
+    return (tmp);
+}
+#endif
+
+
 void DelResult(RESULT * result)
 {
     result->type = 0;