From 2fcc2950e43cba7cd677057cde39c2766848616f Mon Sep 17 00:00:00 2001 From: michael Date: Sun, 17 Jun 2007 06:06:19 +0000 Subject: strndup() replacement git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@805 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- evaluator.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'evaluator.c') diff --git a/evaluator.c b/evaluator.c index aaebee9..958ed6e 100644 --- a/evaluator.c +++ b/evaluator.c @@ -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; -- cgit v1.2.3