mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 12:36:58 +00:00
first phase of proper fix for portable string function problems (bug #4669)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6133 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
2
Makefile
2
Makefile
@@ -249,7 +249,7 @@ LIBS+=-lresolv
|
|||||||
CFLAGS+=-D__Darwin__
|
CFLAGS+=-D__Darwin__
|
||||||
endif
|
endif
|
||||||
ifeq (${OSARCH},FreeBSD)
|
ifeq (${OSARCH},FreeBSD)
|
||||||
LIBS+=-lcrypto -lstrfunc
|
LIBS+=-lcrypto
|
||||||
endif
|
endif
|
||||||
ifeq (${OSARCH},NetBSD)
|
ifeq (${OSARCH},NetBSD)
|
||||||
LIBS+=-lpthread -lcrypto -lm -L$(CROSS_COMPILE_TARGET)/usr/local/lib -L$(CROSS_COMPILE_TARGET)/usr/pkg/lib -lncurses
|
LIBS+=-lpthread -lcrypto -lm -L$(CROSS_COMPILE_TARGET)/usr/local/lib -L$(CROSS_COMPILE_TARGET)/usr/pkg/lib -lncurses
|
||||||
|
10
channel.c
10
channel.c
@@ -31,12 +31,6 @@
|
|||||||
#error "You need newer zaptel! Please cvs update zaptel"
|
#error "You need newer zaptel! Please cvs update zaptel"
|
||||||
#endif
|
#endif
|
||||||
#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"
|
#include "asterisk.h"
|
||||||
|
|
||||||
@@ -1759,8 +1753,8 @@ char *ast_recvtext(struct ast_channel *chan, int timeout)
|
|||||||
break; /* no frame */
|
break; /* no frame */
|
||||||
if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP)
|
if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP)
|
||||||
done = 1; /* force a break */
|
done = 1; /* force a break */
|
||||||
else if (f->frametype == AST_FRAME_TEXT) { /* what we want */
|
else if (f->frametype == AST_FRAME_TEXT) { /* what we want */
|
||||||
buf = strndup((char *)f->data, f->datalen); /* dup and break */
|
buf = ast_strndup((char *) f->data, f->datalen); /* dup and break */
|
||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
ast_frfree(f);
|
ast_frfree(f);
|
||||||
|
@@ -199,8 +199,12 @@ struct ast_realloca {
|
|||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#define ast_strcasestr strcasestr
|
#define ast_strcasestr strcasestr
|
||||||
#else
|
#define ast_strndup strndup
|
||||||
extern char *ast_strcasestr(const char *, const char *);
|
#define ast_strnlen strnlen
|
||||||
#endif /* __linux__ */
|
#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 */
|
#endif /* _ASTERISK_STRINGS_H */
|
||||||
|
26
utils.c
26
utils.c
@@ -535,4 +535,28 @@ char *ast_strcasestr(const char *haystack, const char *needle)
|
|||||||
return NULL;
|
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 */
|
||||||
|
Reference in New Issue
Block a user