aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-07-15 00:39:01 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-07-15 00:39:01 +0000
commit4903f50fe80f104312ba89e7481ceedd49f39fd8 (patch)
tree991a3938a32d6c27484076dd80d878ebad6f9010
parentcf67ae6727542678c4c23782af7c6418ec3290a7 (diff)
first phase of proper fix for portable string function problems (bug #4669)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6133 f38db490-d61c-443f-a65b-d21fe96a405b
-rwxr-xr-xMakefile2
-rwxr-xr-xchannel.c10
-rwxr-xr-xinclude/asterisk/strings.h10
-rwxr-xr-xutils.c26
4 files changed, 35 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index afdbcafbc..ba0912feb 100755
--- a/Makefile
+++ b/Makefile
@@ -249,7 +249,7 @@ LIBS+=-lresolv
CFLAGS+=-D__Darwin__
endif
ifeq (${OSARCH},FreeBSD)
-LIBS+=-lcrypto -lstrfunc
+LIBS+=-lcrypto
endif
ifeq (${OSARCH},NetBSD)
LIBS+=-lpthread -lcrypto -lm -L$(CROSS_COMPILE_TARGET)/usr/local/lib -L$(CROSS_COMPILE_TARGET)/usr/pkg/lib -lncurses
diff --git a/channel.c b/channel.c
index 2bfe485e2..ae9d98f6b 100755
--- a/channel.c
+++ b/channel.c
@@ -31,12 +31,6 @@
#error "You need newer zaptel! Please cvs update zaptel"
#endif
#endif
-#ifdef __FreeBSD__
-#include <strfunc.h>
-#if (!defined(__STRFUNC_H__) && (!defined(STRFUNC_H)))
-#error "Please install the strfunc library located in the ports collection at /usr/ports/devel/libstrfunc"
-#endif
-#endif
#include "asterisk.h"
@@ -1759,8 +1753,8 @@ char *ast_recvtext(struct ast_channel *chan, int timeout)
break; /* no frame */
if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP)
done = 1; /* force a break */
- else if (f->frametype == AST_FRAME_TEXT) { /* what we want */
- buf = strndup((char *)f->data, f->datalen); /* dup and break */
+ else if (f->frametype == AST_FRAME_TEXT) { /* what we want */
+ buf = ast_strndup((char *) f->data, f->datalen); /* dup and break */
done = 1;
}
ast_frfree(f);
diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h
index 2b845a837..f6902ef1b 100755
--- a/include/asterisk/strings.h
+++ b/include/asterisk/strings.h
@@ -199,8 +199,12 @@ struct ast_realloca {
#ifdef __linux__
#define ast_strcasestr strcasestr
-#else
-extern char *ast_strcasestr(const char *, const char *);
-#endif /* __linux__ */
+#define ast_strndup strndup
+#define ast_strnlen strnlen
+#else /* !__linux__ */
+char *ast_strcasestr(const char *, const char *);
+char *ast_strndup(const char *, size_t);
+size_t ast_strnlen(const char *, size_t);
+#endif /* !__linux__ */
#endif /* _ASTERISK_STRINGS_H */
diff --git a/utils.c b/utils.c
index 1319f71b9..72b7f9be6 100755
--- a/utils.c
+++ b/utils.c
@@ -535,4 +535,28 @@ char *ast_strcasestr(const char *haystack, const char *needle)
return NULL;
}
}
-#endif /* LINUX */
+
+size_t ast_strnlen(const char *s, size_t n)
+{
+ size_t len;
+
+ for (len=0; len < n; len++)
+ if (s[len] == '\0')
+ break;
+
+ return len;
+}
+
+char *ast_strndup(const char *s, size_t n)
+{
+ size_t len = ast_strnlen(s, n);
+ char *new = malloc(len + 1);
+
+ if (!new)
+ return NULL;
+
+ new[len] = '\0';
+ return memcpy(new, s, len);
+}
+
+#endif /* !LINUX */